aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-12 07:06:47 +0100
committerMax Kellermann <max@duempel.org>2008-11-12 07:06:47 +0100
commit731e99c26ee5b865bad4e6504147c7b6aff6d94a (patch)
tree87fbab78a3b8f7042c818ca01a460ada03946c0a
parent975d5cd77e80c8fbaf5ab307767cb4740dac4be4 (diff)
downloadmpd-731e99c26ee5b865bad4e6504147c7b6aff6d94a.tar.gz
mpd-731e99c26ee5b865bad4e6504147c7b6aff6d94a.tar.xz
mpd-731e99c26ee5b865bad4e6504147c7b6aff6d94a.zip
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().
-rw-r--r--src/decoder/mpc_plugin.c26
1 files changed, 12 insertions, 14 deletions
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
@@ -96,6 +96,14 @@ static inline int32_t convertSample(MPC_SAMPLE_FORMAT sample)
}
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)
{
mpc_decoder decoder;
@@ -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;
}