shithub: opus

Download patch

ref: 5ead149cf49cc8d2fd0e1fb3c7cd564ecbbce100
parent: e26abfaca8fef5188abb9f65b72ddf8b087486cd
author: Felicia Lim <[email protected]>
date: Sat Jun 4 06:10:52 EDT 2016

Saturate when adding prediction to LPC excitation to avoid integer overflow

Slightly modified by Jean-Marc Valin

Signed-off-by: Jean-Marc Valin <[email protected]>

--- a/silk/PLC.c
+++ b/silk/PLC.c
@@ -365,7 +365,8 @@
         }
 
         /* Add prediction to LPC excitation */
-        sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], LPC_pred_Q10, 4 );
+        sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ],
+                                            silk_LSHIFT_SAT32( LPC_pred_Q10, 4 ));
 
         /* Scale with Gain */
         frame[ i ] = (opus_int16)silk_SAT16( silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], prevGain_Q10[ 1 ] ), 8 ) ) );
--- a/silk/decode_core.c
+++ b/silk/decode_core.c
@@ -219,7 +219,7 @@
             }
 
             /* Add prediction to LPC excitation */
-            sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( pres_Q14[ i ], LPC_pred_Q10, 4 );
+            sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( pres_Q14[ i ], silk_LSHIFT_SAT32( LPC_pred_Q10, 4 ) );
 
             /* Scale with gain */
             pxq[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14[ MAX_LPC_ORDER + i ], Gain_Q10 ), 8 ) );