]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp3dec: Allocate correct output buffer size also for mono files.
authorAndre Noll <maan@systemlinux.org>
Sat, 16 Jul 2011 13:21:57 +0000 (15:21 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 9 Aug 2011 21:11:34 +0000 (23:11 +0200)
Currently the buffer size is chosen to hold 4 bytes per sample
even for mono files where 2 bytes per sample suffice.

Since the channel count does not change within a frame, use the
cached value in pmd->channels rather than the MAD_NCHANNELS
macro for each sample.

mp3dec_filter.c

index 82f014189d3ccb8ece45652ec17fa80c9a3ee6b6..7731a379cfe6028559829cdcff9c29e4f541b983 100644 (file)
@@ -181,14 +181,13 @@ next_frame:
        }
        mad_synth_frame(&pmd->synth, &pmd->frame);
        pmd->flags |= MP3DEC_FLAG_DECODE_STARTED;
-
-       outbuffer = para_malloc(pmd->synth.pcm.length * 4);
+       outbuffer = para_malloc(pmd->synth.pcm.length * 2 * pmd->channels);
        loaded = 0;
        for (i = 0; i < pmd->synth.pcm.length; i++) {
                int sample = MAD_TO_SHORT(pmd->synth.pcm.samples[0][i]);
                write_int16_host_endian(outbuffer + loaded, sample);
                loaded += 2;
-               if (MAD_NCHANNELS(&pmd->frame.header) == 2) { /* stereo */
+               if (pmd->channels == 2) { /* stereo */
                        sample = MAD_TO_SHORT(pmd->synth.pcm.samples[1][i]);
                        write_int16_host_endian(outbuffer + loaded, sample);
                        loaded += 2;