From 90d9bc02bea0b7d031bd99fa9f4ba3e57d4401fd Mon Sep 17 00:00:00 2001 From: waker Date: Sat, 15 Jan 2011 15:54:23 +0100 Subject: little mp3 optimization --- plugins/mpgmad/mpgmad.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'plugins/mpgmad/mpgmad.c') diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c index 3bec56ff..ced16e79 100644 --- a/plugins/mpgmad/mpgmad.c +++ b/plugins/mpgmad/mpgmad.c @@ -781,23 +781,31 @@ cmp3_decode_requested_int16 (mpgmad_info_t *info) { cmp3_skip (info); // copy synthesized samples into readbuffer int idx = info->synth.pcm.length-info->buffer.decode_remaining; - while (info->buffer.decode_remaining > 0 && info->buffer.readsize > 0) { - int16_t sample = MadFixedToSshort (info->synth.pcm.samples[0][idx]); - *((int16_t*)info->buffer.out) = sample; - info->buffer.readsize -= 2; - info->buffer.out += 2; - if (MAD_NCHANNELS(&info->frame.header) == 2 && info->info.fmt.channels == 2) { + if (MAD_NCHANNELS(&info->frame.header) == 2 && info->info.fmt.channels == 2) { + while (info->buffer.decode_remaining > 0 && info->buffer.readsize > 0) { + *((int16_t*)info->buffer.out) = MadFixedToSshort (info->synth.pcm.samples[0][idx]); + info->buffer.readsize -= 2; + info->buffer.out += 2; *((int16_t*)info->buffer.out) = MadFixedToSshort (info->synth.pcm.samples[1][idx]); info->buffer.readsize -= 2; info->buffer.out += 2; + info->buffer.decode_remaining--; + idx++; } - else if (MAD_NCHANNELS(&info->frame.header) == 1 && info->info.fmt.channels == 2) { + } + // workaround for bad mp3s that have both mono and stereo frames + else if (MAD_NCHANNELS(&info->frame.header) == 1 && info->info.fmt.channels == 2) { + while (info->buffer.decode_remaining > 0 && info->buffer.readsize > 0) { + int16_t sample = MadFixedToSshort (info->synth.pcm.samples[0][idx]); *((int16_t*)info->buffer.out) = sample; info->buffer.readsize -= 2; info->buffer.out += 2; + *((int16_t*)info->buffer.out) = sample; + info->buffer.readsize -= 2; + info->buffer.out += 2; + info->buffer.decode_remaining--; + idx++; } - info->buffer.decode_remaining--; - idx++; } assert (info->buffer.readsize >= 0); } -- cgit v1.2.3