From 418c31c56a80dd8781186d904b896f49ad22d61e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 31 Mar 2025 21:13:07 +0530 Subject: [PATCH 1/2] Fix for 3GPP issue 1448: Complexity measurement crashes: StereoDmxEVS Link #1448 --- lib_com/tools_fx.c | 4 ++-- lib_com/wi_fx.c | 8 ++++---- lib_enc/core_enc_updt_fx.c | 4 ++-- lib_enc/fd_cng_enc_fx.c | 2 +- lib_enc/gaus_enc_fx.c | 2 +- lib_enc/ppp_enc_fx.c | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 5219d076c..9e5547c7d 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -3579,8 +3579,8 @@ Word16 erb_diff_search_fx( Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif } ELSE { - dh = sub( dif_erb[i + offset], cb_fx[j * cb_dim + i] ); /* Q13 */ - Ltemp1 = L_mult( dh, dh ); /* Q27 */ + dh = sub_sat( dif_erb[i + offset], cb_fx[j * cb_dim + i] ); /* Q13 */ + Ltemp1 = L_mult_sat( dh, dh ); /* Q27 */ dh = extract_h( Ltemp1 ); dl = extract_l( Ltemp1 ); diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 7df4cb3f0..85d9df472 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -2901,11 +2901,11 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, W Ltemp1 = log10_fx( Ltemp1 ); /* subtract 10log10(2)*(2Q-13), Q23 */ - Ltemp1 = L_sub( Ltemp1, Ltemp3 ); + Ltemp1 = L_sub_sat( Ltemp1, Ltemp3 ); Ltemp1 = L_max( 0, Ltemp1 ); Ltemp2 = getSpEngyFromResAmp_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, curr_lpc, sin_tab, cos_tab ); Ltemp2 = log10_fx( Ltemp2 ); /* Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */ - Ltemp2 = L_sub( Ltemp2, Ltemp3 ); /* Ltemp2 in Q23 */ + Ltemp2 = L_sub_sat( Ltemp2, Ltemp3 ); /* Ltemp2 in Q23 */ Ltemp2 = L_max( 0, Ltemp2 ); @@ -2929,10 +2929,10 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, W tmp = round_fx( Ltemp ); /* tmp in Q(22-n) */ Ltemp1 = Mult_32_16( Ltemp1, tmp ); /* Q(30-n) */ n = sub( 8, exp ); - w[0] = round_fx( L_shl( Ltemp1, n ) ); /* w[0] in Q15 */ + w[0] = round_fx_sat( L_shl_sat( Ltemp1, n ) ); /* w[0] in Q15 */ move16(); Ltemp2 = Mult_32_16( Ltemp2, tmp ); - w[1] = round_fx( L_shl( Ltemp2, n ) ); /* w[1] in Q15 */ + w[1] = round_fx_sat( L_shl_sat( Ltemp2, n ) ); /* w[1] in Q15 */ move16(); logLag = log10_fx( X_fx->lag_fx ); /* logLag=10*log10(lag), Q23 */ diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index 305c2a92f..ce2681e75 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -171,8 +171,8 @@ void core_encode_update_cng_fx( tmp = sub( st->wspeech_enc[-1], shl( hLPDmem->mem_w0, shift ) ); E_UTIL_deemph2( negate( shift ), wsyn, st->preemph_fac, st->L_frame, &tmp ); - hLPDmem->mem_w0 = sub( st->wspeech_enc[st->L_frame - 1], tmp ); - hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); + hLPDmem->mem_w0 = sub_sat( st->wspeech_enc[st->L_frame - 1], tmp ); + hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); move16(); move16(); /* Update LPC-related memories */ diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index d182e4a44..fbf5247c3 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2066,7 +2066,7 @@ Word16 cng_energy_fx( L_tmp = L_mult0( tmp16, tmp16 ); pt_res++; tmp16 = shl( *pt_res, scale ); - L_tmp = L_mac0( L_tmp, tmp16, tmp16 ); /* 2*(Q_new+scale) */ + L_tmp = L_mac0_sat( L_tmp, tmp16, tmp16 ); /* 2*(Q_new+scale) */ pt_res++; L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ } diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 081cf7ef0..2aa9a5dff 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -90,7 +90,7 @@ Word16 gaus_encode_fx( exp_code = sub( exp_code, 18 + 6 ); /* exp: -18 (code in Q9), -6 (L_subfr = 64) */ Ltmp = Isqrt_lc( Ltmp, &exp_code ); - *gain_inov = extract_h( L_shl( Ltmp, sub( exp_code, 3 ) ) ); /* g_code_inov in Q12 */ + *gain_inov = extract_h( L_shl_sat( Ltmp, sub( exp_code, 3 ) ) ); /* g_code_inov in Q12 */ nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; /* Q0 */ move16(); diff --git a/lib_enc/ppp_enc_fx.c b/lib_enc/ppp_enc_fx.c index ac3d5836a..d6dc8b6d6 100644 --- a/lib_enc/ppp_enc_fx.c +++ b/lib_enc/ppp_enc_fx.c @@ -830,7 +830,7 @@ static void LPCPowSpect_fx( Lacc = L_add( Lacc, L_shr( L_mult( dh, dh ), 1 ) ); /* Lacc=Re^2+Im^2, Q22 */ exp = norm_l( Lacc ); - tmp = round_fx( L_shl( Lacc, exp ) ); + tmp = round_fx_sat( L_shl( Lacc, exp ) ); exp = sub( sub( 30, exp ), 22 ); /* tmp may potentially become negative, when Lacc is a very large value */ -- GitLab From 5bd27bba7b3a3e6a7027c20ba92f18a07b157c79 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 31 Mar 2025 21:22:15 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/wi_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 85d9df472..591645017 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -2904,7 +2904,7 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, W Ltemp1 = L_sub_sat( Ltemp1, Ltemp3 ); Ltemp1 = L_max( 0, Ltemp1 ); Ltemp2 = getSpEngyFromResAmp_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, curr_lpc, sin_tab, cos_tab ); - Ltemp2 = log10_fx( Ltemp2 ); /* Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */ + Ltemp2 = log10_fx( Ltemp2 ); /* Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */ Ltemp2 = L_sub_sat( Ltemp2, Ltemp3 ); /* Ltemp2 in Q23 */ Ltemp2 = L_max( 0, Ltemp2 ); -- GitLab