mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
Finally fix FS#10678. Now the mp3 encoder plugin supports mono/stereo and the sampling rates 16/22.05/24/32/44.1/48 kHz.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28976 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f0f9f66319
commit
ef70c9f32c
1 changed files with 18 additions and 26 deletions
|
|
@ -15,7 +15,7 @@
|
|||
#include "plugin.h"
|
||||
|
||||
|
||||
#define SAMP_PER_FRAME 1152
|
||||
#define MAX_SAMP_PER_FRAME 1152
|
||||
#define SAMPL2 576
|
||||
#define SBLIMIT 32
|
||||
#define HTN 16
|
||||
|
|
@ -61,7 +61,7 @@ typedef struct {
|
|||
int ResvSize;
|
||||
int channels;
|
||||
int granules;
|
||||
int resample;
|
||||
int smpl_per_frm;
|
||||
uint16_t samplerate;
|
||||
} config_t;
|
||||
|
||||
|
|
@ -813,7 +813,7 @@ static char* mp3_enc_err[] = {
|
|||
/* 6 */ "16 bit per sample required.",
|
||||
/* 7 */ "<=2 channels required.",
|
||||
/* 8 */ "'data' missing.",
|
||||
/* 9 */ "32/44.1/48 kHz required."
|
||||
/* 9 */ "Samplerate not supported."
|
||||
};
|
||||
|
||||
static const char* wav_filename;
|
||||
|
|
@ -898,12 +898,10 @@ int wave_open(void)
|
|||
if(cfg.channels > 2) return -7; /* <=2 channels required */
|
||||
if(!checkString(wavfile,"data")) return -8;
|
||||
|
||||
/* FIXME: sample rates != 32/44.1/48 kHz do not encode properly as those
|
||||
* need MPEG2 format with different setup of the encoder. This MPEG2 setup
|
||||
* is buggy. */
|
||||
if((cfg.samplerate != 32000) &&
|
||||
(cfg.samplerate != 44100) &&
|
||||
(cfg.samplerate != 48000)) return -9;
|
||||
/* Sample rates != 16/22.05/24/32/44.1/48 kHz are not supported. */
|
||||
if((cfg.samplerate != 16000) && (cfg.samplerate != 22050) &&
|
||||
(cfg.samplerate != 24000) && (cfg.samplerate != 32000) &&
|
||||
(cfg.samplerate != 44100) && (cfg.samplerate != 48000)) return -9;
|
||||
|
||||
header_size = 0x28;
|
||||
wav_size = rb->filesize(wavfile);
|
||||
|
|
@ -914,7 +912,7 @@ int wave_open(void)
|
|||
|
||||
int read_samples(uint16_t *buffer, int num_samples)
|
||||
{
|
||||
uint16_t tmpbuf[SAMP_PER_FRAME*2]; /* SAMP_PER_FRAME*MAX_CHANNELS */
|
||||
uint16_t tmpbuf[MAX_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 */
|
||||
|
|
@ -2092,13 +2090,13 @@ void init_mp3_encoder_engine(bool stereo, int bitrate, uint16_t sample_rate)
|
|||
|
||||
if(0 == cfg.mpg.type)
|
||||
{ /* use MPEG2 format */
|
||||
cfg.resample = 1;
|
||||
cfg.granules = 1;
|
||||
cfg.smpl_per_frm = MAX_SAMP_PER_FRAME/2;
|
||||
cfg.granules = 1;
|
||||
}
|
||||
else
|
||||
{ /* use MPEG1 format */
|
||||
cfg.resample = 0;
|
||||
cfg.granules = 2;
|
||||
cfg.smpl_per_frm = MAX_SAMP_PER_FRAME;
|
||||
cfg.granules = 2;
|
||||
}
|
||||
|
||||
scalefac = sfBand[cfg.mpg.smpl_id + 3*cfg.mpg.type];
|
||||
|
|
@ -2172,7 +2170,8 @@ void compress(void)
|
|||
{
|
||||
if((frames & 7) == 0)
|
||||
{ rb->lcd_clear_display();
|
||||
rb->lcd_putsxyf(4, 20, "Frame %d / %d", frames, wav_size/SAMPL2/8);
|
||||
rb->lcd_putsxyf(4, 20, "Frame %d / %d", frames,
|
||||
wav_size/cfg.smpl_per_frm/cfg.channels/2);
|
||||
rb->lcd_update();
|
||||
}
|
||||
/* encode one mp3 frame in this loop */
|
||||
|
|
@ -2194,25 +2193,18 @@ void compress(void)
|
|||
memcpy(mfbuf, mfbuf + 2*cfg.granules*576, 4*512);
|
||||
|
||||
/* read new samples to iram for further processing */
|
||||
if(read_samples((mfbuf + 2*512), SAMP_PER_FRAME) == 0)
|
||||
if(read_samples((mfbuf + 2*512), cfg.smpl_per_frm) == 0)
|
||||
break;
|
||||
|
||||
/* swap bytes if neccessary */
|
||||
if(cfg.byte_order == order_bigEndian)
|
||||
for(i=0; i<SAMP_PER_FRAME; i++)
|
||||
for(i=0; i<cfg.smpl_per_frm; i++)
|
||||
{
|
||||
uint32_t t = ((uint32_t*)mfbuf)[512 + i];
|
||||
t = ((t >> 8) & 0xff00ff) | ((t << 8) & 0xff00ff00);
|
||||
((uint32_t*)mfbuf)[512 + i] = t;
|
||||
}
|
||||
|
||||
if(cfg.resample) /* downsample to half of original */
|
||||
for(i=2*512; i<2*512+2*SAMP_PER_FRAME; i+=4)
|
||||
{
|
||||
mfbuf[i/2+512] = (short)(((int)mfbuf[i+0] + mfbuf[i+2]) >> 1);
|
||||
mfbuf[i/2+513] = (short)(((int)mfbuf[i+1] + mfbuf[i+3]) >> 1);
|
||||
}
|
||||
|
||||
cfg.ResvSize = 0;
|
||||
gr_cnt = cfg.granules * cfg.channels;
|
||||
CodedData.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */
|
||||
|
|
@ -2612,7 +2604,7 @@ enum plugin_status plugin_start(const void* parameter)
|
|||
|
||||
rb->lcd_clear_display();
|
||||
rb->lcd_putsxyf(0, 30, " Conversion: %ld.%02lds ", tim/100, tim%100);
|
||||
tim = frames * SAMP_PER_FRAME * 100 / cfg.samplerate; /* unit=.01s */
|
||||
tim = frames * cfg.smpl_per_frm * 100 / cfg.samplerate; /* unit=.01s */
|
||||
rb->lcd_putsxyf(0, 20, " WAV-Length: %ld.%02lds ", tim/100, tim%100);
|
||||
rb->lcd_update();
|
||||
rb->sleep(5*HZ);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue