From f97b9f11e4f95cf87b09f5184e2016d247f72d09 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Wed, 5 Jan 2011 07:39:12 +0000 Subject: [PATCH] Fix FS#5317. mp3_encoder does now properly encode mono files. Still there is a bug when using sampling rates != 44100 Hz. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28971 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/mp3_encoder.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c index bdfb4d8cdd..f36a25241a 100644 --- a/apps/plugins/mp3_encoder.c +++ b/apps/plugins/mp3_encoder.c @@ -893,12 +893,25 @@ int wave_open(void) return 0; } -int read_samples(uint32_t *buffer, int num_samples) +int read_samples(uint16_t *buffer, int num_samples) { - int s, samples = rb->read(wavfile, buffer, 4 * num_samples) / 4; + uint16_t tmpbuf[SAMP_PER_FRAME*2]; /* SAMP_PER_FRAME*MAX_CHANNELS */ + int byte_per_sample = cfg.channels * 2; /* requires bits_per_sample==16 */ + int s, samples = rb->read(wavfile, tmpbuf, byte_per_sample * num_samples) / byte_per_sample; /* Pad last sample with zeros */ - for(s=samples; s> 1); } - if(cfg.channels == 1) /* mix left and right channels to mono */ - for(i=2*512; i<2*512+2*SAMP_PER_FRAME; i+=2) - mfbuf[i] = mfbuf[i+1] = (short)(((int)mfbuf[i] + mfbuf[i+1]) >> 1); - cfg.ResvSize = 0; gr_cnt = cfg.granules * cfg.channels; CodedData.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */ @@ -2560,7 +2569,7 @@ enum plugin_status plugin_start(const void* parameter) ret = wave_open(); if(ret == 0) { - init_mp3_encoder_engine(true, brate[srat], cfg.samplerate); + init_mp3_encoder_engine((cfg.channels==2), brate[srat], cfg.samplerate); get_mp3_filename(wav_filename); mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC, 0666); frames = 0;