From 93bc5ef1d64ee140d6c578c9a3cab39d5f267bda Mon Sep 17 00:00:00 2001 From: Michael Giacomelli Date: Sun, 8 Jul 2007 06:06:00 +0000 Subject: Fix rare overflow when decoding MDCT coefficients. As a bonus, decoding is now slightly faster. Thanks to preglow for suggesting I test with a full scale normalized square wave. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13815 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libwma/wmadeci.c | 26 +++++++++----------------- apps/plugins/SOURCES | 1 + 2 files changed, 10 insertions(+), 17 deletions(-) (limited to 'apps') diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c index cd01c030c8..f018cfbc53 100644 --- a/apps/codecs/libwma/wmadeci.c +++ b/apps/codecs/libwma/wmadeci.c @@ -630,16 +630,7 @@ void ff_imdct_calc(MDCTContext *s, in2 -= 2; } - for(k = 0; k < n4; k++){ - z[k].re >>=1; - z[k].im >>=1; - } - - //rb->splash(HZ, "in MDCT calc"); scale = fft_calc_unscaled(&s->fft, z); - // scale = fft_calc(&s->fft, z); - - //rb->splash(HZ, "in MDCT calc2"); /* post rotation + reordering */ @@ -1764,8 +1755,7 @@ static int wma_decode_block(WMADecodeContext *s) { /* XXX: optimize more */ - for(i = 0;i < s->coefs_start; ++i) - *coefs++ = 0; //why do we do this step?! + n = nb_coefs[ch]; @@ -1773,15 +1763,17 @@ static int wma_decode_block(WMADecodeContext *s) for(i = 0;i < n; ++i) { + /* + * Previously the IMDCT was run in 17.15 precision to avoid overflow. However rare files could + * overflow here as well, so switch to 17.15 now. As a bonus, this saves us a shift later on. + */ - atemp = (fixed32)(coefs1[i]*mult>>16); - //atemp= ftofix32(coefs1[i] * fixtof64(exponents[i]) * fixtof64(mult>>16)); //this "works" in the sense that the mdcts converge - - //this can still overflow in rare cases - //running a full scale value square wave through here does bad things - *coefs++=fixmul32(atemp,exponents[i<>esize]); + atemp = (fixed32)(coefs1[i]*mult>>17); + //this "works" in the sense that the mdcts converge + //atemp= ftofix32(coefs1[i] * fixtof64(exponents[i]) * fixtof64(mult>>16)); + *coefs++=fixmul32(atemp,exponents[i<>esize]); } n = s->block_len - s->coefs_end[bsize]; diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 14f4d552d1..807f20f9f8 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -18,6 +18,7 @@ stats.c stopwatch.c vbrfix.c viewer.c +test_codec.c /* plugins built for all targets, but not for the simulator */ #if !defined(SIMULATOR) -- cgit v1.2.3