diff --git a/lib_com/options.h b/lib_com/options.h index d1b3cb63e4f0e20bafe9f31d1fd8e41adc6fc06b..d82b4862e99636fc499edb21519fd6db8d4eecb4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -111,4 +111,6 @@ #define FIX_1735_W_SHL_SAT_L /* FhG: Usage of W_shl_sat_l() */ +#define FIX_ISSUE_1795_Q3_OVERFLOW /* FhG: Q3 overflow in function WB_BWE_gain_pred_fx (EVS legacy code) BE, MR1855 */ + #endif diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 11da78c46f06cf04a6895050c706e53824225711..8b134e5d63591a710ca01b80c2999e722c276c0d 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -241,14 +241,26 @@ Word16 WB_BWE_gain_pred_fx( tmp = extract_l( L_tmp ); enerL = L_deposit_l( enerL_16 ); - enerL = L_shl( enerL, 6 ); /*Q6 */ + enerL = L_shl( enerL, 6 ); /*Q6 */ +#ifdef FIX_ISSUE_1795_Q3_OVERFLOW + /* Here, we do not multiply L_tmp by 3 to avoid overflow */ + L_tmp = L_mult0( WB_fenv[0], WB_fenv[0] ); /* Q6 */ +#else + /* Here, we have not enough headroom for mult with 3, so we get some overflow */ tmp1 = i_mult_sat( 3, WB_fenv[0] ); /*Q3 */ L_tmp = L_mult0( tmp1, WB_fenv[0] ); /*Q6 */ +#endif test(); test(); test(); +#ifdef FIX_ISSUE_1795_Q3_OVERFLOW +#define ONE_DIV_3 ( (Word32) 0x2AAAAAAA ) + /* Here, L_tmp is not pre-multiplied with 3, we multiply enerL with 1/3 */ + IF( GT_16( shr( enerL_16, 3 ), tmp ) && GT_32( Mpy_32_32( ONE_DIV_3, enerL ), L_tmp ) && NE_16( prev_coder_type, UNVOICED ) && WB_fenv[0] != 0 ) +#else IF( GT_16( shr( enerL_16, 3 ), tmp ) && GT_32( enerL, L_tmp ) && NE_16( prev_coder_type, UNVOICED ) && WB_fenv[0] != 0 ) +#endif { env_var_flag = 1; move16();