Commit b284947c authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Resolve overflow by swapping the order of addition and multiplication

parent 028d6837
Loading
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -2792,6 +2792,9 @@ enum
#define LOG2_10                               27213       /* log base 2 of 10 in Q12 */
#define LOG2_10_Q29                           1783446566  /* log base 2 of 10 in Q12 */
#define LOG10_2_Q31                           646456993   /* inverse log base 10 of 2 in Q31 */
#ifdef FIX_2210_ASSERT_IN_BW_DETEC_FX_FOR_OMASA
#define INV_LOG2_10                           9864        /* 1/log2(10), Q15*/
#endif
#define MU_MA_FX                              10923       /* original prediction factor for the AMR WB tables (Q15) */

#define E_MIN_FXQ15                           115     /* Q15*/
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@
#define FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING         /* Orange: Fix for issue 2184 - to prevent one channel from becoming inaudible in the mono downmix output */
#define FIX_2148_OBJ_EDIT_ISSUE_WITH_OSBA                    /* Nokia: Add missing code to solve issue */
#define FIX_2200_ISAR_PLC_CRASH                              /* Dolby: Fix for ISAR PLC crash observed with newly added BASOP tests */

#define FIX_2210_ASSERT_IN_BW_DETEC_FX_FOR_OMASA             /* FhG: Resolve overflow by swapping the order of addition and multiplication */
/* ################### End FIXES switches ########################### */

/* #################### Start BASOP porting switches ############################ */
+34 −14
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ void bw_detect_fx(
    Word16 spect[L_FRAME48k], spect_bin[BWD_N_BINS_MAX];
    Word32 spect32[L_FRAME48k], in_win32[BWD_TOTAL_WIDTH];
    Word16 e_tmp, f_tmp;
    Word32 L_tmp, sum32;
    Word32 L_tmp, sum32, L_tmp_q_shift;

    Word32 L_tmp1, L_tmp2, L_tmp3;
    Word16 scale;
@@ -131,12 +131,17 @@ void bw_detect_fx(
            }
#endif
            L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/
#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING
            L_tmp = L_add_sat( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#ifdef FIX_2210_ASSERT_IN_BW_DETEC_FX_FOR_OMASA
            L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ).

            L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25
            L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 );                        // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ).

            cldfb_bin[0] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */
#else
            L_tmp = L_add_sat( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#endif
            cldfb_bin[0] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ );
#endif
            move32(); /* 1/log2(10) */ /* Q25 */

            /* WB: 4.4 - 7.2 kHz, 8 cldfb-bands, mid band(14) counted twice */
@@ -165,12 +170,17 @@ void bw_detect_fx(
                        move32();
                    }
                    L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/
#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING
                    L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#ifdef FIX_2210_ASSERT_IN_BW_DETEC_FX_FOR_OMASA
                    L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ).

                    L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25
                    L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 );                        // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ).

                    cldfb_bin[i] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */
#else
                    L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#endif
                    cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ );
#endif
                    move32(); /* 1/log2(10) */ /* Q25 */
                }
            }
@@ -208,12 +218,17 @@ void bw_detect_fx(
                        move32();
                    }
                    L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/
#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING
                    L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#ifdef FIX_2210_ASSERT_IN_BW_DETEC_FX_FOR_OMASA
                    L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ).

                    L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25
                    L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 );                        // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ).

                    cldfb_bin[i] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */
#else
                    L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#endif
                    cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ );
#endif
                    move32(); /* 1/log2(10) */ /* Q25 */
                }
            }
@@ -245,12 +260,17 @@ void bw_detect_fx(
                        move32();
                    }
                    L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/
#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING
                    L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#ifdef FIX_2210_ASSERT_IN_BW_DETEC_FX_FOR_OMASA
                    L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ).

                    L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25
                    L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 );                        // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ).

                    cldfb_bin[i] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */
#else
                    L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */
#endif
                    cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ );
#endif
                    move32(); /* 1/log2(10) */ /* Q25 */
                }
            }