Fixes two fixed-point overflow issues
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Thu, 10 May 2012 16:36:46 +0000 (12:36 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Thu, 10 May 2012 16:36:46 +0000 (12:36 -0400)
One in SILK, one in CELT, none of them causing real harm in practice it seems

celt/celt.c
silk/fixed/prefilter_FIX.c

index 3b1b4f6..8c9105b 100644 (file)
@@ -865,8 +865,9 @@ static int stereo_analysis(const CELTMode *m, const celt_norm *X,
          R = X[N0+j];
          M = L+R;
          S = L-R;
          R = X[N0+j];
          M = L+R;
          S = L-R;
-         sumLR += EXTEND32(ABS16(L)) + EXTEND32(ABS16(R));
-         sumMS += EXTEND32(ABS16(M)) + EXTEND32(ABS16(S));
+         /* We cast to 32-bit first because of the -32768 case */
+         sumLR += ABS32(EXTEND32(L)) + ABS32(EXTEND32(R));
+         sumMS += ABS32(EXTEND32(M)) + ABS32(EXTEND32(S));
       }
    }
    sumMS = MULT16_32_Q15(QCONST16(0.707107f, 15), sumMS);
       }
    }
    sumMS = MULT16_32_Q15(QCONST16(0.707107f, 15), sumMS);
index 1b54d14..a96f511 100644 (file)
@@ -135,9 +135,9 @@ void silk_prefilter_FIX(
         tmp_32 = silk_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] );                                                /* Q24 */
         tmp_32 = silk_RSHIFT_ROUND( tmp_32, 14 );                                                                     /* Q10 */
         B_Q10[ 1 ]= silk_SAT16( tmp_32 );
         tmp_32 = silk_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] );                                                /* Q24 */
         tmp_32 = silk_RSHIFT_ROUND( tmp_32, 14 );                                                                     /* Q10 */
         B_Q10[ 1 ]= silk_SAT16( tmp_32 );
-        x_filt_Q12[ 0 ] = silk_SMLABB( silk_SMULBB( st_res_Q2[ 0 ], B_Q10[ 0 ] ), P->sHarmHP_Q2, B_Q10[ 1 ] );
+        x_filt_Q12[ 0 ] = silk_MLA( silk_MUL( st_res_Q2[ 0 ], B_Q10[ 0 ] ), P->sHarmHP_Q2, B_Q10[ 1 ] );
         for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) {
         for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) {
-            x_filt_Q12[ j ] = silk_SMLABB( silk_SMULBB( st_res_Q2[ j ], B_Q10[ 0 ] ), st_res_Q2[ j - 1 ], B_Q10[ 1 ] );
+            x_filt_Q12[ j ] = silk_MLA( silk_MUL( st_res_Q2[ j ], B_Q10[ 0 ] ), st_res_Q2[ j - 1 ], B_Q10[ 1 ] );
         }
         P->sHarmHP_Q2 = st_res_Q2[ psEnc->sCmn.subfr_length - 1 ];
 
         }
         P->sHarmHP_Q2 = st_res_Q2[ psEnc->sCmn.subfr_length - 1 ];