From 87d3dde15a1f0af6eaac21107d74aa240515fd0c Mon Sep 17 00:00:00 2001 From: Michael Giacomelli Date: Mon, 30 Apr 2012 23:28:57 -0400 Subject: Fix corrupt when repeatidly playing very low bitrate WMA files. The LSP feature in WMA requires that the noise table values be doubled verses when it is not used. Unfortunately, the previous code would double the same values every time a LSP file was decoded without first resetting them to their original values. Change the code to check if the values are already doubled, and then double/halve them as needed. This is still a bit ugly, in the future consider using the built in rockbox dither instead of a lookup table. Fixes playback when skipping back and forth between low and high bitrate WMA. Change-Id: I4c393092e4a789bc8f98d74274fe207400b9550e Reviewed-on: http://gerrit.rockbox.org/226 Reviewed-by: Michael Giacomelli Tested-by: Michael Giacomelli --- lib/rbcodec/codecs/libwma/wmadata.h | 3 ++- lib/rbcodec/codecs/libwma/wmadeci.c | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) mode change 100644 => 100755 lib/rbcodec/codecs/libwma/wmadata.h mode change 100644 => 100755 lib/rbcodec/codecs/libwma/wmadeci.c diff --git a/lib/rbcodec/codecs/libwma/wmadata.h b/lib/rbcodec/codecs/libwma/wmadata.h old mode 100644 new mode 100755 index 07a55df19a..7f97a75676 --- a/lib/rbcodec/codecs/libwma/wmadata.h +++ b/lib/rbcodec/codecs/libwma/wmadata.h @@ -1578,7 +1578,8 @@ const fixed64 lsp_pow_e_table[] ICONST_ATTR_WMA_XL_IRAM = 0x0LL }; -/* table of exp noise values multiplied by 16 in order to reduce rounding error */ +/* table of exp noise values multiplied by 16 in order to reduce rounding error, + * note that that first value (0x5) is used as a magic number in the init code*/ fixed32 noisetable_exp[] = { 0x5, 0xfffffa2e, 0xc2c, 0xb47, 0xffffaebe, 0xfffffa63, 0xfffff7ff, 0x16bd, diff --git a/lib/rbcodec/codecs/libwma/wmadeci.c b/lib/rbcodec/codecs/libwma/wmadeci.c old mode 100644 new mode 100755 index d7a836dd97..69bdbeaca2 --- a/lib/rbcodec/codecs/libwma/wmadeci.c +++ b/lib/rbcodec/codecs/libwma/wmadeci.c @@ -487,23 +487,33 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx) s->reset_block_lengths = 1; - if (s->use_noise_coding) + if (s->use_noise_coding) /* init the noise generator */ { - /* init the noise generator */ + /* LSP values are simply 2x the EXP values */ if (s->use_exp_vlc) { s->noise_mult = 0x51f; + /*unlikely, but we may have previoiusly used this table for LSP, + so halve the values if needed*/ + if(noisetable_exp[0] == 0x10) { + for (i=0;i>= 1; + } s->noise_table = noisetable_exp; } else { s->noise_mult = 0xa3d; - /* LSP values are simply 2x the EXP values */ - for (i=0;inoise_table = noisetable_exp; } #if 0 +/*TODO: Rockbox has a dither function. Consider using it for noise coding*/ + /* We use a lookup table computered in advance, so no need to do this*/ { unsigned int seed; -- cgit v1.2.3