summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-01-05 07:39:12 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-01-05 07:39:12 +0000
commitf97b9f11e4f95cf87b09f5184e2016d247f72d09 (patch)
tree8588c4f67463312b8a351b278563e84cfb61f636
parent114c9503bfffe3ccc129cf02443e5d78acea84e5 (diff)
downloadrockbox-f97b9f11e4f95cf87b09f5184e2016d247f72d09.tar.gz
rockbox-f97b9f11e4f95cf87b09f5184e2016d247f72d09.zip
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
-rw-r--r--apps/plugins/mp3_encoder.c29
1 files 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)
893 return 0; 893 return 0;
894} 894}
895 895
896int read_samples(uint32_t *buffer, int num_samples) 896int read_samples(uint16_t *buffer, int num_samples)
897{ 897{
898 int s, samples = rb->read(wavfile, buffer, 4 * num_samples) / 4; 898 uint16_t tmpbuf[SAMP_PER_FRAME*2]; /* SAMP_PER_FRAME*MAX_CHANNELS */
899 int byte_per_sample = cfg.channels * 2; /* requires bits_per_sample==16 */
900 int s, samples = rb->read(wavfile, tmpbuf, byte_per_sample * num_samples) / byte_per_sample;
899 /* Pad last sample with zeros */ 901 /* Pad last sample with zeros */
900 for(s=samples; s<num_samples; s++) 902 memset(tmpbuf + samples*cfg.channels, 0, (num_samples-samples)*cfg.channels);
901 buffer[s] = 0; 903
904 if (cfg.channels==1)
905 {
906 /* interleave the mono samples to stereo as required by encoder */
907 for(s=0; s<num_samples; s++)
908 buffer[2*s] = tmpbuf[s];
909 }
910 else
911 {
912 /* interleaving is correct for stereo */
913 memcpy(buffer, tmpbuf, sizeof(tmpbuf));
914 }
902 915
903 return samples; 916 return samples;
904} 917}
@@ -2163,7 +2176,7 @@ void compress(void)
2163 memcpy(mfbuf, mfbuf + 2*cfg.granules*576, 4*512); 2176 memcpy(mfbuf, mfbuf + 2*cfg.granules*576, 4*512);
2164 2177
2165 /* read new samples to iram for further processing */ 2178 /* read new samples to iram for further processing */
2166 if(read_samples((uint32_t*)(mfbuf + 2*512), SAMP_PER_FRAME) == 0) 2179 if(read_samples((mfbuf + 2*512), SAMP_PER_FRAME) == 0)
2167 break; 2180 break;
2168 2181
2169 /* swap bytes if neccessary */ 2182 /* swap bytes if neccessary */
@@ -2182,10 +2195,6 @@ void compress(void)
2182 mfbuf[i/2+513] = (short)(((int)mfbuf[i+1] + mfbuf[i+3]) >> 1); 2195 mfbuf[i/2+513] = (short)(((int)mfbuf[i+1] + mfbuf[i+3]) >> 1);
2183 } 2196 }
2184 2197
2185 if(cfg.channels == 1) /* mix left and right channels to mono */
2186 for(i=2*512; i<2*512+2*SAMP_PER_FRAME; i+=2)
2187 mfbuf[i] = mfbuf[i+1] = (short)(((int)mfbuf[i] + mfbuf[i+1]) >> 1);
2188
2189 cfg.ResvSize = 0; 2198 cfg.ResvSize = 0;
2190 gr_cnt = cfg.granules * cfg.channels; 2199 gr_cnt = cfg.granules * cfg.channels;
2191 CodedData.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */ 2200 CodedData.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */
@@ -2560,7 +2569,7 @@ enum plugin_status plugin_start(const void* parameter)
2560 ret = wave_open(); 2569 ret = wave_open();
2561 if(ret == 0) 2570 if(ret == 0)
2562 { 2571 {
2563 init_mp3_encoder_engine(true, brate[srat], cfg.samplerate); 2572 init_mp3_encoder_engine((cfg.channels==2), brate[srat], cfg.samplerate);
2564 get_mp3_filename(wav_filename); 2573 get_mp3_filename(wav_filename);
2565 mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC, 0666); 2574 mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC, 0666);
2566 frames = 0; 2575 frames = 0;