From 731e99c26ee5b865bad4e6504147c7b6aff6d94a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 12 Nov 2008 07:06:47 +0100 Subject: mpc: moved code to mpc_to_mpd_buffer() mpc_to_mpd_buffer() converts a whole chunk at a time. This eliminates 3 local variables in mpc_decode(). --- src/decoder/mpc_plugin.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/decoder/mpc_plugin.c b/src/decoder/mpc_plugin.c index e1f6353de..f3e54f4d2 100644 --- a/src/decoder/mpc_plugin.c +++ b/src/decoder/mpc_plugin.c @@ -95,6 +95,14 @@ static inline int32_t convertSample(MPC_SAMPLE_FORMAT sample) return val; } +static void +mpc_to_mpd_buffer(int32_t *dest, const MPC_SAMPLE_FORMAT *src, + unsigned num_samples) +{ + while (num_samples-- > 0) + *dest++ = convertSample(*src++); +} + static void mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) { @@ -109,14 +117,11 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) long ret; int32_t chunk[G_N_ELEMENTS(sample_buffer)]; - int chunkpos = 0; long bitRate = 0; - int32_t *dest = chunk; unsigned long samplePos = 0; mpc_uint32_t vbrUpdateAcc; mpc_uint32_t vbrUpdateBits; float total_time; - int i; struct replay_gain_info *replayGainInfo = NULL; data.inStream = inStream; @@ -163,11 +168,9 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) { samplePos = decoder_seek_where(mpd_decoder) * audio_format.sample_rate; - if (mpc_decoder_seek_sample(&decoder, samplePos)) { - dest = chunk; - chunkpos = 0; + if (mpc_decoder_seek_sample(&decoder, samplePos)) decoder_command_finished(mpd_decoder); - } else + else decoder_seek_error(mpd_decoder); } @@ -184,22 +187,17 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) /* ret is in samples, and we have stereo */ ret *= 2; - for (i = 0; i < ret; i++) { - *dest++ = convertSample(sample_buffer[i]); - chunkpos += sizeof(*dest); - } + mpc_to_mpd_buffer(chunk, sample_buffer, ret); total_time = ((float)samplePos) / audio_format.sample_rate; bitRate = vbrUpdateBits * audio_format.sample_rate / 1152 / 1000; decoder_data(mpd_decoder, inStream, - chunk, chunkpos, + chunk, ret * sizeof(chunk[0]), total_time, bitRate, replayGainInfo); - dest = chunk; - if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP) break; } -- cgit v1.2.3