summaryrefslogtreecommitdiff
path: root/apps/codecs/mp3_enc.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2008-10-08 22:18:16 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2008-10-08 22:18:16 +0000
commit528fe442fc6e6e077172b2e8a3b586a3ce96d16b (patch)
tree4985fe6f102727419862cf58bcb5aa8a7d736f11 /apps/codecs/mp3_enc.c
parentcb1173cedd4eb1c8648420a3926a591995390537 (diff)
New recording setting to configure how mono recordings are made. Previously, this was always L+R, which was kinda silly if your signal was on L only. This setting allows for L, R or L+R. SWCODEC only for now, to be added for HWCODEC (although that will only be L and L+R probably)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18745 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/mp3_enc.c')
-rw-r--r--apps/codecs/mp3_enc.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c
index 767a292343..555e981a06 100644
--- a/apps/codecs/mp3_enc.c
+++ b/apps/codecs/mp3_enc.c
@@ -90,6 +90,7 @@ typedef struct {
int mean_bits;
int ResvSize;
int channels;
+ int rec_mono_mode;
int granules;
long samplerate;
} config_t;
@@ -1972,12 +1973,14 @@ static int find_samplerate_index(long freq, int *mp3_type)
bool init_mp3_encoder_engine(int sample_rate,
int num_channels,
+ int rec_mono_mode,
struct encoder_config *enc_cfg)
{
const bool stereo = num_channels > 1;
uint32_t avg_byte_per_frame;
cfg.channels = stereo ? 2 : 1;
+ cfg.rec_mono_mode = rec_mono_mode;
cfg.mpg.mode = stereo ? 0 : 3; /* 0=stereo, 3=mono */
cfg.mpg.smpl_id = find_samplerate_index(sample_rate, &cfg.mpg.type);
cfg.samplerate = sampr_index[cfg.mpg.type][cfg.mpg.smpl_id];
@@ -2093,9 +2096,26 @@ STATICIRAM void to_mono_mm(void)
inline void to_mono(uint32_t **samp)
{
int32_t lr = **samp;
- int32_t m = (int16_t)lr + (lr >> 16) + err;
- err = m & 1;
- m >>= 1;
+ int32_t m;
+
+ switch(cfg.rec_mono_mode)
+ {
+ case 1:
+ /* mono = L */
+ m = lr >> 16;
+ break;
+ case 2:
+ /* mono = R */
+ m = (int16_t)lr;
+ break;
+ case 0:
+ default:
+ /* mono = (L+R)/2 */
+ m = (int16_t)lr + (lr >> 16) + err;
+ err = m & 1;
+ m >>= 1;
+ break;
+ }
*(*samp)++ = (m << 16) | (uint16_t)m;
} /* to_mono */
@@ -2517,7 +2537,7 @@ static bool enc_init(void)
return false;
init_mp3_encoder_engine(inputs.sample_rate, inputs.num_channels,
- inputs.config);
+ inputs.rec_mono_mode, inputs.config);
err = 0;