summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-01-06 12:03:12 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-01-06 12:03:12 +0000
commitb5b41e9f687d123a2bfb076e642d7b1ae6dcb393 (patch)
tree17d8927d7fcd4de2b36da3a3039b06ea555c3b7e /apps
parent89a7a8138ec97a038200ab3080710bd101a9ff0e (diff)
downloadrockbox-b5b41e9f687d123a2bfb076e642d7b1ae6dcb393.tar.gz
rockbox-b5b41e9f687d123a2bfb076e642d7b1ae6dcb393.zip
Related to FS#10678. The mp3 encoder plugin of Rockbox does not encode MPEG2 layer3 properly and does not support MPEG2.5 layer3 at all. Therefor only samplerates of 32, 44.1 and 48 kHz are supported as input. This change introduces a proper error handling and user error message until the underlying error is fixed.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28973 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/mp3_encoder.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c
index f36a25241a..3cf2b642f0 100644
--- a/apps/plugins/mp3_encoder.c
+++ b/apps/plugins/mp3_encoder.c
@@ -802,7 +802,19 @@ static const int16_t win[18][4] = {
802 { 529, -831,-3747,-2387 }, 802 { 529, -831,-3747,-2387 },
803 { 362, -471,-3579,-2747 }, 803 { 362, -471,-3579,-2747 },
804 { 134, -146,-3352,-3072 } }; 804 { 134, -146,-3352,-3072 } };
805 805
806static char* mp3_enc_err[] = {
807 /* 0 */ "",
808 /* 1 */ "Cannot open file.",
809 /* 2 */ "'RIFF' missing.",
810 /* 3 */ "'WAVE' missing.",
811 /* 4 */ "'fmt ' missing.",
812 /* 5 */ "Linear PCM required.",
813 /* 6 */ "16 bit per sample required.",
814 /* 7 */ "<=2 channels required.",
815 /* 8 */ "'data' missing.",
816 /* 9 */ "32/44.1/48 kHz required."
817};
806 818
807static const char* wav_filename; 819static const char* wav_filename;
808static int mp3file, wavfile, wav_size, frames; 820static int mp3file, wavfile, wav_size, frames;
@@ -881,11 +893,18 @@ int wave_open(void)
881 wBlockAlign = Read16BitsLowHigh(wavfile); 893 wBlockAlign = Read16BitsLowHigh(wavfile);
882 bits_per_samp = Read16BitsLowHigh(wavfile); 894 bits_per_samp = Read16BitsLowHigh(wavfile);
883 895
884 if(wFormatTag != 0x0001) return -5; 896 if(wFormatTag != 0x0001) return -5; /* linear PCM required */
885 if(bits_per_samp != 16) return -6; 897 if(bits_per_samp != 16) return -6; /* 16 bps required */
886 if(cfg.channels > 2) return -7; 898 if(cfg.channels > 2) return -7; /* <=2 channels required */
887 if(!checkString(wavfile,"data")) return -8; 899 if(!checkString(wavfile,"data")) return -8;
888 900
901 /* FIXME: sample rates != 32/44.1/48 kHz do not encode properly as those
902 * need MPEG2 format with different setup of the encoder. This MPEG2 setup
903 * is buggy. */
904 if((cfg.samplerate != 32000) &&
905 (cfg.samplerate != 44100) &&
906 (cfg.samplerate != 48000)) return -9;
907
889 header_size = 0x28; 908 header_size = 0x28;
890 wav_size = rb->filesize(wavfile); 909 wav_size = rb->filesize(wavfile);
891 rb->lseek(wavfile, header_size, SEEK_SET); 910 rb->lseek(wavfile, header_size, SEEK_SET);
@@ -2063,9 +2082,16 @@ void init_mp3_encoder_engine(bool stereo, int bitrate, uint16_t sample_rate)
2063 cfg.byte_order = order_bigEndian; 2082 cfg.byte_order = order_bigEndian;
2064#endif 2083#endif
2065 2084
2066 if(bitrate < 96 && stereo && sample_rate >= 32000) 2085 cfg.samplerate = sample_rate;
2086 cfg.channels = stereo ? 2 : 1;
2087 cfg.mpg.mode = stereo ? 0 : 3; /* 0=stereo, 3=mono */
2088 cfg.mpg.bitrate = stereo ? bitrate : bitrate > 160 ? 160 : bitrate;
2089 cfg.mpg.smpl_id = find_samplerate_index(cfg.samplerate, &cfg.mpg.type);
2090 cfg.mpg.bitr_id = find_bitrate_index(cfg.mpg.type, cfg.mpg.bitrate);
2091 cfg.mpg.num_bands = num_bands[stereo ? cfg.mpg.type : 2][cfg.mpg.bitr_id];
2092
2093 if(0 == cfg.mpg.type)
2067 { /* use MPEG2 format */ 2094 { /* use MPEG2 format */
2068 sample_rate >>= 1;
2069 cfg.resample = 1; 2095 cfg.resample = 1;
2070 cfg.granules = 1; 2096 cfg.granules = 1;
2071 } 2097 }
@@ -2075,14 +2101,6 @@ void init_mp3_encoder_engine(bool stereo, int bitrate, uint16_t sample_rate)
2075 cfg.granules = 2; 2101 cfg.granules = 2;
2076 } 2102 }
2077 2103
2078 cfg.samplerate = sample_rate;
2079 cfg.channels = stereo ? 2 : 1;
2080 cfg.mpg.mode = stereo ? 0 : 3; /* 0=stereo, 3=mono */
2081 cfg.mpg.bitrate = stereo ? bitrate : bitrate > 160 ? 160 : bitrate;
2082 cfg.mpg.smpl_id = find_samplerate_index(cfg.samplerate, &cfg.mpg.type);
2083 cfg.mpg.bitr_id = find_bitrate_index(cfg.mpg.type, cfg.mpg.bitrate);
2084 cfg.mpg.num_bands = num_bands[stereo ? cfg.mpg.type : 2][cfg.mpg.bitr_id];
2085
2086 scalefac = sfBand[cfg.mpg.smpl_id + 3*cfg.mpg.type]; 2104 scalefac = sfBand[cfg.mpg.smpl_id + 3*cfg.mpg.type];
2087 2105
2088 ht[ 0].table = NULL; ht[ 0].hlen = NULL; /* Apparently not used */ 2106 ht[ 0].table = NULL; ht[ 0].hlen = NULL; /* Apparently not used */
@@ -2585,14 +2603,16 @@ enum plugin_status plugin_start(const void* parameter)
2585 else 2603 else
2586 { 2604 {
2587 rb->close(wavfile); 2605 rb->close(wavfile);
2606 rb->lcd_clear_display();
2588 rb->lcd_putsxyf(0, 20, "WaveOpen failed %d", ret); 2607 rb->lcd_putsxyf(0, 20, "WaveOpen failed %d", ret);
2608 rb->lcd_putsxyf(0, 30, "%s", mp3_enc_err[-ret]);
2589 rb->lcd_update(); 2609 rb->lcd_update();
2590 rb->sleep(5*HZ); 2610 rb->sleep(5*HZ);
2591 } 2611 }
2592 2612
2593 rb->lcd_clear_display(); 2613 rb->lcd_clear_display();
2594 rb->lcd_putsxyf(0, 30, " Conversion: %ld.%02lds ", tim/100, tim%100); 2614 rb->lcd_putsxyf(0, 30, " Conversion: %ld.%02lds ", tim/100, tim%100);
2595 tim = frames * SAMP_PER_FRAME * 100 / 44100; /* unit=.01s */ 2615 tim = frames * SAMP_PER_FRAME * 100 / cfg.samplerate; /* unit=.01s */
2596 rb->lcd_putsxyf(0, 20, " WAV-Length: %ld.%02lds ", tim/100, tim%100); 2616 rb->lcd_putsxyf(0, 20, " WAV-Length: %ld.%02lds ", tim/100, tim%100);
2597 rb->lcd_update(); 2617 rb->lcd_update();
2598 rb->sleep(5*HZ); 2618 rb->sleep(5*HZ);