summaryrefslogtreecommitdiffstats
path: root/libAACenc
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2013-08-08 17:38:33 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2013-08-20 15:01:21 -0700
commited247dfa54234c1115c35a05327955b29b161e8a (patch)
tree9e4488bf844e217bf16d8cd3f001738d14ed56fd /libAACenc
parent577fcbb570d023be4cea9564292dd2bd95f40c3b (diff)
downloadODR-AudioEnc-ed247dfa54234c1115c35a05327955b29b161e8a.tar.gz
ODR-AudioEnc-ed247dfa54234c1115c35a05327955b29b161e8a.tar.bz2
ODR-AudioEnc-ed247dfa54234c1115c35a05327955b29b161e8a.zip
Encoder quantizer fix
AAC Encoder: Saturate quantizer shift value to prevent undefined behaviour. In very rare cases the shift value 'totalShift = (16-4)-(3*(totalShift>>2))' can be greater than accu data width. If you apply a shift with more then 31 bit the result depends on the architecture and is not defined in C. For certain platforms zeros are shifted in. That would be our desired behaviour. On other platforms the shift will be applied as modulo. For example >>34 would be applied as >>2. To prevent this discrepancy the shift value is limited/saturated to DFRACT_BITS-1. 'accu >>= fixMin(totalShift,DFRACT_BITS-1)'. Bug 9428126 Change-Id: I27177654c4dc22cf899bc35dad9cdd040dccb02d
Diffstat (limited to 'libAACenc')
-rw-r--r--libAACenc/src/aacenc_lib.cpp2
-rw-r--r--libAACenc/src/quantize.cpp4
2 files changed, 3 insertions, 3 deletions
diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp
index 2f95ab1..e229ed6 100644
--- a/libAACenc/src/aacenc_lib.cpp
+++ b/libAACenc/src/aacenc_lib.cpp
@@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de
/* Encoder library info */
#define AACENCODER_LIB_VL0 3
#define AACENCODER_LIB_VL1 4
-#define AACENCODER_LIB_VL2 1
+#define AACENCODER_LIB_VL2 2
#define AACENCODER_LIB_TITLE "AAC Encoder"
#define AACENCODER_LIB_BUILD_DATE __DATE__
#define AACENCODER_LIB_BUILD_TIME __TIME__
diff --git a/libAACenc/src/quantize.cpp b/libAACenc/src/quantize.cpp
index da6f85e..5380e35 100644
--- a/libAACenc/src/quantize.cpp
+++ b/libAACenc/src/quantize.cpp
@@ -127,7 +127,7 @@ static void FDKaacEnc_quantizeLines(INT gain,
accu = fMultDiv2(FDKaacEnc_mTab_3_4[tabIndex],FDKaacEnc_quantTableE[totalShift&3]);
totalShift = (16-4)-(3*(totalShift>>2));
FDK_ASSERT(totalShift >=0); /* MAX_QUANT_VIOLATION */
- accu>>=totalShift;
+ accu >>= fixMin(totalShift,DFRACT_BITS-1);
quaSpectrum[line] = (SHORT)(-((LONG)(k + accu) >> (DFRACT_BITS-1-16)));
}
else if(accu > FL2FXCONST_DBL(0.0f))
@@ -140,7 +140,7 @@ static void FDKaacEnc_quantizeLines(INT gain,
accu = fMultDiv2(FDKaacEnc_mTab_3_4[tabIndex],FDKaacEnc_quantTableE[totalShift&3]);
totalShift = (16-4)-(3*(totalShift>>2));
FDK_ASSERT(totalShift >=0); /* MAX_QUANT_VIOLATION */
- accu>>=totalShift;
+ accu >>= fixMin(totalShift,DFRACT_BITS-1);
quaSpectrum[line] = (SHORT)((LONG)(k + accu) >> (DFRACT_BITS-1-16));
}
else