[FFmpeg-cvslog] adx: use 12-bit coefficients instead of 14-bit to avoid integer overflow

Justin Ruggles git at videolan.org
Sun Nov 27 00:39:15 CET 2011


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Sun Nov 20 14:03:21 2011 -0500| [954d94dd5e13ba7a5e9e049d0f980bddced9644c] | committer: Justin Ruggles

adx: use 12-bit coefficients instead of 14-bit to avoid integer overflow

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=954d94dd5e13ba7a5e9e049d0f980bddced9644c
---

 libavcodec/adx.h    |    6 +++---
 libavcodec/adxdec.c |    2 +-
 libavcodec/adxenc.c |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/adx.h b/libavcodec/adx.h
index a329afb..ae5eb6a 100644
--- a/libavcodec/adx.h
+++ b/libavcodec/adx.h
@@ -43,8 +43,8 @@ typedef struct {
     int in_temp;
 } ADXContext;
 
-#define    BASEVOL   0x4000
-#define    SCALE1    0x7298
-#define    SCALE2    0x3350
+#define COEFF_BITS  12
+#define COEFF1      0x1CA6
+#define COEFF2      0x0CD4
 
 #endif /* AVCODEC_ADX_H */
diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c
index 39223c2..93bbc6b 100644
--- a/libavcodec/adxdec.c
+++ b/libavcodec/adxdec.c
@@ -59,7 +59,7 @@ static void adx_decode(ADXContext *c, int16_t *out, const uint8_t *in, int ch)
     s2 = prev->s2;
     for (i = 0; i < 32; i++) {
         d  = get_sbits(&gb, 4);
-        s0 = (BASEVOL * d * scale + SCALE1 * s1 - SCALE2 * s2) >> 14;
+        s0 = ((d << COEFF_BITS) * scale + COEFF1 * s1 - COEFF2 * s2) >> COEFF_BITS;
         s2 = s1;
         s1 = av_clip_int16(s0);
         *out = s1;
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index fde0b82..7225c31 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -48,7 +48,7 @@ static void adx_encode(unsigned char *adx,const short *wav,
     s2 = prev->s2;
     for(i=0;i<32;i++) {
         s0 = wav[i];
-        d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL;
+        d = ((s0 << COEFF_BITS) - COEFF1 * s1 + COEFF2 * s2) >> COEFF_BITS;
         data[i]=d;
         if (max<d) max=d;
         if (min>d) min=d;



More information about the ffmpeg-cvslog mailing list