summaryrefslogtreecommitdiff
path: root/apps/codecs/mp3_enc.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-02-09 18:11:11 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-02-09 18:11:11 +0000
commitd52f2e4bcaac8a70f306d3022a16ea6360108559 (patch)
tree134ae84bc188ee44f4e6cfc7706616618cedd67b /apps/codecs/mp3_enc.c
parent0abfe9f8ea5cc52a17ae3ac0b4ebe9df0b27ce14 (diff)
Encoders: Add a little dithering with the fractional bit for mono mixdowns so faster shifts can be used again instead of division without introducing their own DC offset into the mixed channels.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12246 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/mp3_enc.c')
-rw-r--r--apps/codecs/mp3_enc.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c
index 64c0996dc2..70b327aef2 100644
--- a/apps/codecs/mp3_enc.c
+++ b/apps/codecs/mp3_enc.c
@@ -174,6 +174,7 @@ static unsigned samp_per_frame IBSS_ATTR;
static config_t cfg IBSS_ATTR;
static char *res_buffer;
+static int32_t err IBSS_ATTR;
static const uint8_t ht_count_const[2][2][16] =
{ { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */
@@ -2055,7 +2056,9 @@ static void to_mono_mm(void)
inline void to_mono(uint32_t **samp)
{
int32_t lr = **samp;
- int32_t m = ((int16_t)lr + (lr >> 16)) / 2;
+ int32_t m = (int16_t)lr + (lr >> 16) + err;
+ err = m & 1;
+ m >>= 1;
*(*samp)++ = (m << 16) | (uint16_t)m;
} /* to_mono */
@@ -2434,6 +2437,8 @@ static bool enc_init(void)
init_mp3_encoder_engine(inputs.sample_rate, inputs.num_channels,
inputs.config);
+ err = 0;
+
/* configure the buffer system */
params.afmt = AFMT_MPA_L3;
params.chunk_size = cfg.byte_per_frame + 1;