diff options
author | Max Kellermann <max@duempel.org> | 2009-01-17 13:11:10 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-17 13:11:10 +0100 |
commit | 610e79500e872a4fb25d9c8725ed188379d9fe81 (patch) | |
tree | ff94749d087c36fc5760205bd5ed662e2e68b8f4 /src/decoder_api.c | |
parent | fd948571f884e6354883e2ecfc24bab799fc0805 (diff) | |
download | mpd-610e79500e872a4fb25d9c8725ed188379d9fe81.tar.gz mpd-610e79500e872a4fb25d9c8725ed188379d9fe81.tar.xz mpd-610e79500e872a4fb25d9c8725ed188379d9fe81.zip |
decoder_api: use music_pipe_write() instead of music_pipe_append()
Copy PCM data to the music_pipe_write() buffer, and apply replay gain
/ normalization to it, instead of manipulating the source buffer.
Diffstat (limited to '')
-rw-r--r-- | src/decoder_api.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/decoder_api.c b/src/decoder_api.c index da61f3110..0ddb4ab90 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -193,7 +193,6 @@ decoder_data(struct decoder *decoder, { static char *conv_buffer; static size_t conv_buffer_size; - size_t nbytes; char *data; assert(dc.state == DECODE_STATE_DECODE); @@ -250,25 +249,45 @@ decoder_data(struct decoder *decoder, return DECODE_COMMAND_NONE; } - if (replay_gain_info != NULL && (replay_gain_mode != REPLAY_GAIN_OFF)) - replay_gain_apply(replay_gain_info, data, length, - &dc.out_audio_format); - else if (normalizationEnabled) - normalizeData(data, length, &dc.out_audio_format); - while (length > 0) { - nbytes = music_pipe_append(data, length, - &dc.out_audio_format, - data_time, bitRate); - length -= nbytes; - data += nbytes; - - if (length > 0) { + size_t nbytes; + char *dest = music_pipe_write(&dc.out_audio_format, + data_time, bitRate, + &nbytes); + if (dest == NULL) { + /* the music pipe is full: wait for more + room */ enum decoder_command cmd = need_chunks(is, nbytes == 0); if (cmd != DECODE_COMMAND_NONE) return cmd; + continue; } + + assert(nbytes > 0); + + if (nbytes > length) + nbytes = length; + + /* copy the buffer */ + + memcpy(dest, data, nbytes); + + /* apply replay gain or normalization */ + + if (replay_gain_info != NULL && + replay_gain_mode != REPLAY_GAIN_OFF) + replay_gain_apply(replay_gain_info, dest, nbytes, + &dc.out_audio_format); + else if (normalizationEnabled) + normalizeData(dest, nbytes, &dc.out_audio_format); + + /* expand the music pipe chunk */ + + music_pipe_expand(&dc.out_audio_format, nbytes); + + data += nbytes; + length -= nbytes; } return DECODE_COMMAND_NONE; |