Fixes the stereo_analysis() fixed-point overflow issue properly

This commit is contained in:
Jean-Marc Valin 2012-05-16 17:47:17 -04:00
parent 7143b2d0ff
commit 14d63d1879
2 changed files with 8 additions and 8 deletions

View file

@ -860,14 +860,14 @@ static int stereo_analysis(const CELTMode *m, const celt_norm *X,
int j; int j;
for (j=m->eBands[i]<<LM;j<m->eBands[i+1]<<LM;j++) for (j=m->eBands[i]<<LM;j<m->eBands[i+1]<<LM;j++)
{ {
opus_val16 L, R, M, S; opus_val32 L, R, M, S;
L = X[j];
R = X[N0+j];
M = L+R;
S = L-R;
/* We cast to 32-bit first because of the -32768 case */ /* We cast to 32-bit first because of the -32768 case */
sumLR += ABS32(EXTEND32(L)) + ABS32(EXTEND32(R)); L = EXTEND32(X[j]);
sumMS += ABS32(EXTEND32(M)) + ABS32(EXTEND32(S)); R = EXTEND32(X[N0+j]);
M = ADD32(L, R);
S = SUB32(L, R);
sumLR = ADD32(sumLR, ADD32(ABS32(L), ABS32(R)));
sumMS = ADD32(sumMS, ADD32(ABS32(M), ABS32(S)));
} }
} }
sumMS = MULT16_32_Q15(QCONST16(0.707107f, 15), sumMS); sumMS = MULT16_32_Q15(QCONST16(0.707107f, 15), sumMS);

View file

@ -69,7 +69,7 @@ struct OpusDecoder {
#ifdef FIXED_POINT #ifdef FIXED_POINT
static inline opus_int16 SAT16(opus_int32 x) { static inline opus_int16 SAT16(opus_int32 x) {
return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x; return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
}; }
#endif #endif