summaryrefslogtreecommitdiffstats
path: root/apps/codecs/aiff_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/aiff_enc.c
parent0abfe9f8ea5cc52a17ae3ac0b4ebe9df0b27ce14 (diff)
downloadrockbox-d52f2e4bcaac8a70f306d3022a16ea6360108559.tar.gz
rockbox-d52f2e4bcaac8a70f306d3022a16ea6360108559.zip
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/aiff_enc.c')
-rw-r--r--apps/codecs/aiff_enc.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/apps/codecs/aiff_enc.c b/apps/codecs/aiff_enc.c
index f1569d20ff..5f993084c7 100644
--- a/apps/codecs/aiff_enc.c
+++ b/apps/codecs/aiff_enc.c
@@ -69,9 +69,10 @@ struct aiff_header aiff_header =
/* (*) updated when finalizing file */
-static int num_channels;
-uint32_t sample_rate;
-uint32_t enc_size;
+static int num_channels IBSS_ATTR;
+static uint32_t sample_rate;
+static uint32_t enc_size;
+static int32_t err IBSS_ATTR;
/* convert unsigned 32 bit value to 80-bit floating point number */
static void uint32_h_to_ieee754_extended_be(uint8_t f[10], uint32_t l) ICODE_ATTR;
@@ -240,10 +241,14 @@ static void chunk_to_aiff_format(uint32_t *src, uint32_t *dst)
int32_t lr1, lr2;
lr1 = *(*src)++;
- lr1 = ((int16_t)lr1 + (lr1 >> 16)) / 2;
+ lr1 = (int16_t)lr1 + (lr1 >> 16) + err;
+ err = lr1 & 1;
+ lr1 >>= 1;
lr2 = *(*src)++;
- lr2 = ((int16_t)lr2 + (lr2 >> 16)) / 2;
+ lr2 = (int16_t)lr2 + (lr2 >> 16) + err;
+ err = lr2 & 1;
+ lr2 >>= 1;
*(*dst)++ = swap_odd_even_le32((lr1 << 16) | (uint16_t)lr2);
} /* to_mono */
@@ -311,6 +316,7 @@ static bool init_encoder(void)
sample_rate = inputs.sample_rate;
num_channels = inputs.num_channels;
+ err = 0;
/* configure the buffer system */
params.afmt = AFMT_AIFF;