Fixes a fixed-point overflow on 16-bit architectures
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Wed, 29 Sep 2010 22:05:20 +0000 (18:05 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Wed, 29 Sep 2010 22:05:20 +0000 (18:05 -0400)
libcelt/quant_bands.c

index 0a40db7..ba80fa9 100644 (file)
@@ -287,7 +287,7 @@ void quant_fine_energy(const CELTMode *m, int start, int end, celt_ener *eBands,
             q2 = 0;
          ec_enc_bits(enc, q2, fine_quant[i]);
 #ifdef FIXED_POINT
-         offset = SUB16(SHR16(SHL16(q2,DB_SHIFT)+QCONST16(.5,DB_SHIFT),fine_quant[i]),QCONST16(.5f,DB_SHIFT));
+         offset = SUB16(SHR32(SHL32(EXTEND32(q2),DB_SHIFT)+QCONST16(.5,DB_SHIFT),fine_quant[i]),QCONST16(.5f,DB_SHIFT));
 #else
          offset = (q2+.5f)*(1<<(14-fine_quant[i]))*(1.f/16384) - .5f;
 #endif
@@ -377,7 +377,7 @@ void unquant_fine_energy(const CELTMode *m, int start, int end, celt_ener *eBand
          celt_word16 offset;
          q2 = ec_dec_bits(dec, fine_quant[i]);
 #ifdef FIXED_POINT
-         offset = SUB16(SHR16(SHL16(q2,DB_SHIFT)+QCONST16(.5,DB_SHIFT),fine_quant[i]),QCONST16(.5f,DB_SHIFT));
+         offset = SUB16(SHR32(SHL32(EXTEND32(q2),DB_SHIFT)+QCONST16(.5,DB_SHIFT),fine_quant[i]),QCONST16(.5f,DB_SHIFT));
 #else
          offset = (q2+.5f)*(1<<(14-fine_quant[i]))*(1.f/16384) - .5f;
 #endif