aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins/flac_plugin.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2005-02-02 04:22:16 +0000
committerWarren Dukes <warren.dukes@gmail.com>2005-02-02 04:22:16 +0000
commit1e123ad4b737bc93317f8203ed34d3cebe24b2e0 (patch)
tree85ee254520ce4a9e793f83fcaca61dccd0c81ced /src/inputPlugins/flac_plugin.c
parentf134e2686a18eb7c9ef176e2322e7cede9843ea8 (diff)
downloadmpd-1e123ad4b737bc93317f8203ed34d3cebe24b2e0.tar.gz
mpd-1e123ad4b737bc93317f8203ed34d3cebe24b2e0.tar.xz
mpd-1e123ad4b737bc93317f8203ed34d3cebe24b2e0.zip
minor optimization to flacWrite()
git-svn-id: https://svn.musicpd.org/mpd/trunk@2927 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/inputPlugins/flac_plugin.c')
-rw-r--r--src/inputPlugins/flac_plugin.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 365bfb78a..e65853f6d 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -397,12 +397,11 @@ FLAC__StreamDecoderWriteStatus flacWrite(const FLAC__SeekableStreamDecoder *dec,
{
FlacData * data = (FlacData *)vdata;
FLAC__uint32 samples = frame->header.blocksize;
- FLAC__uint16 u16;
- unsigned char * uc;
- int c_samp, c_chan, d_samp;
- int i;
+ int c_samp;
+ int c_chan;
float timeChange;
FLAC__uint64 newPosition = 0;
+ int bytesPerSample = data->dc->audioFormat.bits/8;
timeChange = ((float)samples)/frame->header.sample_rate;
data->time+= timeChange;
@@ -414,22 +413,20 @@ FLAC__StreamDecoderWriteStatus flacWrite(const FLAC__SeekableStreamDecoder *dec,
}
data->position = newPosition;
- for(c_samp = d_samp = 0; c_samp < frame->header.blocksize; c_samp++) {
- for(c_chan = 0; c_chan < frame->header.channels;
- c_chan++, d_samp++) {
- u16 = buf[c_chan][c_samp];
- uc = (unsigned char *)&u16;
- for(i=0;i<(data->dc->audioFormat.bits/8);i++) {
- if(data->chunk_length>=FLAC_CHUNK_SIZE) {
- if(flacSendChunk(data)<0) {
- return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
- }
- data->chunk_length = 0;
- if(data->dc->seek) {
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
- }
+ for(c_samp = 0; c_samp < frame->header.blocksize; c_samp++) {
+ for(c_chan = 0; c_chan < frame->header.channels; c_chan++) {
+ memcpy(data->chunk+data->chunk_length,
+ &buf[c_chan][c_samp], bytesPerSample);
+ data->chunk_length++;
+ if(FLAC_CHUNK_SIZE-data->chunk_length < bytesPerSample)
+ {
+ if(flacSendChunk(data)<0) {
+ return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+ }
+ data->chunk_length = 0;
+ if(data->dc->seek) {
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
- data->chunk[data->chunk_length++] = *(uc++);
}
}
}