From c7a3d86c0df6871260487608b894d7a943dd8562 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 22 Aug 2025 13:16:48 -0400 Subject: [PATCH 1/3] Adding missing _sat --- lib_com/options.h | 1 + lib_enc/gain_enc_fx.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 428ddbb05..90410c08c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -171,6 +171,7 @@ #define NONBE_1220_OMASA_JBM_BRATE_SW_FLUSH /* VA: issue 1220: fix bug in renderer flush in OMASA 1ISM JBM bitrate switching */ #define FIX_1139_REV_COLORATION_SHORT_T60 /* Nokia,FhG: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */ +#define FIX_1959_assert_in_gain_enc_mless_fx /* VA: Fix saturation introduced by the usage of the non-EVS basop operators =, the saturation was expected */ /* #################### End BASOP porting switches ############################ */ #endif diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index ea7a26685..015eb43e7 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -339,10 +339,18 @@ void gain_enc_mless_fx( = ((-0.5*g_corr[3]*g_corr[0]) - (-0.25*g_corr[1]*g_corr[4]))/tmp1; = ((0.25*g_corr[1]*g_corr[4]) - (0.5*g_corr[0]*g_corr[3]))/tmp1; */ +#ifdef FIX_1959_assert_in_gain_enc_mless_fx + L_tmp1 = L_mult_sat( coeff[0], coeff[2] ); /*Q31*/ +#else L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ + #endif exp1 = add( exp_coeff[0], exp_coeff[2] ); +#ifdef FIX_1959_assert_in_gain_enc_mless_fx + L_tmp2 = L_shr( L_mult_sat( coeff[4], coeff[4] ), 2 ); /*Q31*/ +#else L_tmp2 = L_shr( L_mult( coeff[4], coeff[4] ), 2 ); /*Q31*/ +#endif exp2 = add( exp_coeff[4], exp_coeff[4] ); IF( GT_16( exp1, exp2 ) ) -- GitLab From 64347e16b3c531c426eedc8bcc1ebac95e78d869 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 22 Aug 2025 13:22:19 -0400 Subject: [PATCH 2/3] fix clang --- lib_enc/gain_enc_fx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index 015eb43e7..761f06319 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -341,15 +341,15 @@ void gain_enc_mless_fx( #ifdef FIX_1959_assert_in_gain_enc_mless_fx L_tmp1 = L_mult_sat( coeff[0], coeff[2] ); /*Q31*/ -#else - L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ - #endif +#else + L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ +#endif exp1 = add( exp_coeff[0], exp_coeff[2] ); #ifdef FIX_1959_assert_in_gain_enc_mless_fx L_tmp2 = L_shr( L_mult_sat( coeff[4], coeff[4] ), 2 ); /*Q31*/ #else - L_tmp2 = L_shr( L_mult( coeff[4], coeff[4] ), 2 ); /*Q31*/ + L_tmp2 = L_shr( L_mult( coeff[4], coeff[4] ), 2 ); /*Q31*/ #endif exp2 = add( exp_coeff[4], exp_coeff[4] ); -- GitLab From 43fa5856e69a72f81af8f1b903b1955425bc5a06 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 22 Aug 2025 13:46:09 -0400 Subject: [PATCH 3/3] adding another exception --- lib_enc/gain_enc_fx.c | 59 ++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index 761f06319..ca93207c7 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -275,31 +275,50 @@ void gain_enc_mless_fx( /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ L_tmp = Dot_product12( code, code, L_SUBFR, &exp_code ); exp_inov = sub( exp_code, 18 + 6 ); - exp_code = sub( exp_code, 30 ); +#ifdef FIX_1959_assert_in_gain_enc_mless_fx + // To avoid crash in case code value is 0, + test(); + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_tmp, exp_inov, 21474836, 0 ), -1 ) && element_mode > EVS_MONO ) + { + // setting values to avoid extra computation + *gain_inov = 32767; /*8(max value gain_inov can hold) in Q12*/ + Ei = -9743; /* -38 in Q8*/ + move16(); + move16(); + } + ELSE +#endif + { - /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ + exp_code = sub( exp_code, 30 ); - /*----------------------------------------------------------------* - * calculate the predicted gain code - *----------------------------------------------------------------*/ - tmp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, tmp ) ); - tmp = add( 30 - 18 - 6 - 1, sub( exp_code, tmp ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp1 = Mpy_32_16( tmp, frac, 12330 ); /* Q13 */ - Ei = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ + /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ + /*----------------------------------------------------------------* + * calculate the predicted gain code + *----------------------------------------------------------------*/ + tmp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, tmp ) ); + tmp = add( 30 - 18 - 6 - 1, sub( exp_code, tmp ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp1 = Mpy_32_16( tmp, frac, 12330 ); /* Q13 */ + Ei = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ +#ifndef FIX_1959_assert_in_gain_enc_mless_fx + /* predicted codebook gain */ + gcode0 = sub( Es_pred, Ei ); /* Q8 */ +#endif + /*---------------------------------------------------------------* + * Decode codebook gain and the adaptive excitation low-pass + * filtering factor (Finalize computation ) + *---------------------------------------------------------------*/ + /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ + L_tmp = Isqrt_lc( L_tmp, &exp_inov ); + *gain_inov = extract_h( L_shl( L_tmp, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ + move16(); + } +#ifdef FIX_1959_assert_in_gain_enc_mless_fx /* predicted codebook gain */ gcode0 = sub( Es_pred, Ei ); /* Q8 */ - - /*---------------------------------------------------------------* - * Decode codebook gain and the adaptive excitation low-pass - * filtering factor (Finalize computation ) - *---------------------------------------------------------------*/ - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = Isqrt_lc( L_tmp, &exp_inov ); - *gain_inov = extract_h( L_shl( L_tmp, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ - move16(); - +#endif /* gcode0 = pow(10, 0.05 * (Es_pred - Ei)) */ /*----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) -- GitLab