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.
This commit is contained in:
Max Kellermann 2009-01-17 13:11:10 +01:00
parent fd948571f8
commit 610e79500e

View File

@ -193,7 +193,6 @@ decoder_data(struct decoder *decoder,
{ {
static char *conv_buffer; static char *conv_buffer;
static size_t conv_buffer_size; static size_t conv_buffer_size;
size_t nbytes;
char *data; char *data;
assert(dc.state == DECODE_STATE_DECODE); assert(dc.state == DECODE_STATE_DECODE);
@ -250,25 +249,45 @@ decoder_data(struct decoder *decoder,
return DECODE_COMMAND_NONE; 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) { while (length > 0) {
nbytes = music_pipe_append(data, length, size_t nbytes;
&dc.out_audio_format, char *dest = music_pipe_write(&dc.out_audio_format,
data_time, bitRate); data_time, bitRate,
length -= nbytes; &nbytes);
data += nbytes; if (dest == NULL) {
/* the music pipe is full: wait for more
if (length > 0) { room */
enum decoder_command cmd = enum decoder_command cmd =
need_chunks(is, nbytes == 0); need_chunks(is, nbytes == 0);
if (cmd != DECODE_COMMAND_NONE) if (cmd != DECODE_COMMAND_NONE)
return cmd; 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; return DECODE_COMMAND_NONE;