From 957ebf503ac1a52d2dda36993e8117186dde08d5 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 12:37:02 -0500 Subject: [PATCH 01/42] adding basop sat for signal with extreme saturation --- lib_com/modif_fs_fx.c | 14 +++++++++++--- lib_enc/detect_transient_fx.c | 8 ++++++-- lib_enc/find_uv_fx.c | 7 +++++-- lib_enc/hq_lr_enc_fx.c | 33 +++++++++++++++++++++++++++------ lib_enc/scale_enc_fx.c | 6 +++++- lib_enc/tcx_utils_enc_fx.c | 6 +++++- 6 files changed, 59 insertions(+), 15 deletions(-) diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 7d42b2689..b64f70b13 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -207,8 +207,13 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigPtr = signal_fx+lg+mem_len+i; move16(); /*+i*/ L_tmp = syn_kern_16(0, A_fx, sigPtr); - L_tmp = L_shl(L_tmp, 3); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 3 ); + *sigPtr = round_fx_sat(L_tmp); /* AZ ringing padding */ +#else + L_tmp = L_shl( L_tmp, 3 ); *sigPtr = round_fx(L_tmp); /* AZ ringing padding */ +#endif } mem_preemph_fx = signal_fx[mem_len+lg-LEN_WIN_SSS - 1]; move16(); @@ -232,8 +237,11 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR(i=0; ifilter_fx, frac, fac_num, filt_len_tmp )); - +#ifdef BASOP_NOGLOB + sigOut_fx[i] = round_fx_sat( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); +#else + sigOut_fx[i] = round_fx( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); +#endif frac = add(frac,fracstep); j = sub(fac_num, frac); diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 8cad74f96..416e32573 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -75,9 +75,13 @@ static void hp_filter_fx( #else /* BASOP_NOGLOB */ L_tmp = L_mult(sub(x[0], *oldx), 24465);/*Q_new+16 */ #endif /* BASOP_NOGLOB */ - L_tmp = L_mac(L_tmp, *oldy, 16158);/*Q_new+16 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac_sat( L_tmp, *oldy, 16158 ); /*Q_new+16 */ + y[0] = round_fx_sat(L_tmp);/*Q_new */ +#else + L_tmp = L_mac( L_tmp, *oldy, 16158 ); /*Q_new+16 */ y[0] = round_fx(L_tmp);/*Q_new */ - +#endif FOR(i = 1; i < L; i++) { /*y[i] = 0.4931f*y[i-1] + 0.7466f*(x[i] - x[i-1]); */ diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 56b6a7f4d..d04389ad0 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -71,8 +71,11 @@ static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10 } - minEnr = L_add(minEnr, 100000); - +#ifdef BASOP_NOGLOB + minEnr = L_add_sat( minEnr, 100000 ); +#else + minEnr = L_add( minEnr, 100000 ); +#endif exp0 = norm_l(minEnr); wtmp0 = extract_h(L_shl(minEnr, exp0)); exp1 = sub(norm_l(maxEnr),1); diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 4906be8fc..6f8a577de 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -349,7 +349,11 @@ void hq_lr_enc_fx( frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ L_tmp = Pow2(30, frac1); exp = sub(exp, 30); - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ +#ifdef BASOP_NOGLOB + Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#else + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#endif } FOR( i = 0; i < bands_fx; i++ ) @@ -416,13 +420,22 @@ void hq_lr_enc_fx( { IF( GE_16(i,lowband)) { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif } ELSE { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif IF(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) { Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ @@ -596,11 +609,19 @@ void hq_lr_enc_fx( { IF(GE_16(i,lowband)) { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif } ELSE { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ +#ifdef BASOP_NOGLOB + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ +#else + Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ +#endif IF(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) { Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q13 */ diff --git a/lib_enc/scale_enc_fx.c b/lib_enc/scale_enc_fx.c index 31ef140c4..f2b8b186c 100644 --- a/lib_enc/scale_enc_fx.c +++ b/lib_enc/scale_enc_fx.c @@ -179,7 +179,11 @@ void Preemph_scaled( L_tmp = L_msu(L_tmp, new_speech[i - 1], mu); #endif /* BASOP_NOGLOB */ L_tmp = L_shl(L_tmp, *Q_new); - new_speech[i] = round_fx(L_tmp); +#ifdef BASOP_NOGLOB + new_speech[i] = round_fx_sat( L_tmp ); +#else + new_speech[i] = round_fx( L_tmp ); +#endif } L_tmp = L_mult(new_speech[0], QVal); diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index c6bba4e12..c9536fdb9 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1446,7 +1446,11 @@ void tcx_encoder_memory_update_fx( Residu3_fx(Ai+(st->nb_subfr-1)*(M+1), synth + sub(L_frame_glob, 1), &tmp, 1, Q_new+shift-1); LPDmem->mem_w0 =sub(wsig[sub(L_frame_glob, 1)], tmp); move16(); - LPDmem->mem_w0 =shr(LPDmem->mem_w0, shift); /*Qnew-1*/ +#ifdef BASOP_NOGLOB + LPDmem->mem_w0 = shr_sat( LPDmem->mem_w0, shift ); /*Qnew-1*/ +#else + LPDmem->mem_w0 = shr( LPDmem->mem_w0, shift ); /*Qnew-1*/ +#endif } -- GitLab From b2e84c977a4fb721889bd1b76619a438262337b3 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 12:43:09 -0500 Subject: [PATCH 02/42] adding basop sat for signal with extreme saturation --- lib_enc/gaus_enc_fx.c | 12 ++++++++++-- lib_enc/nelp_enc_fx.c | 20 +++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 5d6d2ed18..4d42b5b4f 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -599,10 +599,18 @@ void gauss2v_fx( div_result = div_s(Num, Den); /* Q15 */ /* Re-scale to compensate for normalization*/ - GainPortion2 = L_shr(L_deposit_l(div_result), sub(exp_num, exp_den)); +#ifdef BASOP_NOGLOB + GainPortion2 = L_shr_sat( L_deposit_l( div_result ), sub( exp_num, exp_den ) ); +#else + GainPortion2 = L_shr( L_deposit_l( div_result ), sub( exp_num, exp_den ) ); +#endif } - ener_sqrt = Isqrt(L_shl(GainPortion2, 1)); /* Make value a Q16 prior to division (align on power of 4) */ +#ifdef BASOP_NOGLOB + ener_sqrt = Isqrt( L_shl_sat( GainPortion2, 1 ) ); /* Make value a Q16 prior to division (align on power of 4) */ +#else + ener_sqrt = Isqrt( L_shl( GainPortion2, 1 ) ); /* Make value a Q16 prior to division (align on power of 4) */ +#endif ener_sqrt = L_shr(ener_sqrt, 8); /* Left-shift Q23 result to make a Q15 result */ Portion = Mult_32_16(GainPortion1, 19661); /* Performs GainPortion1*.6 */ diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index 1323bac5d..8a0bc5ef8 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -132,7 +132,11 @@ void quantize_uvg_fx(Word16 *G, Word16 *iG1, Word16 *iG2, Word16 *quantG, Word16 FOR(i = 0; i < UVG1_CBSIZE; i++) { L16 = shr(sub(G1[0], UVG1CB_fx[i][0]), 1); /* Q12 */ - L16_1 = shr(sub(G1[1], UVG1CB_fx[i][1]), 1); /* Q12 */ +#ifdef BASOP_NOGLOB + L16_1 = shr( sub_sat( G1[1], UVG1CB_fx[i][1] ), 1 ); /* Q12 */ +#else + L16_1 = shr( sub( G1[1], UVG1CB_fx[i][1] ), 1 ); /* Q12 */ +#endif Lacc = 0; Lacc = L_mac0(Lacc, L16, L16); /*Q24 */ Lacc = L_mac0(Lacc, L16_1, L16_1);/*Q24 */ @@ -189,15 +193,25 @@ void quantize_uvg_fx(Word16 *G, Word16 *iG1, Word16 *iG2, Word16 *quantG, Word16 { /*mse += SQR(G2[i*5+k]-UVG2CB1[j][k]); */ ind = add(shr(extract_l(L_mult(i, 5)), 1), k); - temp = sub(G2[ind], UVG2CB1_fx[j][k]); +#ifdef BASOP_NOGLOB + temp = sub_sat( G2[ind], UVG2CB1_fx[j][k] ); + Lacc = L_mac0_sat(Lacc, temp, temp); /*Q24 */ +#else + temp = sub( G2[ind], UVG2CB1_fx[j][k] ); Lacc = L_mac0(Lacc, temp, temp); /*Q24 */ +#endif } ELSE IF(i == 1) { /*mse += SQR(G2[i*5+k]-UVG2CB2[j][k]); */ ind = add(shr(extract_l(L_mult(i, 5)), 1), k); - temp = sub(G2[ind], UVG2CB2_fx[j][k]); +#ifdef BASOP_NOGLOB + temp = sub_sat( G2[ind], UVG2CB2_fx[j][k] ); + Lacc = L_mac0_sat(Lacc, temp, temp); /*Q24 */ +#else + temp = sub( G2[ind], UVG2CB2_fx[j][k] ); Lacc = L_mac0(Lacc, temp, temp); /*Q24 */ +#endif } } -- GitLab From b13d27201260aff7f18f276c0f8ef33d47953cac Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 12:56:47 -0500 Subject: [PATCH 03/42] adding basop sat for signal with extreme saturation --- lib_com/bitalloc_fx.c | 7 +++++-- lib_com/modif_fs_fx.c | 6 +++++- lib_com/residu_fx.c | 6 +++++- lib_com/swb_bwe_com_fx.c | 12 ++++++++++-- lib_com/swb_tbe_com_fx.c | 13 ++++++++++--- lib_enc/acelp_core_switch_enc_fx.c | 15 +++++++++++++-- lib_enc/enc_higher_acelp_fx.c | 6 +++++- lib_enc/enc_tran_fx.c | 6 +++++- lib_enc/scale_enc_fx.c | 15 ++++++++++++--- lib_enc/swb_bwe_enc_fx.c | 14 +++++++++++--- lib_enc/swb_tbe_enc_fx.c | 16 ++++++++++++++++ lib_enc/tcq_core_enc_fx.c | 6 +++++- lib_enc/tcx_ltp_enc_fx.c | 6 +++++- lib_enc/transient_detection_fx.c | 12 ++++++++++-- 14 files changed, 117 insertions(+), 23 deletions(-) diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index f27606273..8cb434f72 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -371,8 +371,11 @@ Word16 BitAllocF_fx ( exp1 = sub(norm_l(L_tmp1), 1); exp2 = norm_s(n); tmp = div_s(extract_h(L_shl(L_tmp1, exp1)), shl(n, exp2));/*15 + 15 + exp1 - 16 - exp2*/ - m_fx = shl(tmp, sub(exp2, exp1));/*Q14*/ - +#ifdef BASOP_NOGLOB + m_fx = shl_sat( tmp, sub( exp2, exp1 ) ); /*Q14*/ +#else + m_fx = shl( tmp, sub( exp2, exp1 ) ); /*Q14*/ +#endif t_fx = L_deposit_l(0); n = 0; move16(); diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index b64f70b13..245f0f3e2 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -815,7 +815,11 @@ void Decimate_allpass_steep_fx( sum = mult_r( out_fx[k], 16384 ); /* Qx */ - out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP-1], 16384 ) ); +#ifdef BASOP_NOGLOB + out_fx[k] = add_sat( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); +#else + out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); +#endif move16(); /* Qx */ } diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 2c3624a5d..4801ffbea 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -127,7 +127,11 @@ void Residu3_10_fx( s64 = W_mac_16_16(s64, x[i-j], a[j]); } s = W_shl_sat_l(s64, q); - y[i] = round_fx(s); +#ifdef BASOP_NOGLOB + y[i] = round_fx_sat( s ); +#else + y[i] = round_fx( s ); +#endif } } /*--------------------------------------------------------------------* diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 808dbfef7..83c87aecf 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2421,7 +2421,11 @@ void calc_normal_length_fx_32( peak = mag; move16(); } - mean = L_add(mean, mag); +#ifdef BASOP_NOGLOB + mean = L_add_sat( mean, mag ); +#else + mean = L_add( mean, mag ); +#endif pit++; } @@ -2510,7 +2514,11 @@ void calc_norm_envelop_fx_32( move16(); FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { - envelope_fx[env_index] = L_add(envelope_fx[env_index], L_abs(SWB_signal_fx[add(n_freq, n_lag)])); +#ifdef BASOP_NOGLOB + envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); +#else + envelope_fx[env_index] = L_add( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); +#endif move32(); } env_index++; diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 1d39003e5..e1a69d879 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -4068,7 +4068,11 @@ void Estimate_mix_factors_fx( shb_res_local[i] = round_fx(L_tmp2); /* temp_numer1[i] = sub(shb_res_local[i], WN_exc_local[i]); */ - temp_numer1[i] = round_fx(L_sub(L_shl(L_tmp2, sc2), L_shl(L_tmp1, sc1))); +#ifdef BASOP_NOGLOB + temp_numer1[i] = round_fx_sat( L_sub_sat( L_shl_sat( L_tmp2, sc2 ), L_shl_sat( L_tmp1, sc1 ) ) ); +#else + temp_numer1[i] = round_fx( L_sub( L_shl( L_tmp2, sc2 ), L_shl( L_tmp1, sc1 ) ) ); +#endif /* (Q_bwe_exc) */ /* temp_numer2[i] = sub(exc16kWhtnd[i], WN_exc_local[i]); */ @@ -4123,8 +4127,11 @@ void Estimate_mix_factors_fx( tmp = div_s(fracb,fraca); exp1 = sub(expb,expa); - tmp = shl(tmp,exp1); - +#ifdef BASOP_NOGLOB + tmp = shl_sat( tmp, exp1 ); +#else + tmp = shl( tmp, exp1 ); +#endif if(NE_16(num_flag,den_flag)) { tmp = negate(tmp); diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index ce7dfa212..50a98b6b2 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -365,10 +365,17 @@ static void encod_gen_voic_core_switch_fx( { /* code in Q9, gain_pit in Q14 */ L_tmp = L_mult(gcode16, code[i]); - L_tmp = L_shl(L_tmp, 5); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); + L_tmp = L_mac_sat(L_tmp, exc[i ], gain_pit); + L_tmp = L_shl_sat(L_tmp, 1); /* saturation can occur here */ + exc[i ] = round_fx_sat(L_tmp); +#else + L_tmp = L_shl( L_tmp, 5 ); L_tmp = L_mac(L_tmp, exc[i ], gain_pit); L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ exc[i ] = round_fx(L_tmp); +#endif } /* write reserved bits */ @@ -385,7 +392,11 @@ static void encod_gen_voic_core_switch_fx( FOR( i = L_SUBFR; i < 2*L_SUBFR; i++ ) { - exc[i] = round_fx(L_shl(L_mult(exc[i], gain_pit), 1)); +#ifdef BASOP_NOGLOB + exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) ); +#else + exc[i] = round_fx( L_shl( L_mult( exc[i], gain_pit ), 1 ) ); +#endif } return; diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 1cf16e5d5..44751b5dc 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -176,7 +176,11 @@ void transf_cdbk_enc_fx( } m_corr = div_s(m_corr, m_ener); e_corr = sub(e_corr, e_ener); - Ltmp = L_shl(m_corr, s_min(add(e_corr,1),31)); /* Lgain in Q16 */ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ +#else + Ltmp = L_shl( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ +#endif IF ( EQ_16(st_fx->coder_type,INACTIVE)) { Ltmp1 = L_max(gain_code,1); diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index dad3acf3b..5fd64a761 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -264,7 +264,11 @@ Word16 encod_tran_fx( { FOR (i = 0; i < L_SUBFR; i++) { - exc2_fx[i+i_subfr] = round_fx(L_shl(L_mult(gain_pit,exc_fx[i+i_subfr]),1)); +#ifdef BASOP_NOGLOB + exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); +#else + exc2_fx[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); +#endif } } ELSE diff --git a/lib_enc/scale_enc_fx.c b/lib_enc/scale_enc_fx.c index f2b8b186c..0f5575d44 100644 --- a/lib_enc/scale_enc_fx.c +++ b/lib_enc/scale_enc_fx.c @@ -111,7 +111,11 @@ void Preemph_scaled( /* get max of new preemphased samples (L_FRAME+L_FILT) */ L_tmp = L_mult(new_speech[0], QVal); - L_tmp = L_msu(L_tmp, *mem_preemph, mu); +#ifdef BASOP_NOGLOB + L_tmp = L_msu_sat( L_tmp, *mem_preemph, mu ); +#else + L_tmp = L_msu( L_tmp, *mem_preemph, mu ); +#endif L_maxloc = L_abs(L_tmp); FOR (i = 1; i < Lframe; i++) @@ -187,10 +191,15 @@ void Preemph_scaled( } L_tmp = L_mult(new_speech[0], QVal); - L_tmp = L_msu(L_tmp, *mem_preemph, mu); +#ifdef BASOP_NOGLOB + L_tmp = L_msu_sat( L_tmp, *mem_preemph, mu ); + L_tmp = L_shl_sat(L_tmp, *Q_new); + new_speech[0] = round_fx_sat(L_tmp); +#else + L_tmp = L_msu( L_tmp, *mem_preemph, mu ); L_tmp = L_shl(L_tmp, *Q_new); new_speech[0] = round_fx(L_tmp); - +#endif *mem_preemph = tmp_fixed; move16(); } diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index c3420d2e4..194f45b04 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -2496,9 +2496,13 @@ static void calculate_tonality_fx_32( FOR ( n_coeff = 0; n_coeff Date: Fri, 8 Mar 2024 13:00:37 -0500 Subject: [PATCH 04/42] adding basop sat for signal with extreme saturation --- lib_com/wi_fx.c | 32 +++++++++++++++++++++++++++----- lib_enc/gain_enc_fx.c | 12 ++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 9dd61d2da..35832db82 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -3381,7 +3381,11 @@ Word16 ppp_extract_pitch_period_fx( spike=i; move16(); } - en1 =L_mac0(en1, ptr[i], ptr[i]); /* Q0 */ +#ifdef BASOP_NOGLOB + en1 = L_mac0_sat( en1, ptr[i], ptr[i] ); /* Q0 */ +#else + en1 = L_mac0( en1, ptr[i], ptr[i] ); /* Q0 */ +#endif } IF (ptr[spike]>0) @@ -3508,7 +3512,11 @@ Word16 ppp_extract_pitch_period_fx( Lacc = L_deposit_l(0); FOR (i=0; i= 0) { if (GT_32(L_temp,maxPosEn_fx)) @@ -3980,7 +3991,17 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 tmp1 = round_fx(ftmp_real_fx); tmp2 = round_fx(ftmp_imag_fx); - *(farray_ptr_fx + kj) = sub(*(farray_ptr_fx + k), tmp1); +#ifdef BASOP_NOGLOB + *( farray_ptr_fx + kj ) = sub_sat( *( farray_ptr_fx + k ), tmp1 ); + move16(); + *(farray_ptr_fx + kj + 1) = sub_sat(*(farray_ptr_fx + k + 1), tmp2); + move16(); + *(farray_ptr_fx + k) = add_sat(*(farray_ptr_fx + k), tmp1); + move16(); + *(farray_ptr_fx + k + 1) = add_sat(*(farray_ptr_fx + k + 1), tmp2); + move16(); +#else + *( farray_ptr_fx + kj ) = sub( *( farray_ptr_fx + k ), tmp1 ); move16(); *(farray_ptr_fx + kj + 1) = sub(*(farray_ptr_fx + k + 1), tmp2); move16(); @@ -3988,6 +4009,7 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 move16(); *(farray_ptr_fx + k + 1) = add(*(farray_ptr_fx + k + 1), tmp2); move16(); +#endif } } } diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index e18463c2e..d64ee9feb 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -954,7 +954,11 @@ void gain_enc_tc_fx( i = sub(exp_num, exp_den); /* Gain_trans in Q7 */ g_code_fx = i_mult2(g_code_fx, tmp16); /* apply sign */ - *gain_code_fx = L_shr(L_deposit_l(g_code_fx),i); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shr_sat( L_deposit_l( g_code_fx ), i ); +#else + *gain_code_fx = L_shr( L_deposit_l( g_code_fx ), i ); +#endif move32(); /*----------------------------------------------------------------* @@ -1058,7 +1062,11 @@ void gain_enc_tc_fx( move16(); /**gain_code *= gcode0;*/ L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); +#endif move32(); /* Q14 -> Q16 */ push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); } -- GitLab From 0e12e1b95c943be694f8347578369f324d679ea8 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 13:11:13 -0500 Subject: [PATCH 05/42] adding basop sat for signal with extreme saturation --- lib_com/enhancer_fx.c | 12 ++++++++++-- lib_com/swb_tbe_com_fx.c | 7 ++++++- lib_enc/cod_ace_fx.c | 2 +- lib_enc/core_enc_ol_fx.c | 6 +++++- lib_enc/enc_pit_exc_fx.c | 7 ++++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index ab9e9f781..44c399519 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -422,9 +422,17 @@ Word16 E_UTIL_enhancer( L_tmp = L_msu0(L_tmp,tmp,code[1]); if (gain) { - L_tmp = L_shl(L_tmp,gain); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, gain ); +#else + L_tmp = L_shl( L_tmp, gain ); +#endif } - exc2[0] = msu_r(L_tmp,-32768, exc2[0]); +#ifdef BASOP_NOGLOB + exc2[0] = msu_r_sat( L_tmp, -32768, exc2[0] ); +#else + exc2[0] = msu_r( L_tmp, -32768, exc2[0] ); +#endif move16(); FOR (i=1; iprevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) ) && +#ifdef BASOP_NOGLOB + ( GT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) && +#else + ( GT_16( add( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) && +#endif (GE_16(st->acelpFramesCount, 6) )) { dsnr = 512/*2.0f Q8*/; diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index ceb64bad2..316a21865 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -416,8 +416,13 @@ void enc_pit_exc_fx( { Ltmp = L_mult(exc[i + i_subfr], gain_pit); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_sat(Ltmp); +#else + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ exc[i + i_subfr] = round_fx(Ltmp); +#endif } } -- GitLab From 67554765ad5a18f3952cd270d62d8b88b5217da7 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 13:21:26 -0500 Subject: [PATCH 06/42] adding basop sat for signal with extreme saturation --- lib_com/tcx_ltp_fx.c | 6 +++++- lib_com/tcx_utils_fx.c | 6 +++++- lib_enc/cod_tcx_fx.c | 24 ++++++++++++++++++++---- lib_enc/core_enc_ol_fx.c | 6 +++++- lib_enc/ext_sig_ana_fx.c | 6 +++++- lib_enc/tcx_utils_enc_fx.c | 6 +++++- lib_enc/waveadjust_fec_cod_fx.c | 6 +++++- 7 files changed, 50 insertions(+), 10 deletions(-) diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index 39a501dce..17ed9308f 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -44,7 +44,11 @@ void tcx_ltp_get_lpc( if (L_tmp > 0) r = L_shr(r, 2); tmp = shl(x[j], s); - r = L_mac0(r, tmp, tmp); +#ifdef BASOP_NOGLOB + r = L_mac0_sat( r, tmp, tmp ); +#else + r = L_mac0( r, tmp, tmp ); +#endif } r = L_max(r, L_shl(100, shl(s, 1))); r = Mpy_32_16_1(r, 16386/*1.0001f Q14*/); diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 3f0d0887c..bf6fdcef1 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -474,7 +474,11 @@ void tcx_windowing_synthesis_current_frame( { /*remove reconstructed ZIR and add ACELP ZIR*/ move16(); - signal[i+overlap+acelp_mem_len] = sub(signal[i+overlap+acelp_mem_len], mult_r(acelp_zir[i], div_s(sub(acelp_zir_len, i), acelp_zir_len))); +#ifdef BASOP_NOGLOB + signal[i + overlap + acelp_mem_len] = sub_sat( signal[i + overlap + acelp_mem_len], mult_r_sat( acelp_zir[i], div_s( sub_sat( acelp_zir_len, i ), acelp_zir_len ) ) ); +#else + signal[i + overlap + acelp_mem_len] = sub( signal[i + overlap + acelp_mem_len], mult_r( acelp_zir[i], div_s( sub( acelp_zir_len, i ), acelp_zir_len ) ) ); +#endif } } /* Rectangular window (past-frame is TCX) */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 035e03000..59fbb808b 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -2581,7 +2581,11 @@ void QuantizeSpectrum_fx( tmp1 = sub(overlap, hTcxCfg->tcx_mdct_window_min_length); FOR (i=0; i < tmp1; i++) { - xn_buf16[i] = shl(add(xn_buf16[i], shr(hTcxEnc->old_out_fx[i+nz], tmp2)), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], shr_sat( hTcxEnc->old_out_fx[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( add( xn_buf16[i], shr( hTcxEnc->old_out_fx[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#endif move16(); } @@ -2590,19 +2594,31 @@ void QuantizeSpectrum_fx( FOR ( ; i < tmp1; i++) { tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[i-overlap+hTcxCfg->tcx_mdct_window_min_length].v.re); - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( add( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR ( ; i < overlap; i++) { tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[overlap-1-i].v.im); - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( add( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR ( ; i < L_frame; i++) { - xn_buf16[i] = shl(xn_buf16[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( xn_buf16[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( xn_buf16[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index 9c5dba516..fb31e3794 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -1233,7 +1233,11 @@ void core_acelp_tcx20_switching_fx( #else /* BASOP_NOGLOB */ (LT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) || EQ_16(stab_fac, 0x7fff) || #endif - (EQ_32(st->sr_core, INT_FS_12k8) && EQ_16(st->sp_aud_decision0,1) && LT_16(add(st->prevTempFlatness_fx, currFlatness), 2560/*20.f Q7*/) )) && +#ifdef BASOP_NOGLOB + ( EQ_32( st->sr_core, INT_FS_12k8 ) && EQ_16( st->sp_aud_decision0, 1 ) && LT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && +#else + ( EQ_32( st->sr_core, INT_FS_12k8 ) && EQ_16( st->sp_aud_decision0, 1 ) && LT_16( add( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && +#endif (LE_16(st->acelpFramesCount, 6) )) { dsnr = -512/*-2.0f Q8*/; diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 6df5c076a..fc8f6b666 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -310,7 +310,11 @@ void core_signal_analysis_high_bitrate_fx( /* Outter left folding */ FOR(i = 0; i < folding_offset; i++) { - tcx20Win[folding_offset + i] = sub(tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i]); +#ifdef BASOP_NOGLOB + tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); +#else + tcx20Win[folding_offset + i] = sub( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); +#endif move16(); } #ifdef IVAS_CODE diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index c9536fdb9..9a12aaefe 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -869,7 +869,11 @@ Word16 tcx_scalar_quantization_rateloop_fx( /* convert to normalized 16 bit */ tmp = norm_l(tmp32); - sqGain = round_fx(L_shl(tmp32, tmp)); +#ifdef BASOP_NOGLOB + sqGain = round_fx_sat( L_shl( tmp32, tmp ) ); +#else + sqGain = round_fx( L_shl( tmp32, tmp ) ); +#endif sqGain_e = sub(sqGain_e, tmp); /* divide */ diff --git a/lib_enc/waveadjust_fec_cod_fx.c b/lib_enc/waveadjust_fec_cod_fx.c index 988d7564c..eb5b8953d 100644 --- a/lib_enc/waveadjust_fec_cod_fx.c +++ b/lib_enc/waveadjust_fec_cod_fx.c @@ -38,7 +38,11 @@ Word32 SFM_Cal_fx(Word32 magn[], Word16 n) /* sum(log2(magn(i))) */ sumLogMagn =L_add(sumLogMagn, logMagn); /* Q8 */ - sumMagn =L_add(sumMagn, magn_abs); +#ifdef BASOP_NOGLOB + sumMagn = L_add_sat( sumMagn, magn_abs ); +#else + sumMagn = L_add( sumMagn, magn_abs ); +#endif } IF(EQ_32(sumMagn,MAX_32)) -- GitLab From 23502c78562df5a515f18322c5e47fab0c02fcf7 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 13:30:00 -0500 Subject: [PATCH 07/42] adding basop sat for signal with extreme saturation --- lib_com/re8_util_fx.c | 7 +++++-- lib_enc/enc_higher_acelp_fx.c | 9 +++++++-- lib_enc/gain_enc_fx.c | 6 +++++- lib_enc/q_gain2p_fx.c | 6 +++++- lib_enc/swb_tbe_enc_fx.c | 35 ++++++++++++++++++++++++++++------- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/lib_com/re8_util_fx.c b/lib_com/re8_util_fx.c index 012441be6..8526ddc24 100644 --- a/lib_com/re8_util_fx.c +++ b/lib_com/re8_util_fx.c @@ -276,8 +276,11 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y i { Ls = L_mac( Ls, y[i], y[i]); } - s = extract_h(L_shl(Ls, 16-(3+1))); /* s can saturate here */ - +#ifdef BASOP_NOGLOB + s = extract_h( L_shl_sat( Ls, 16 - ( 3 + 1 ) ) ); /* s can saturate here */ +#else + s = extract_h( L_shl( Ls, 16 - ( 3 + 1 ) ) ); /* s can saturate here */ +#endif /*-----------------------------------------------------------------------* * compute the index 0 <= ka <= NB_LEADER+1 which identifies an absolute leader of Q0, Q2, Q3 or Q4 * diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 44751b5dc..0ccb17be7 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -148,11 +148,12 @@ void transf_cdbk_enc_fx( { /*fcorr += fx_tran[i]*(float)ix_norm[i];*/ /*fener += (float)ix_norm[i]*(float)ix_norm[i];*/ - stmp = shl(x_norm[i],Q_AVQ_OUT ); #ifdef BASOP_NOGLOB + stmp = shl_sat( x_norm[i], Q_AVQ_OUT ); L_corr = L_mac_sat( L_corr, x_tran[i], stmp ); L_ener = L_mac_sat(L_ener, stmp, stmp); #else + stmp = shl( x_norm[i], Q_AVQ_OUT ); L_corr = L_mac( L_corr, x_tran[i], stmp ); L_ener = L_mac(L_ener, stmp, stmp); #endif @@ -185,7 +186,11 @@ void transf_cdbk_enc_fx( { Ltmp1 = L_max(gain_code,1); e_den = norm_l(Ltmp1); - m_den = extract_h(L_shl(Ltmp1, e_den)); +#ifdef BASOP_NOGLOB + m_den = extract_h( L_shl_sat( Ltmp1, e_den ) ); +#else + m_den = extract_h( L_shl( Ltmp1, e_den ) ); +#endif /* ensure m_corr < m_den */ test(); IF( m_corr>0 && m_den >0) diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index d64ee9feb..3af0e6b26 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -767,7 +767,11 @@ void gain_enc_SQ_fx( L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ exp_div = sub(exp_num,exp_den); - *gain_code = L_shl(L_div,s_max(-31,sub(add(exp,exp_div),14))); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( L_div, s_max( -31, sub( add( exp, exp_div ), 14 ) ) ); +#else + *gain_code = L_shl( L_div, s_max( -31, sub( add( exp, exp_div ), 14 ) ) ); +#endif move32();/*Q16*/ *gain_pit = s_max(G_PITCH_MIN_Q14,s_min(*gain_pit,G_PITCH_MAX_Q14)); diff --git a/lib_enc/q_gain2p_fx.c b/lib_enc/q_gain2p_fx.c index 03fb36a8d..0a9b73ce4 100644 --- a/lib_enc/q_gain2p_fx.c +++ b/lib_enc/q_gain2p_fx.c @@ -587,7 +587,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index } - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#else + *gain_code = L_shl( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#endif move32(); *gain_pit = 0; diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index a1af7d2ba..997154a61 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -2404,11 +2404,17 @@ static void EstimateSHBGainShape_fx( FOR( k = 0; k < length; k++ ) { sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - +#ifdef BASOP_NOGLOB + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ +#else + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ +#endif sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ - +#ifdef BASOP_NOGLOB + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ +#else + synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ +#endif } } IF( i == NUM_SHB_SUBFR / 2 - 1 ) @@ -2417,10 +2423,18 @@ static void EstimateSHBGainShape_fx( FOR( ; k < length_tmp; k++ ) { sig = mult_r( oriSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ +#ifdef BASOP_NOGLOB + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ +#else + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ +#endif sig = mult_r( synSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ +#ifdef BASOP_NOGLOB + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ +#else + synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ +#endif } } ELSE @@ -2428,10 +2442,17 @@ static void EstimateSHBGainShape_fx( FOR(; k < length2; k++ ) { sig = mult_r( oriSHB[j + k], subwin[2 * length - k - 1] ); /* Q_oriSHB */ +#ifdef BASOP_NOGLOB + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ +#else oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - +#endif sig = mult_r( synSHB[j + k], subwin[2 * length - k - 1] ); /* Q_synSHB */ +#ifdef BASOP_NOGLOB + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ +#else synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ +#endif } } -- GitLab From ee49bab8fa5812ddc7d35e2d068741afc96729a5 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 13:41:02 -0500 Subject: [PATCH 08/42] adding basop sat for signal with extreme saturation --- lib_enc/enc_pit_exc_fx.c | 8 +++++++- lib_enc/swb_bwe_enc_fx.c | 6 +++++- lib_enc/swb_bwe_enc_hr_fx.c | 6 +++++- lib_enc/tcx_ltp_enc_fx.c | 8 +++++++- lib_enc/tcx_utils_enc_fx.c | 7 +++++-- lib_enc/tfa_enc_fx.c | 6 +++++- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 316a21865..466fa3b2a 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -381,9 +381,15 @@ void enc_pit_exc_fx( ELSE { Ltmp = L_mult(xn[L_subfr - 1], 16384); - Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); +#ifdef BASOP_NOGLOB + Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); + Ltmp = L_shl_sat(Ltmp, sub(1, shift)); + hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ +#else + Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); Ltmp = L_shl(Ltmp, sub(1, shift)); hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ +#endif } /*-----------------------------------------------------------------* diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 194f45b04..72abfe2be 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -2066,7 +2066,11 @@ static Word16 SWB_BWE_encoding_fx( L_tmp = L_deposit_h(tmp); L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - SWB_tenv_fx[n_band] = round_fx(L_shl(L_tmp, sub(exp, 12))); /*Q3 */ +#ifdef BASOP_NOGLOB + SWB_tenv_fx[n_band] = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /*Q3 */ +#else + SWB_tenv_fx[n_band] = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /*Q3 */ +#endif } } diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index 21a407c1f..ea89b22fa 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -547,7 +547,11 @@ void swb_bwe_enc_hr_fx( L_temp = Calc_Energy_Autoscaled(ptr16, t_audio_fx_exp, WIDTH_NONTRANS_FREQ_COEF, &temp2); ptr16 += WIDTH_NONTRANS_FREQ_COEF; L_temp = Sqrt_Ratio32(L_temp, temp2, WIDTH_NONTRANS_FREQ_COEF, /*WIDTH_TRANS_FREQ_COEF is in Q0*/0, &temp2); - en_band_fx[i] = round_fx(L_shr(L_temp, sub(15-9, temp2))); /* Put in Q9 */ +#ifdef BASOP_NOGLOB + en_band_fx[i] = round_fx_sat( L_shr_sat( L_temp, sub( 15 - 9, temp2 ) ) ); /* Put in Q9 */ +#else + en_band_fx[i] = round_fx( L_shr( L_temp, sub( 15 - 9, temp2 ) ) ); /* Put in Q9 */ +#endif } /* Q energy per band */ diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 27b37c89b..71d5b36cf 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -296,9 +296,15 @@ static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_fra FOR (i = 0; i < L_frame; i++) { - tmp = shl(pred_speech[i], s2); +#ifdef BASOP_NOGLOB + tmp = shl_sat( pred_speech[i], s2 ); + corr = L_mac0_sat(corr, shl(speech[i], s1), tmp); + ener = L_mac0_sat(ener, tmp, tmp); +#else + tmp = shl( pred_speech[i], s2 ); corr = L_mac0(corr, shl(speech[i], s1), tmp); ener = L_mac0(ener, tmp, tmp); +#endif } s1 = sub(1, add(s1, s2)); diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 9a12aaefe..cc96f9c27 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1651,8 +1651,11 @@ Word16 tcx_res_Q_gain_fx( } /* bring sqGain to same exponent */ - sqGain = shr(sqGain, sub(gain_reQ_e, sqGain_e)); - +#ifdef BASOP_NOGLOB + sqGain = shr_sat( sqGain, sub( gain_reQ_e, sqGain_e ) ); +#else + sqGain = shr( sqGain, sub( gain_reQ_e, sqGain_e ) ); +#endif FOR (bits=0; bits < TCX_RES_Q_BITS_GAIN; bits++) { IF (LT_16(sqGain, gain_reQ)) diff --git a/lib_enc/tfa_enc_fx.c b/lib_enc/tfa_enc_fx.c index 66ee96687..0dba7d0c9 100644 --- a/lib_enc/tfa_enc_fx.c +++ b/lib_enc/tfa_enc_fx.c @@ -31,7 +31,11 @@ void tfaCalcEnv_fx( enr[i] = L_deposit_l(0); FOR (j=0; j Date: Fri, 8 Mar 2024 13:44:57 -0500 Subject: [PATCH 09/42] adding basop sat for signal with extreme saturation --- lib_enc/cng_enc_fx.c | 6 +++++- lib_enc/cod_ace_fx.c | 6 +++++- lib_enc/enc_amr_wb_fx.c | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index e18b66d00..58ccae7d9 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -840,7 +840,11 @@ void CNG_enc_fx( L_tmp1 = L_add(env[i], 0); FOR ( j=0; j< hDtxEnc->cng_hist_size; j++ ) { - L_tmp1 = L_add(L_tmp1,hTdCngEnc->cng_res_env_fx[j*NUM_ENV_CNG+i]); +#ifdef BASOP_NOGLOB + L_tmp1 = L_add_sat( L_tmp1, hTdCngEnc->cng_res_env_fx[j * NUM_ENV_CNG + i] ); +#else + L_tmp1 = L_add( L_tmp1, hTdCngEnc->cng_res_env_fx[j * NUM_ENV_CNG + i] ); +#endif } L_tmp = L_add(hTdCngEnc->cng_res_env_fx[max_idx1[0]*NUM_ENV_CNG+i],hTdCngEnc->cng_res_env_fx[max_idx1[1]*NUM_ENV_CNG+i]); L_tmp1 = L_sub(L_tmp1,L_tmp); diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index e98070d08..c5709fe4c 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -388,7 +388,11 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ Ltmp2 = Mpy_32_16_1(gain_code, code[i]); Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); +#ifdef BASOP_NOGLOB + Ltmp = L_add_sat( Ltmp, Ltmp2 ); +#else + Ltmp = L_add( Ltmp, Ltmp2 ); +#endif #ifdef BASOP_NOGLOB Ltmp = L_shl_o(Ltmp, 1, &Overflow); /* saturation can occur here */ exc[i + i_subfr] = round_fx_o(Ltmp, &Overflow); diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index be7d3bd07..1bf5d1f64 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -226,7 +226,11 @@ void encod_amr_wb_fx( { L_tmp = L_mult(gcode16, code[i]); L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc[i + i_subfr], gain_pit); +#ifdef BASOP_NOGLOB + L_tmp = L_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); +#else + L_tmp = L_mac( L_tmp, exc[i + i_subfr], gain_pit ); +#endif #ifdef BASOP_NOGLOB L_tmp = L_shl_o(L_tmp, 1, &Overflow); /* saturation can occur here */ exc[i + i_subfr] = round_fx_o(L_tmp, &Overflow); -- GitLab From 96f97a43250c58913ace09f975ef6b40ecdfa728 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 14:07:53 -0500 Subject: [PATCH 10/42] adding basop sat for signal with extreme saturation --- lib_com/hp50.c | 6 +++++- lib_com/trans_inv_fx.c | 29 +++++++++++++++++++++-------- lib_dec/FEC_HQ_core_fx.c | 12 ++++++++++-- lib_dec/LD_music_post_filter_fx.c | 18 +++++++++++++++--- lib_dec/gain_dec_fx.c | 19 +++++++++++++++---- lib_dec/hq_lr_dec_fx.c | 26 +++++++++++++++++++++----- lib_dec/nelp_dec_fx.c | 12 ++++++++++-- 7 files changed, 97 insertions(+), 25 deletions(-) diff --git a/lib_com/hp50.c b/lib_com/hp50.c index 0f950af36..eb96f2a40 100644 --- a/lib_com/hp50.c +++ b/lib_com/hp50.c @@ -322,7 +322,11 @@ void hp20(Word16 signal[], /* i/o: signal to filter any * prescale = getScaleFactor16(signal, lg); prescaleOld = extract_l(mem[4]); - diff = norm_l(L_shl(mem[2], prescaleOld)); +#ifdef BASOP_NOGLOB + diff = norm_l( L_shl_sat( mem[2], prescaleOld ) ); +#else + diff = norm_l( L_shl( mem[2], prescaleOld ) ); +#endif if (mem[2] != 0) { prescale = s_min(prescale, diff); diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index 67fc70bfe..6404b8434 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -147,12 +147,20 @@ void preecho_sb_fx( fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; FOR( i = 0; i < len3xLp20; i++ ) { - *fxptr1++ = negate(extract_h(L_shl(*fx32ptr1--,15-q_sig32))); +#ifdef BASOP_NOGLOB + *fxptr1++ = negate( extract_h( L_shl_sat( *fx32ptr1--, 15 - q_sig32 ) ) ); +#else + *fxptr1++ = negate( extract_h( L_shl( *fx32ptr1--, 15 - q_sig32 ) ) ); +#endif move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ } FOR( i = 0; i < L_shr(framelength, 1); i++ ) { - *fxptr1++ = negate(extract_h(L_shl(wtda_audio_fx[i], 15-q_sig32))); +#ifdef BASOP_NOGLOB + *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], 15 - q_sig32 ) ) ); +#else + *fxptr1++ = negate( extract_h( L_shl( wtda_audio_fx[i], 15 - q_sig32 ) ) ); +#endif move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ } qmemp1 = 0; /*already in q-1*/ @@ -253,11 +261,15 @@ void preecho_sb_fx( FOR (j = 0; j < NUMSF; j++) /* 8 present subframes */ { tmp_fx2 = sub(j, 1); - tmp_fx1 = shr(*fxptr2, q16p1); /*q-1 to avoisd saturation in energy*/ +#ifdef BASOP_NOGLOB + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat(25, tmp_fx1, tmp_fx1); + tmp_fxL2 = L_mac0_sat(100, *fxptr3, *fxptr3); +#else + tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ tmp_fxL1 = L_mac0(25, tmp_fx1, tmp_fx1); - tmp_fxL2 = L_mac0(100, *fxptr3, *fxptr3); - +#endif sptr2_loc = 0; move16(); @@ -277,12 +289,13 @@ void preecho_sb_fx( *fx32ptr6 = tmp_fxL1; move32(); } - tmp_fx1 = shr(*fxptr2, q16p1); /*q-1 to avoisd saturation in energy*/ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac0_sat(tmp_fxL1, tmp_fx1, tmp_fx1); + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); tmp_fxL2 = L_mac0_sat(tmp_fxL2, *fxptr3, *fxptr3); #else - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); + tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); tmp_fxL2 = L_mac0(tmp_fxL2, *fxptr3, *fxptr3); #endif cntnzcr = add(cntnzcr, 1); diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 61620e003..d79a53fba 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -1535,7 +1535,11 @@ static void Repetition_smoothing_nextgood_fx( /*mvr2r(&ImdctOutWin[L], OldauOut, L);*/ FOR (i = 0; i < L; i++) { - auOut_fx[i] = add(ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i]); +#ifdef BASOP_NOGLOB + auOut_fx[i] = add_sat( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); +#else + auOut_fx[i] = add( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); +#endif move16(); } Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); @@ -1626,7 +1630,11 @@ static void common_overlapping_fx( FOR (i=0 ; i < end1; i++) { /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ - auOut_fx[i] = add(ImdctOutWin_fx[i+N_ZERO_NB], OldauOut_fx[i+offset1]); +#ifdef BASOP_NOGLOB + auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); +#else + auOut_fx[i] = add( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); +#endif move16(); } FOR (i=start2 ; i < end2; i++) diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index e47fd61b8..94ed7c6db 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -344,7 +344,11 @@ void LD_music_post_filter_fx tmp16 = s_min(max_ovf_4k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_4k, tmp16); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } test(); @@ -356,7 +360,11 @@ void LD_music_post_filter_fx tmp16 = s_min(max_ovf_6k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_6k, tmp16); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } } } @@ -367,7 +375,11 @@ void LD_music_post_filter_fx { tmp16 = s_min(4096, hMusicPF->filt_lfE_fx[i]); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } } } diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 360d05a87..08bde0c11 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -188,7 +188,11 @@ void gain_dec_tc_fx( /* *gain_code *= gcode0;*/ L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); +#endif move32(); /* Q14 -> Q16 */ /**norm_gain_code = *gain_code / *gain_inov;*/ @@ -742,8 +746,11 @@ void gain_dec_lbr_fx( move16(); L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); /* Q10 -> Q16*/ - +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ +#endif gc_mem[2] = *gain_code_fx; move32(); gp_mem[2] = *gain_pit_fx; @@ -822,7 +829,11 @@ void gain_dec_lbr_fx( move16(); L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); +#endif move32(); /* Q10 -> Q16*/ } diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index d6e9eee5b..f3781547e 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -344,7 +344,11 @@ void hq_lr_dec_fx( frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ L_tmp = Pow2(30, frac1); exp = sub(exp, 30); - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ +#ifdef BASOP_NOGLOB + Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#else + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#endif } FOR( i = 0; i < bands_fx; i++ ) @@ -419,13 +423,21 @@ void hq_lr_dec_fx( { IF( GE_16(i,lowband)) { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#else + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - +#endif } ELSE { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif if(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) { Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ @@ -545,7 +557,11 @@ void hq_lr_dec_fx( { IF(GE_16(i,lowband)) { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif } ELSE { diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 9aa4f3ae2..02722e269 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -369,7 +369,11 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 E2 = L_deposit_l(1); FOR (i=0 ; i Date: Fri, 8 Mar 2024 14:12:34 -0500 Subject: [PATCH 11/42] adding basop sat for signal with extreme saturation --- lib_dec/dec_tcx_fx.c | 24 ++++++++++++++++++++---- lib_dec/post_dec_fx.c | 10 +++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 6a7f538c3..a2084a2d8 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2122,7 +2122,11 @@ void IMDCT(Word32 *x, Word16 x_e, tmp1 = sub(overlap, tcx_mdct_window_min_length); FOR (i=0; i < tmp1; i++) { - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], shr(old_out[i+nz], tmp2)), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp4] = shl_sat( add( xn_buf[i + tmp4], shr( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], shr( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#endif move16(); } @@ -2131,19 +2135,31 @@ void IMDCT(Word32 *x, Word16 x_e, FOR ( ; i < tmp1; i++) { tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[i-overlap+tcx_mdct_window_min_length].v.re); - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp4] = shl_sat( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR ( ; i < overlap; i++) { tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[overlap-1-i].v.im); - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp4] = shl_sat( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR (i = add(i, tmp4) ; i < L_frame; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index bc093265f..48e4e71b6 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -324,9 +324,13 @@ static void bass_pf_1sf_delay( tmp16 = mac_r(tmp32, gain, syn[i+i_subfr]); /* Q0 */ #endif lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); - lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ - - tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ +#ifdef BASOP_NOGLOB + lp_error = L_mac_sat( lp_error, tmp16, 0x1000 ); /* Q13 */ + tmp16 = round_fx_sat( L_shl_sat( lp_error, s1 ) ); /* Q0+s1-3 */ +#else + lp_error = L_mac( lp_error, tmp16, 0x1000 ); /* Q13 */ + tmp16 = round_fx( L_shl( lp_error, s1 ) ); /* Q0+s1-3 */ +#endif ener2_64 = W_mac0_16_16(ener2_64, tmp16, tmp16); /* Q0+(s1-3)*2 */ } ener2 = W_sat_l(ener2_64); -- GitLab From 0d78f2ba7f4b466257f056314bccc4359f5f9012 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 14:20:42 -0500 Subject: [PATCH 12/42] adding basop sat for signal with extreme saturation --- lib_com/swb_bwe_com_fx.c | 39 +++++++++++++++++++++++++++++++++------ lib_com/window_ola_fx.c | 12 +++++++++--- lib_dec/dec_ace_fx.c | 6 +++++- lib_dec/evs_dec_fx.c | 12 ++++++++++-- lib_dec/swb_bwe_dec_fx.c | 6 +++++- lib_dec/swb_tbe_dec_fx.c | 7 +++++-- 6 files changed, 67 insertions(+), 15 deletions(-) diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 83c87aecf..8abea5c6b 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -442,7 +442,11 @@ void calc_norm_envelop_lf_fx( tmp = add(lookback, n_freq); FOR(n_lag = 0; n_lag < tmp; n_lag++) { - L_tmp = L_add(L_tmp, L_abs(SWB_signal[n_lag])); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[n_lag] ) ); +#else + L_tmp = L_add( L_tmp, L_abs( SWB_signal[n_lag] ) ); +#endif } envelope[env_index] = L_tmp; move32(); @@ -455,7 +459,11 @@ void calc_norm_envelop_lf_fx( Word32 L_tmp = L_deposit_l(1); FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)])); +#else L_tmp = L_add(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)])); +#endif } envelope[env_index] = L_tmp; @@ -1570,8 +1578,11 @@ void SWB_BWE_decoding_fx( exp = norm_s(SWB_FENV); tmp = div_s(shl(1,sub(14,exp)),SWB_FENV); /*Q(29-exp) */ L_tmp = Mult_32_16(L_energy,tmp); /*Q(1+29-exp+1)->Q(15-exp) */ - Energy_16 = round_fx(L_shl(L_tmp,add(exp,4))); /*Q3 */ - +#ifdef BASOP_NOGLOB + Energy_16 = round_fx_sat( L_shl_sat( L_tmp, add( exp, 4 ) ) ); /*Q3 */ +#else + Energy_16 = round_fx( L_shl( L_tmp, add( exp, 4 ) ) ); /*Q3 */ +#endif IF(NE_16(last_extl, SWB_BWE) && NE_16(last_extl,FB_BWE)) { IF(Energy_16 < shr(EnergyL_16, 4) && EQ_16(extl, FB_BWE)) @@ -1937,7 +1948,11 @@ void SWB_BWE_decoding_fx( } } +#ifdef BASOP_NOGLOB + IF(GT_16(*prev_Energy,add_sat(Energy_16,shr(Energy_16,2))) && Energy_16 > 0) +#else IF(GT_16(*prev_Energy,add(Energy_16,shr(Energy_16,2))) && Energy_16 > 0) +#endif { weight = shr(div_s(Energy_16,*prev_Energy),1); /*Q15 */ } @@ -2004,7 +2019,11 @@ void SWB_BWE_decoding_fx( L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1); move32(); /*15+Qsyn */ - factor = add(factor, factor1); /*Q1 */ +#ifdef BASOP_NOGLOB + factor = add_sat( factor, factor1 ); /*Q1 */ +#else + factor = add( factor, factor1 ); /*Q1 */ +#endif } } L_tmp = L_mult(weight, prev_SWB_fenv[13]); /*Q17 */ @@ -2213,7 +2232,11 @@ void time_reduce_pre_echo_fx( L_tmp = L_deposit_l(0); FOR(j = 0; j < L; j++) { - L_tmp = L_mac0(L_tmp, synth[Len + j], synth[Len + j]); /*2*Q_syn */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */ +#else + L_tmp = L_mac0( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */ +#endif } energyL[i] = Mult_32_16(L_shr(L_tmp, sub(14, exp_L)), inv_L); move32(); /*Q(2*Q_syn +29-exp_L-15 - (14-exp_L) ) -> Q(2*Q_syn) */ @@ -2628,7 +2651,11 @@ void hq_generic_decoding_fx( tmp = div_s(16384, frac);/*15 + 14 - (cs+exp-16) */ exp = sub(add(cs, exp), 30); L_tmp = Isqrt_lc(L_deposit_h(tmp), &exp);/*Q31 - exp */ - fenvL_fx = round_fx(L_shl(L_tmp, sub(exp, 14)));/*Q1 */ +#ifdef BASOP_NOGLOB + fenvL_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ +#else + fenvL_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ +#endif } calc_normal_length_fx_32(HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm); diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 38cc8afaf..52506e037 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -857,9 +857,15 @@ void core_switching_OLA_fx( temp_len = i_mult2(shr(R2_16,2), delta); FOR( i=0 ; i Q15 */ - *pt2 = shl( mult_r(*pt2,*pt4),1); +#ifdef BASOP_NOGLOB + *pt = shl_sat( mult_r_sat( *pt, *pt5 ), 1 ); + move16(); /* // Q14* Q15 + shl ==> Q15 */ + *pt2 = shl_sat( mult_r_sat( *pt2, *pt4 ), 1 ); +#else + *pt = shl( mult_r( *pt, *pt5 ), 1 ); + move16(); /* // Q14* Q15 + shl ==> Q15 */ + *pt2 = shl( mult_r( *pt2, *pt4 ), 1 ); +#endif move16();/*/= win[(3*L_FRAME16k/2-1-i/2)*decimate+decay-L_FRAME48k*14/20]; */ pt+=2; pt2+=2; diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index d659e3277..70dad2d2e 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -469,7 +469,11 @@ void decoder_acelp( Ltmp2 = L_shl(Ltmp2, add(5,st->Q_exc)); Ltmp = L_add(Ltmp, Ltmp2); BASOP_SATURATE_WARNING_OFF_EVS - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ +#else + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ +#endif BASOP_SATURATE_WARNING_ON_EVS exc[i + i_subfr] = round_fx(Ltmp); } diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 5f178a044..112cd825b 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1307,7 +1307,11 @@ ivas_error evs_dec_fx( FOR (i = 0; i < tmps; i++) { - output_sp[i+tmps] = msu_r(L_mult(shr(pcmbufFB[i], timeIn_e), alpha), output_sp[i+tmps], add(alpha, -32768)); +#ifdef BASOP_NOGLOB + output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); +#else + output_sp[i + tmps] = msu_r( L_mult( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); +#endif move16(); alpha = add(alpha, step); } @@ -1345,7 +1349,11 @@ ivas_error evs_dec_fx( FOR (i = delta; i < tmps; i++) { - output_sp[i] = msu_r(L_mult(output_sp[i], alpha), shr(hTcxDec->FBTCXdelayBuf[i], timeIn_e), add(alpha, -32768)); +#ifdef BASOP_NOGLOB + output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); +#else + output_sp[i] = msu_r( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); +#endif move16(); #ifdef BASOP_NOGLOB alpha = add_sat(alpha, step); diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index ef505ae45..4371e6380 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -870,7 +870,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub(exp, 13); - SWB_fenv[n_band] = shl(tmp, add(exp,1)); +#ifdef BASOP_NOGLOB + SWB_fenv[n_band] = shl_sat( tmp, add( exp, 1 ) ); +#else + SWB_fenv[n_band] = shl( tmp, add( exp, 1 ) ); +#endif move16();/*Q1 */ } diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 05a0fbe2f..1eae52126 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -2598,8 +2598,11 @@ void swb_tbe_dec_fx( #endif } } - ener = s_max(1, round_fx( L_shl( L_ener, sub(19, shl(Q_bwe_exc, 1)) ) )); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ - +#ifdef BASOP_NOGLOB + ener = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ +#else + ener = s_max( 1, round_fx( L_shl( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ +#endif /* WB/SWB bandwidth switching */ IF( st_fx->bws_cnt_fx > 0 ) { -- GitLab From 90b2a27abaf2f7e3eebb20e486519db777ae3e47 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 14:25:49 -0500 Subject: [PATCH 13/42] adding basop sat for signal with extreme saturation --- lib_dec/bass_psfilter_fx.c | 7 ++++--- lib_dec/d_gain2p_fx.c | 6 +++++- lib_dec/dec_tcx_fx.c | 6 +++++- lib_dec/er_sync_exc_fx.c | 12 ++++++++++-- lib_dec/swb_tbe_dec_fx.c | 8 ++++++++ 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 7a5d8476b..3f9497bc4 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -452,11 +452,12 @@ void bass_psfilter_fx( FOR (i=0; i< subfr_len; i++) { /*syn2_fx[i] = alpha*(syn_fx[i]-syn2_fx[i]); */ - tmp = sub(syn_fx[i],syn2_fx[i]); #ifdef BASOP_NOGLOB - syn2_fx[i] = mult_sat(alpha, shl_sat(tmp, 1)); + tmp = sub_sat( syn_fx[i], syn2_fx[i] ); + syn2_fx[i] = mult_sat( alpha, shl_sat( tmp, 1 ) ); #else - syn2_fx[i] = mult(alpha,shl(tmp,1)); + tmp = sub( syn_fx[i], syn2_fx[i] ); + syn2_fx[i] = mult( alpha, shl( tmp, 1 ) ); #endif move16();/*Q_syn2 */ } diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index ce1f1b908..2c380170d 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -304,7 +304,11 @@ static void gain_dec_gacelp_uv( *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32(); - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#else + *gain_code = L_shl( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#endif move32(); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index a2084a2d8..79e7475b3 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2211,7 +2211,11 @@ void IMDCT(Word32 *x, Word16 x_e, { FOR (i = add(i, tmp1); i < L_frame; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 23145a7d0..6703b5404 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -54,10 +54,18 @@ static Word16 GetMinimumPosition( FOR (i = 0; i < cnt; i++) { tmp16 = shr(x[i],tmp_e); - energy = L_msu(energy_old,tmp16,tmp16); +#ifdef BASOP_NOGLOB + energy = L_msu_sat( energy_old, tmp16, tmp16 ); +#else + energy = L_msu( energy_old, tmp16, tmp16 ); +#endif tmp16 = shr(x[i+filterLength],tmp_e); BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ - energy = L_mac(energy,tmp16,tmp16); +#ifdef BASOP_NOGLOB + energy = L_mac_sat( energy, tmp16, tmp16 ); +#else + energy = L_mac( energy, tmp16, tmp16 ); +#endif BASOP_SATURATE_WARNING_ON_EVS /*if (energy == MAXVAL_WORD32)*/ diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 1eae52126..91639f73a 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3222,7 +3222,11 @@ void swb_tbe_dec_fx( tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); +#ifdef BASOP_NOGLOB + st_fx->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#else st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#endif } /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ @@ -3236,7 +3240,11 @@ void swb_tbe_dec_fx( tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#else tmp = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#endif } set16_fx(st_fx->prev_SWB_fenv_fx, tmp, SWB_FENV); /* Q1 */ -- GitLab From 1f3443a6d3644e0ec7dd586bcaf53d63425a343f Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 14:45:36 -0500 Subject: [PATCH 14/42] adding basop sat for signal with extreme saturation --- lib_com/enhancer_fx.c | 12 ++++++++++-- lib_com/fft_fx_evs.c | 6 +++++- lib_com/hq_tools_fx.c | 24 ++++++++++++++++++++---- lib_com/swb_bwe_com_fx.c | 6 +++++- lib_com/swb_tbe_com_fx.c | 25 ++++++++++++++++++++----- lib_dec/LD_music_post_filter_fx.c | 6 +++++- lib_dec/dec_tcx_fx.c | 28 ++++++++++++++++++++++++---- lib_dec/evs_dec_fx.c | 6 +++++- lib_dec/hq_hr_dec_fx.c | 6 +++++- lib_dec/swb_tbe_dec_fx.c | 4 ++++ 10 files changed, 103 insertions(+), 20 deletions(-) diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 44c399519..a70a31358 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -257,7 +257,11 @@ void enhancer_fx( L_tmp = L_deposit_h(code[L_SUBFR - 1]);/*Q28 */ L_tmp = L_msu(L_tmp, code[L_SUBFR - 2], tmp);/*Q28 */ L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); - pt_exc2[L_SUBFR - 1] = msu_r(L_tmp, -32768, pt_exc2[L_SUBFR - 1]); +#ifdef BASOP_NOGLOB + pt_exc2[L_SUBFR - 1] = msu_r_sat( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); +#else + pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); +#endif move16();/* in Q_exc */ test(); test(); @@ -553,7 +557,11 @@ static void phase_dispersion_fx( prev_gain_pit[0] = gain_pit; move16(); - IF (GT_32(L_sub(gain_code, *prev_gain_code), L_shl(*prev_gain_code, 1))) +#ifdef BASOP_NOGLOB + IF( GT_32( L_sub_sat( gain_code, *prev_gain_code ), L_shl_sat( *prev_gain_code, 1 ) ) ) +#else + IF( GT_32( L_sub( gain_code, *prev_gain_code ), L_shl( *prev_gain_code, 1 ) ) ) +#endif { state = s_min(add(state, 1), 2); } diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index b6ed50554..53ad86ae4 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -1071,7 +1071,11 @@ static void fft5_shift4_16fx( move16(); T3 = zRe[i4]; move16(); - T4 = add(T2,T3); +#ifdef BASOP_NOGLOB + T4 = add_sat( T2, T3 ); +#else + T4 = add( T2, T3 ); +#endif T5 = zRe[i2]; move16(); T6 = zRe[i3]; diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 88b4340a4..7ac60b967 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -88,7 +88,11 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { L_tmp = L_abs(L_SWB_signal[n_lag]); - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); +#ifdef BASOP_NOGLOB + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); +#else + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); +#endif move32(); } env_index = add(env_index, 1); @@ -105,7 +109,11 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { L_tmp = L_abs(L_SWB_signal[add(n_freq, n_lag)]); - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); +#ifdef BASOP_NOGLOB + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); +#else + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); +#endif move32(); } env_index = add(env_index, 1); @@ -122,7 +130,11 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { L_tmp = L_abs(L_SWB_signal[add(n_freq, n_lag)]); - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); +#ifdef BASOP_NOGLOB + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); +#else + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); +#endif move32(); } env_index = add(env_index, 1); @@ -2353,7 +2365,11 @@ void hq_wb_nf_bwe_fx( /* smooth the noise magnitudes between inter-frame */ test(); test(); - IF(GT_32(prev_avrg_norm_fx, L_shr(avrg_norm_fx, 1)) && LT_32(prev_avrg_norm_fx, L_shl(avrg_norm_fx, 1)) && prev_is_transient == 0) +#ifdef BASOP_NOGLOB + IF( GT_32( prev_avrg_norm_fx, L_shr( avrg_norm_fx, 1 ) ) && LT_32( prev_avrg_norm_fx, L_shl_sat( avrg_norm_fx, 1 ) ) && prev_is_transient == 0 ) +#else + IF( GT_32( prev_avrg_norm_fx, L_shr( avrg_norm_fx, 1 ) ) && LT_32( prev_avrg_norm_fx, L_shl( avrg_norm_fx, 1 ) ) && prev_is_transient == 0 ) +#endif { exp1 = norm_l(prev_env_fx[sfm]); L_tmp1 = L_shl(prev_env_fx[sfm], exp1);/* prev_env_Q[sfm] +exp1 */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 8abea5c6b..e74e2a2bd 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -1706,7 +1706,11 @@ void SWB_BWE_decoding_fx( /*20480 = 5 in Q12 */ FOR(tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048) { - *pit1 = round_fx(L_shl(L_mult(*pit1,tmp3),3)); /*Q_syn */ +#ifdef BASOP_NOGLOB + *pit1 = round_fx_sat( L_shl_sat( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */ +#else + *pit1 = round_fx( L_shl( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */ +#endif pit1--; } } diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 71ce441e9..6ec822fcd 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -2955,23 +2955,38 @@ void ScaleShapedWB_fx( { /* mod_syn in (16+Q_bwe_exc), frame_gain in Q18 */ L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* L_tmp in (Q_bwe_exc+3) */ - synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift) ); /* Qx */ +#ifdef BASOP_NOGLOB + synSHB[i] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ + synSHB[i] = add_sat( synSHB[i], overlap[i] ); + move16(); /* Qx */ + synSHB[i + l_shb_lahead] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx */ +#else + synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ synSHB[i] = add( synSHB[i], overlap[i] ); - move16(); /* Qx */ - synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift) ); /* Qx */ + move16(); /* Qx */ + synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift ) ); /* Qx */ +#endif } FOR ( ; i < l_frame; i++ ) { L_tmp = Mult_32_32( mod_syn[i], frame_gain); /* L_tmp in (Q_bwe_exc+3) */ - synSHB[i] = round_fx( L_shl(L_tmp, shift) ); /* Qx; */ +#ifdef BASOP_NOGLOB + synSHB[i] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx; */ +#else + synSHB[i] = round_fx( L_shl( L_tmp, shift ) ); /* Qx; */ +#endif } l_frame_tmp = add(l_frame, l_shb_lahead); FOR ( ; i < l_frame_tmp; i++ ) { L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* (Q_bwe_exc+3) */ - overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ +#ifdef BASOP_NOGLOB + overlap[i - l_frame] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ +#else + overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ +#endif } return; diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index 94ed7c6db..9b29e8601 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -755,7 +755,11 @@ static void find_enr_dct_fx( FOR( i = min_band; i <= NB_LIMIT_BAND; i++ ) { /* total channel energy */ - Ltmp = L_add(band[i],Ltmp); +#ifdef BASOP_NOGLOB + Ltmp = L_add_sat( band[i], Ltmp ); +#else + Ltmp = L_add( band[i], Ltmp ); +#endif } *Etot = Ltmp; diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 79e7475b3..56b7f38ed 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2356,14 +2356,24 @@ void IMDCT(Word32 *x, Word16 x_e, tmp3 = shr(tcx_mdct_window_half_length, 1); FOR (i = 0; i < tmp3; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); + xn_buf[i+tmp1] = add_sat( xn_buf[i+tmp1], mult_r_sat(hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#endif move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i+tmp1] = add_sat( xn_buf[i+tmp1], mult_r_sat(hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); +#endif move16(); } } @@ -2373,14 +2383,24 @@ void IMDCT(Word32 *x, Word16 x_e, tmp3 = shr(tcx_mdct_window_half_length, 1); FOR (i = 0; i < tmp3; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#endif move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); +#endif move16(); } } diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 112cd825b..c74a026b4 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1184,7 +1184,11 @@ ivas_error evs_dec_fx( FOR (i = 0; i < tmps; i++) { - output_sp[i+delay_comp] = msu_r(L_mult(output_sp[i+delay_comp], alpha), shr(hHQ_core->old_out_fx[i+nz], timeIn_e), add(alpha, -32768)); +#ifdef BASOP_NOGLOB + output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); +#else + output_sp[i + delay_comp] = msu_r( L_mult( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); +#endif move16(); alpha = add(alpha, step); } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 06b1d056a..7bfc1aef8 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -93,7 +93,11 @@ void hq_pred_hb_bws_fx( L_tmp = L_deposit_l(0); FOR(i=25; iprev_ener_shb_fx = extract_l(L_tmp);/*Q1*/ diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 91639f73a..1566df27f 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -1659,7 +1659,11 @@ void wb_tbe_dec_fx( exp = sub( add( exp, 22 ), 30 ); tmp = div_s( 16384, tmp ); L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ +#ifdef BASOP_NOGLOB + st_fx->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ +#else st_fx->last_wb_bwe_ener_fx = round_fx( L_shl( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ +#endif } -- GitLab From 78b45a03ecdb2a498955a5b67bce8246e33e7ad5 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 15:00:28 -0500 Subject: [PATCH 15/42] adding basop sat for signal with extreme saturation --- lib_com/fft_rel_fx.c | 60 ++++++++++++++++++++++++++++------- lib_com/wi_fx.c | 6 +++- lib_dec/FEC_HQ_phase_ecu_fx.c | 12 +++++-- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index 49ae18103..fb63faecc 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -132,46 +132,84 @@ static void c_fft_fx( input_ptr1 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); - tmp1 = msu_r(L_tmp1, *input_ptr1, 16384); +#ifdef BASOP_NOGLOB + tmp1 = msu_r_sat( L_tmp1, *input_ptr1, 16384 ); + tmp3 = mac_r_sat(L_tmp1, *input_ptr1++, 16384); +#else + tmp1 = msu_r( L_tmp1, *input_ptr1, 16384 ); tmp3 = mac_r(L_tmp1, *input_ptr1++, 16384); - +#endif input_ptr2 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); input_ptr3 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); L_tmp1 = L_mult(*input_ptr2++, 16384); - tmp2 = mac_r(L_tmp1, *input_ptr3, 16384); +#ifdef BASOP_NOGLOB + tmp2 = mac_r_sat( L_tmp1, *input_ptr3, 16384 ); + tmp4 = msu_r_sat(L_tmp1, *input_ptr3++, 16384); +#else + tmp2 = mac_r( L_tmp1, *input_ptr3, 16384 ); tmp4 = msu_r(L_tmp1, *input_ptr3++, 16384); - +#endif L_tmp1 = L_mult(tmp3, 16384); - out_ptr[k] = mac_r(L_tmp1, tmp2, 16384); +#ifdef BASOP_NOGLOB + out_ptr[k] = mac_r_sat( L_tmp1, tmp2, 16384 ); + move16(); + out_ptr[k+4] = msu_r_sat(L_tmp1, tmp2, 16384); + move16(); + + tmp2 = mac_r_sat(L_tmp2, *input_ptr1, 16384); + tmp3 = msu_r_sat(L_tmp2, *input_ptr1, 16384); +#else + out_ptr[k] = mac_r( L_tmp1, tmp2, 16384 ); move16(); out_ptr[k+4] = msu_r(L_tmp1, tmp2, 16384); move16(); tmp2 = mac_r(L_tmp2, *input_ptr1, 16384); tmp3 = msu_r(L_tmp2, *input_ptr1, 16384); - +#endif L_tmp2 = L_mult(*input_ptr2, 16384); L_tmp1 = L_mult(tmp1, 16384); - tmp1 = msu_r(L_tmp2, *input_ptr3, 16384); +#ifdef BASOP_NOGLOB + tmp1 = msu_r_sat( L_tmp2, *input_ptr3, 16384 ); + out_ptr[k + 2] = mac_r_sat( L_tmp1, tmp1, 16384 ); + move16(); + out_ptr[k + 6] = msu_r_sat( L_tmp1, tmp1, 16384 ); + move16(); +#else + tmp1 = msu_r( L_tmp2, *input_ptr3, 16384 ); out_ptr[k+2] = mac_r(L_tmp1, tmp1, 16384); move16(); out_ptr[k+6] = msu_r(L_tmp1, tmp1, 16384); move16(); - +#endif L_tmp1 = L_mult(tmp2, 16384); - tmp2 = mac_r(L_tmp2, *input_ptr3, 16384); +#ifdef BASOP_NOGLOB + tmp2 = mac_r_sat( L_tmp2, *input_ptr3, 16384 ); + out_ptr[k+1] = mac_r_sat(L_tmp1, tmp2, 16384); + move16(); + out_ptr[k+5] = msu_r_sat(L_tmp1, tmp2, 16384); + move16(); +#else + tmp2 = mac_r( L_tmp2, *input_ptr3, 16384 ); out_ptr[k+1] = mac_r(L_tmp1, tmp2, 16384); move16(); out_ptr[k+5] = msu_r(L_tmp1, tmp2, 16384); move16(); - +#endif L_tmp1 = L_mult(tmp3, 16384); - out_ptr[k+3] = msu_r(L_tmp1, tmp4, 16384); +#ifdef BASOP_NOGLOB + out_ptr[k + 3] = msu_r_sat( L_tmp1, tmp4, 16384 ); + move16(); + out_ptr[k+7] = mac_r_sat(L_tmp1, tmp4, 16384); + move16(); +#else + out_ptr[k + 3] = msu_r( L_tmp1, tmp4, 16384 ); move16(); out_ptr[k+7] = mac_r(L_tmp1, tmp4, 16384); move16(); +#endif } /* Remaining Stages */ diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 35832db82..3d8920c6a 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -1217,7 +1217,11 @@ static void DTFS_transform_fx( tmptmp3_40_fx=L_add(tmptmp3_40_fx, Mult_32_16(x_r_fx[m],sinc_fx[k][j])); } - out_fx[i] = round_fx(L_shl(tmptmp3_40_fx,2)); +#ifdef BASOP_NOGLOB + out_fx[i] = round_fx_sat( L_shl_sat( tmptmp3_40_fx, 2 ) ); +#else + out_fx[i] = round_fx( L_shl( tmptmp3_40_fx, 2 ) ); +#endif } diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 08c2955f2..9b6c29a4f 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -549,14 +549,22 @@ static void trans_ana_fx( tr_dec[k] = 0; move16(); Mpy_32_16_ss(*pGrPowLeft, THRESH_TR_LIN_BY2_FX, &acc, &lsb); /* To facilitate fixed-point implementation, divide threshold by 2. */ - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#ifdef BASOP_NOGLOB + acc = L_or( L_shl_sat( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#else + acc = L_or( L_shl( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#endif if (GT_32(*pGrPowRight, acc)) /* gr_pow_right > thres_tr_lin*gr_pow_left */ { tr_dec[k] = 1; move16(); } Mpy_32_16_ss(*pGrPowRight, THRESH_TR_LIN_BY2_FX, &acc, &lsb); - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#ifdef BASOP_NOGLOB + acc = L_or( L_shl_sat( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#else + acc = L_or( L_shl( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#endif if (GT_32(*pGrPowLeft, acc)) /* gr_pow_left > thres_tr_lin*gr_pow_right */ { tr_dec[k] = 1; -- GitLab From 9ee3e525cc05e547e7cd5d71844a26431d516cc0 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 15:17:11 -0500 Subject: [PATCH 16/42] adding basop sat for signal with extreme saturation --- lib_com/swb_bwe_com_lr_fx.c | 21 +++++++++++++++------ lib_enc/avq_cod_fx.c | 6 +++++- lib_enc/cod_ace_fx.c | 3 ++- lib_enc/enc_higher_acelp_fx.c | 14 ++++++++++++-- lib_enc/swb_bwe_enc_fx.c | 9 +++++++-- lib_enc/swb_bwe_enc_hr_fx.c | 6 +++++- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 35e0f39f8..eee46575d 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -2290,8 +2290,11 @@ void ton_ene_est_fx( exp_pow = sub(14, temp_hi_fx); L_band_energy_Linear[i] = Pow2(14, temp_lo_fx); move32(); /* Qexp_pow */ - L_band_energy_Linear[i] = L_shl(L_band_energy_Linear[i], sub(*QbeL, exp_pow)); - +#ifdef BASOP_NOGLOB + L_band_energy_Linear[i] = L_shl_sat( L_band_energy_Linear[i], sub( *QbeL, exp_pow ) ); +#else + L_band_energy_Linear[i] = L_shl( L_band_energy_Linear[i], sub( *QbeL, exp_pow ) ); +#endif /* Div Part */ E_r_fx = 0x7fff; move16(); @@ -2584,16 +2587,22 @@ void Gettonl_scalfact_fx exp_pow = sub(14, temp_hi_fx); L_band_energy_Linear[band_pos_fx] = Pow2(14, temp_lo_fx); move32(); /* Qexp_pow */ - L_band_energy_Linear[band_pos_fx] = L_shl(L_band_energy_Linear[band_pos_fx], sub(QbeL, exp_pow)); - +#ifdef BASOP_NOGLOB + L_band_energy_Linear[band_pos_fx] = L_shl_sat( L_band_energy_Linear[band_pos_fx], sub( QbeL, exp_pow ) ); +#else + L_band_energy_Linear[band_pos_fx] = L_shl( L_band_energy_Linear[band_pos_fx], sub( QbeL, exp_pow ) ); +#endif /* Div Part */ exp_normd = norm_l(L_be_tonal[band_pos_fx]); exp_normd = sub(exp_normd, 1); exp_normn = norm_l(L_band_energy_Linear[band_pos_fx]); temp_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_band_energy_Linear[band_pos_fx], exp_normn))); /* QbeL+exp_normd-(QbeL+exp_normn-16)-1 */ sqrt_32n_16_fx(L_deposit_h(temp_fx), add(sub(exp_normd, exp_normn), 31), &temp_fx, &Qtemp); - enrd_r_fx = extract_h(L_shl(L_mult(enrd_r_fx, temp_fx), sub(15, Qtemp))); - +#ifdef BASOP_NOGLOB + enrd_r_fx = extract_h( L_shl_sat( L_mult( enrd_r_fx, temp_fx ), sub( 15, Qtemp ) ) ); +#else + enrd_r_fx = extract_h( L_shl( L_mult( enrd_r_fx, temp_fx ), sub( 15, Qtemp ) ) ); +#endif enrd_r_fx = sub(enrd_r_fx, step_fx); } ELSE diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index b05b84536..9b52741bd 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -123,7 +123,11 @@ void AVQ_cod_fx( /* o: comfort noise gain factor */ /* estimated gain (when offset=0, estimated gain=1) */ f_tmp = L_Extract_lc(Ltmp, &e_tmp); tmp16 = extract_l(Pow2(14, f_tmp)); - Lgain = L_shl(tmp16, e_tmp); +#ifdef BASOP_NOGLOB + Lgain = L_shl_sat( tmp16, e_tmp ); +#else + Lgain = L_shl( tmp16, e_tmp ); +#endif /* gain_inv = 1.0f / gain */ e_tmp = norm_l(Lgain); tmp16 = extract_h(L_shl(Lgain, e_tmp)); diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index c5709fe4c..4d28c6455 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -387,10 +387,11 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ #endif Ltmp2 = Mpy_32_16_1(gain_code, code[i]); - Ltmp2 = L_shl(Ltmp2, Q_new_p5); #ifdef BASOP_NOGLOB + Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); Ltmp = L_add_sat( Ltmp, Ltmp2 ); #else + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); Ltmp = L_add( Ltmp, Ltmp2 ); #endif #ifdef BASOP_NOGLOB diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 0ccb17be7..9695b3241 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -222,8 +222,13 @@ void transf_cdbk_enc_fx( index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12>>1, (1 << G_AVQ_BITS) ); } Ltmp = Mult_32_16(gain_code,stmp); /* Q16 * Q12 - 15 -> Q13*/ - Ltmp = L_shl(Ltmp,5); /* Q13 -> Q18*/ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx_sat(Ltmp); /* Q2*/ +#else + Ltmp = L_shl( Ltmp, 5 ); /* Q13 -> Q18*/ *gain_preQ = round_fx(Ltmp); /* Q2*/ +#endif } ELSE { @@ -477,8 +482,13 @@ Word16 gain_quant_fx( /* o: quantization index */ /*tmp1 = sub(c_max,c_min); Q14*/ /*tmp2 = sub(c_gain,c_min); Q14*/ - tmp1 = msu_r(L_deposit_h(c_max/*in Q13 already*/),c_min, 16384); /*Q13*/ +#ifdef BASOP_NOGLOB + tmp1 = msu_r_sat( L_deposit_h( c_max /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ + tmp2 = msu_r_sat(L_deposit_h(c_gain/*in Q13 already*/),c_min,16384); /*Q13*/ +#else + tmp1 = msu_r( L_deposit_h( c_max /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ tmp2 = msu_r(L_deposit_h(c_gain/*in Q13 already*/),c_min,16384); /*Q13*/ +#endif IF(tmp1 != 0) { exp = norm_s(tmp1); diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 72abfe2be..c402aeb28 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -469,10 +469,15 @@ static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain index */ dist = L_deposit_l(0); FOR (j=0; jQ20 */ + dist = L_add_sat(dist, L_tmp); +#else + tmp = sub( x[j], *pit ); /*Q10 */ L_tmp = L_mult0(tmp, tmp);/*Q(10+10)->Q20 */ dist = L_add(dist, L_tmp); - +#endif pit++; } diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index ea89b22fa..291ef2b19 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -349,7 +349,11 @@ void swb_bwe_enc_hr_fx( L_temp = Calc_Energy_Autoscaled(ptr16, t_audio_fx_exp, WIDTH_TRANS_FREQ_COEF, &temp2); ptr16 += WIDTH_TRANS_FREQ_COEF; L_temp = Sqrt_Ratio32(L_temp, temp2, WIDTH_TRANS_FREQ_COEF, /*WIDTH_TRANS_FREQ_COEF is in Q0*/0, &temp2); - en_band_fx[i] = round_fx(L_shr(L_temp, sub(15-9, temp2))); +#ifdef BASOP_NOGLOB + en_band_fx[i] = round_fx_sat( L_shr_sat( L_temp, sub( 15 - 9, temp2 ) ) ); +#else + en_band_fx[i] = round_fx( L_shr( L_temp, sub( 15 - 9, temp2 ) ) ); +#endif } /* Q energy per band */ -- GitLab From 21ae1724570c5a40ee2c0b9b567206e3cba8ae27 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 15:35:50 -0500 Subject: [PATCH 17/42] adding basop sat for signal with extreme saturation --- lib_com/window_ola_fx.c | 6 +++++- lib_dec/FEC_scale_syn_fx.c | 8 +++++++- lib_dec/acelp_core_switch_dec_fx.c | 6 +++++- lib_dec/dec_ace_fx.c | 6 +++++- lib_dec/dec_higher_acelp_fx.c | 7 ++++++- lib_dec/dec_tcx_fx.c | 4 ++-- lib_dec/er_dec_acelp_fx.c | 13 ++++++++++--- 7 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 52506e037..4d4a211d2 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -935,7 +935,11 @@ void core_switching_OLA_fx( temp_len = sub(L,tmp); FOR( i=0; i< temp_len; i++ ) { - *pt = add(add(*pt,*pt2++),*pt3++); +#ifdef BASOP_NOGLOB + *pt = add_sat( add_sat( *pt, *pt2++ ), *pt3++ ); +#else + *pt = add( add( *pt, *pt2++ ), *pt3++ ); +#endif move16(); pt++; } diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 0e45ca98d..16d696f00 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -594,9 +594,15 @@ void FEC_scale_syn_fx( FOR( i=0; i Q13*/ - L_tmp = L_shl(L_tmp,5); /* Q13 -> Q18*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx_sat(L_tmp); /* Q2*/ +#else + L_tmp = L_shl( L_tmp, 5 ); /* Q13 -> Q18*/ *gain_preQ = round_fx(L_tmp); /* Q2*/ +#endif } ELSE { diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 56b7f38ed..0eaa5a846 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2136,7 +2136,7 @@ void IMDCT(Word32 *x, Word16 x_e, { tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[i-overlap+tcx_mdct_window_min_length].v.re); #ifdef BASOP_NOGLOB - xn_buf[i + tmp4] = shl_sat( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); + xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #else xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #endif @@ -2146,7 +2146,7 @@ void IMDCT(Word32 *x, Word16 x_e, { tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[overlap-1-i].v.im); #ifdef BASOP_NOGLOB - xn_buf[i + tmp4] = shl_sat( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); + xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #else xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); #endif diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index bc7c27a2f..d01b229f0 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -947,7 +947,11 @@ void con_acelp( { FOR( i=0 ; i < st->L_frame; i++ ) { - syn[i] = add(syn[i], syn_unv[i]); +#ifdef BASOP_NOGLOB + syn[i] = add_sat( syn[i], syn_unv[i] ); +#else + syn[i] = add( syn[i], syn_unv[i] ); +#endif move16(); } } @@ -1002,8 +1006,11 @@ void con_acelp( /*updating enr_old parameters*/ frame_ener_fx( st->L_frame, st->last_good_fx, syn, round_fx(tmp_tc), &(st->enr_old_fx), 1, 0, 0, 0 ); - st->enr_old_fx = L_shl(st->enr_old_fx,shl(negate(Qf_syn),1)); - +#ifdef BASOP_NOGLOB + st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); +#else + st->enr_old_fx = L_shl( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); +#endif /* update ACELP synthesis memory */ Copy(mem_syn, st->mem_syn2_fx , M); Copy(syn+st->L_frame-L_SYN_MEM, st->mem_syn_r , L_SYN_MEM); -- GitLab From 5d34cc982b9c89925111513eac7d500e08e8bd20 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 09:17:51 -0400 Subject: [PATCH 18/42] Correction on compl saturations for 26.444 --- lib_com/hq2_noise_inject_fx.c | 12 ++++++++++-- lib_com/syn_filt_fx.c | 6 +++++- lib_com/tcx_utils_fx.c | 6 +++++- lib_enc/amr_wb_enc_fx.c | 6 +++++- lib_enc/cod_ace_fx.c | 6 +++++- lib_enc/enc_amr_wb_fx.c | 8 ++++++-- lib_enc/enc_gen_voic_fx.c | 8 ++++++-- lib_enc/find_tilt_fx.c | 6 +++++- lib_enc/gaus_enc_fx.c | 7 ++++++- lib_enc/hq_lr_enc_fx.c | 12 ++++++++++-- lib_enc/updt_tar_fx.c | 7 ++++--- 11 files changed, 67 insertions(+), 17 deletions(-) diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index f83584a06..7cd26fa39 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -450,7 +450,11 @@ void hq2_noise_inject_fx( tmp = sub(Q_env_fx[k],Q_Ep_fx[k]); tmp = sub(tmp,Q_speech); tmp = add(tmp,25); - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ +#else + L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ +#endif tmp = extract_l(L_min(L_tmp,192));/* */ fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ } @@ -460,7 +464,11 @@ void hq2_noise_inject_fx( L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */ L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */ tmp = sub(Q_env_fx[k],23); - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ +#else + L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ +#endif tmp = extract_l((L_min(L_tmp,192)));/* */ fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ } diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 3e9f97f44..baa5b038c 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -136,7 +136,11 @@ void syn_filt_s_lc_fx( /* Stop at i to Avoid Mults with Zeros */ FOR (j = 1; j <= i; j++) { - L_tmp = L_msu(L_tmp, y[-j], a[j]); +#ifdef BASOP_NOGLOB + L_tmp = L_msu_sat( L_tmp, y[-j], a[j] ); +#else + L_tmp = L_msu( L_tmp, y[-j], a[j] ); +#endif } #ifdef BASOP_NOGLOB diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index bf6fdcef1..2f4c49c32 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -420,7 +420,11 @@ void tcx_windowing_synthesis_current_frame( FOR (i=0; ibckr_fx+1, 9 ); } - hp_bckr = L_shr(L_add(hNoiseEst->bckr_fx[st->max_band -1] , hNoiseEst->bckr_fx[st->max_band]),1); +#ifdef BASOP_NOGLOB + hp_bckr = L_shr( L_add_sat( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 ); +#else + hp_bckr = L_shr( L_add( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 ); +#endif if( hp_bckr == 0 ) /* Avoid division by zero. */ { hp_bckr = L_deposit_l(1); diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 4d28c6455..3c036b054 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -340,7 +340,11 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ hLPDmem->mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); move16(); BASOP_SATURATE_WARNING_OFF_EVS; - hLPDmem->mem_w0 =shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#else + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#endif BASOP_SATURATE_WARNING_ON_EVS; /*-------------------------------------------------------* diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index 1bf5d1f64..e85091ed6 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -216,9 +216,13 @@ void encod_amr_wb_fx( Ltmp = L_negate(Ltmp); Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); Ltmp = L_msu(Ltmp, y1[L_SUBFR - 1], gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - +#endif /*-----------------------------------------------------------------* * Find the total excitation *-----------------------------------------------------------------*/ diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index ed6e3efe7..204951e6f 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -323,9 +323,13 @@ void encod_gen_voic_fx( Ltmp = L_negate(Ltmp); Ltmp = L_mac(Ltmp, xn_fx[L_SUBFR - 1], 16384); Ltmp = L_msu(Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx); - Ltmp = L_shl(Ltmp, sub(1, shift)); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - +#endif IF(gain_preQ_fx != 0 ) { tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index 350a7dc8c..d89fc6765 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -83,7 +83,11 @@ void find_tilt_fx( /*lp_bckr = mean( pt_bckr, nb_bands );*/ /* estimated noise E in first critical bands, up to 1270 Hz */ lp_bckr = Mean32(pt_bckr, nb_bands); /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ - hp_bckr = L_shr(L_add(bckr[max_band-1] , bckr[max_band]),1); +#ifdef BASOP_NOGLOB + hp_bckr = L_shr( L_add_sat( bckr[max_band - 1], bckr[max_band] ), 1 ); +#else + hp_bckr = L_shr( L_add( bckr[max_band - 1], bckr[max_band] ), 1 ); +#endif if (hp_bckr == 0) /* Avoid division by zero. */ { hp_bckr = L_deposit_l(1); diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 4d42b5b4f..4c6068a2a 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -211,8 +211,13 @@ void gauss2v_fx( { /* fc0 += xn[i]*xn[i] */ /* fc1 += xn[i]*xn[i-1] */ - Lc0 = L_mac(Lc0, xn[i], xn[i]); +#ifdef BASOP_NOGLOB + Lc0 = L_mac_sat( Lc0, xn[i], xn[i] ); + Lc1 = L_mac_sat(Lc1, xn[i], xn[i-1]); +#else + Lc0 = L_mac( Lc0, xn[i], xn[i] ); Lc1 = L_mac(Lc1, xn[i], xn[i-1]); +#endif } /* fgxx = fc1/fc0 */ exp_num = sub(norm_l(Lc1), 1); diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 6f8a577de..cdbc11151 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -721,11 +721,19 @@ void hq_lr_enc_fx( IF(GE_16(i,highband)) { - enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ +#ifdef BASOP_NOGLOB + enerH_fx = L_add_sat( enerH_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ +#else + enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ +#endif } ELSE IF(GE_16(i,lowband)) { - enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ +#ifdef BASOP_NOGLOB + enerL_fx = L_add_sat( enerL_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ +#else + enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ +#endif } } diff --git a/lib_enc/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index 3183b6521..b6d7779e8 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -33,11 +33,12 @@ void updt_tar_fx( { /*x2[i] = x[i] - gain*y[i];*/ L_tmp = L_mult(x[i], 16384); - L_tmp = L_msu(L_tmp, y[i], gain); #ifdef BASOP_NOGLOB - x2[i] = extract_h(L_shl_o(L_tmp, 1, &Overflow)); + L_tmp = L_msu_sat( L_tmp, y[i], gain ); + x2[i] = extract_h( L_shl_o( L_tmp, 1, &Overflow ) ); #else /* BASOP_NOGLOB */ - x2[i] = extract_h(L_shl(L_tmp, 1)); + L_tmp = L_msu( L_tmp, y[i], gain ); + x2[i] = extract_h( L_shl( L_tmp, 1 ) ); #endif } return; -- GitLab From fa3657b795781b946c01994fb7c776b41a010c9b Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 09:43:09 -0400 Subject: [PATCH 19/42] Correction on compl saturations for 26.444 --- lib_com/cng_exc_fx.c | 6 +++++- lib_com/codec_tcx_common.c | 6 +++++- lib_com/oper_32b.c | 7 +++++-- lib_com/stat_noise_uv_mod_fx.c | 14 ++++++++++---- lib_com/swb_tbe_com_fx.c | 18 +++++++++++++++--- lib_enc/analy_sp_fx.c | 7 +++++-- lib_enc/core_enc_init_fx.c | 6 +++++- lib_enc/enc_amr_wb_fx.c | 3 ++- lib_enc/find_tilt_fx.c | 7 ++++++- lib_enc/gain_enc_fx.c | 6 +++++- lib_enc/speech_music_classif_fx.c | 6 +++++- 11 files changed, 68 insertions(+), 18 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index c5b8caaef..dcb5399b7 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -326,7 +326,11 @@ void CNG_exc_fx( #endif L_tmp = L_shr(L_tmp,1);/* 2*Q_exc+6 */ tmp = add(Q_exc,Q_exc); - env[i] = L_shr(L_tmp,tmp); +#ifdef BASOP_NOGLOB + env[i] = L_shr_sat( L_tmp, tmp ); +#else + env[i] = L_shr( L_tmp, tmp ); +#endif move32();/* Q6 */ ptR++; ptI--; diff --git a/lib_com/codec_tcx_common.c b/lib_com/codec_tcx_common.c index 0cbed6d8a..5a83b4561 100644 --- a/lib_com/codec_tcx_common.c +++ b/lib_com/codec_tcx_common.c @@ -186,7 +186,11 @@ void tcxFormantEnhancement( { fac = add(fac0, mult(d, extract_l(L_mult0(j, inv_int[n])))); BASOP_SATURATE_WARNING_OFF_EVS; - xn_buf[l + j] = s_min(xn_one, shl(mult(xn_buf[l + j], fac), fac_e)); +#ifdef BASOP_NOGLOB + xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) ); +#else + xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); +#endif move16(); BASOP_SATURATE_WARNING_ON_EVS; } diff --git a/lib_com/oper_32b.c b/lib_com/oper_32b.c index de85bc267..821a4f82d 100644 --- a/lib_com/oper_32b.c +++ b/lib_com/oper_32b.c @@ -400,8 +400,11 @@ Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo) lo = L_Extract_lc (L_32, &hi); n_lo = L_Extract_lc (L_num, &n_hi); L_32 = Mpy_32 (n_hi, n_lo, hi, lo); - L_32 = L_shl (L_32, 2); - +#ifdef BASOP_NOGLOB + L_32 = L_shl_sat( L_32, 2 ); +#else + L_32 = L_shl( L_32, 2 ); +#endif return (L_32); } diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 32be86394..f6df457ba 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -376,11 +376,17 @@ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ { /* r0 = L_mac(r0,x[i],x[i]) */ /* r1 = L_mac(r1,x[i],x[i+1]) -> correlation loop can be optimized */ - r0 = L_mac(r0,xi,xi); - +#ifdef BASOP_NOGLOB + r0 = L_mac_sat( r0, xi, xi ); +#else + r0 = L_mac( r0, xi, xi ); +#endif xi_p1 = shr(x[i+1], Q_shift); - r1 = L_mac(r1, xi, xi_p1); - +#ifdef BASOP_NOGLOB + r1 = L_mac_sat( r1, xi, xi_p1 ); +#else + r1 = L_mac( r1, xi, xi_p1 ); +#endif xi = xi_p1; move16(); } diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 6ec822fcd..5b0ee65e8 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3016,7 +3016,11 @@ static Word32 non_linearity_scaled_copy( { FOR ( i = 0; i < j; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ output[i] = L_tmp; move32(); @@ -3026,7 +3030,11 @@ static Word32 non_linearity_scaled_copy( } FOR ( ; i < length; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ output[i] = L_tmp; move32(); @@ -3036,7 +3044,11 @@ static Word32 non_linearity_scaled_copy( { FOR ( i = 0; i < j; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ if ( input[i] < 0 ) diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 0e115ffa5..ae577bf62 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -427,8 +427,11 @@ static void find_enr( * Find the total energy over the input bandwidth *-----------------------------------------------------------------*/ - etot = L_add(*LEtot, L_shl(etot, sub(exp_etot, 4))); - +#ifdef BASOP_NOGLOB + etot = L_add_sat( *LEtot, L_shl_sat( etot, sub( exp_etot, 4 ) ) ); +#else + etot = L_add( *LEtot, L_shl( etot, sub( exp_etot, 4 ) ) ); +#endif *LEtot = etot; move32(); diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 4252372b6..3adad6489 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -722,7 +722,11 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 Copy( hLPDmem->mem_syn2, tmp_buf+1, M ); deemph_fx( tmp_buf+1, st->preemph_fac, M, &tmp ); Residu3_fx( Ap, tmp_buf+M, &tmp, 1, 1 ); - hLPDmem->mem_w0 = sub(shr(st->wspeech_enc[-1],shift), tmp); +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = sub_sat( shr_sat( st->wspeech_enc[-1], shift ), tmp ); +#else + hLPDmem->mem_w0 = sub( shr( st->wspeech_enc[-1], shift ), tmp ); +#endif } } ELSE IF((NE_16(st->L_frame,L_frame_old))) diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index e85091ed6..b35777e7f 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -229,10 +229,11 @@ void encod_amr_wb_fx( FOR (i = 0; i < L_SUBFR; i++) { L_tmp = L_mult(gcode16, code[i]); - L_tmp = L_shl(L_tmp, 5); #ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); L_tmp = L_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); #else + L_tmp = L_shl( L_tmp, 5 ); L_tmp = L_mac( L_tmp, exc[i + i_subfr], gain_pit ); #endif #ifdef BASOP_NOGLOB diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index d89fc6765..8190bf7a8 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -101,8 +101,13 @@ void find_tilt_fx( { /*lp_bckr *= FACT;*/ /*hp_bckr *= FACT;*/ - lp_bckr = L_add(L_shl(lp_bckr,1),lp_bckr); +#ifdef BASOP_NOGLOB + lp_bckr = L_add_sat( L_shl_sat( lp_bckr, 1 ), lp_bckr ); + hp_bckr = L_add_sat(L_shl_sat(hp_bckr,1),hp_bckr); +#else + lp_bckr = L_add( L_shl( lp_bckr, 1 ), lp_bckr ); hp_bckr = L_add(L_shl(hp_bckr,1),hp_bckr); +#endif } /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ Ltmp = L_mult(voicing[1], 16384); diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index 3af0e6b26..c2789aa06 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -823,7 +823,11 @@ void gain_enc_SQ_fx( index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_Q14, LG10_G_CODE_MAX_Q13, nBits_code, &expg ); push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits_code ); L_tmp = L_mult(gain_code16,gcode0); /*Q0*Q0 -> Q1*/ - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#else + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#endif move32(); /*Q16*/ /* *norm_gain_code = *gain_code / *gain_inov; */ diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 794d13bef..f7bd718e2 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -2767,7 +2767,11 @@ static void flux_fx( { IF ( p2v_map[i] != 0 ) { - L_flux = L_add(L_flux,abs_s(sub(Bin_E[i],old_Bin_E[i]))); /*Q7 */ +#ifdef BASOP_NOGLOB + L_flux = L_add_sat( L_flux, abs_s( sub_sat( Bin_E[i], old_Bin_E[i] ) ) ); /*Q7 */ +#else + L_flux = L_add( L_flux, abs_s( sub( Bin_E[i], old_Bin_E[i] ) ) ); /*Q7 */ +#endif } if ( p2v_map[i] != 0 ) { -- GitLab From a17e842a35e0e7e0e41c4bcef821179dd2383e13 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 11:05:50 -0400 Subject: [PATCH 20/42] Correction on compl saturations for 26.444 --- lib_com/cng_exc_fx.c | 7 ++++- lib_com/enhancer_fx.c | 7 ++++- lib_com/gs_inact_switching_fx.c | 14 ++++++++-- lib_com/modif_fs_fx.c | 7 ++++- lib_com/tcx_utils_fx.c | 14 +++++++--- lib_com/tools_fx.c | 13 +++++++--- lib_com/wi_fx.c | 6 ++++- lib_dec/FEC_HQ_core_fx.c | 13 +++++++--- lib_dec/dec_ace_fx.c | 7 +++-- lib_dec/dec_pit_exc_fx.c | 13 ++++++++-- lib_dec/dec_post_fx.c | 25 ++++++++++++++---- lib_enc/SNR_calc_fx.c | 6 ++++- lib_enc/dtx_fx.c | 6 ++++- lib_enc/enc_nelp_fx.c | 6 ++++- lib_enc/enc_pit_exc_fx.c | 9 +++++-- lib_enc/enc_tran_fx.c | 8 ++++-- lib_enc/fd_cng_enc_fx.c | 12 +++++++-- lib_enc/gaus_enc_fx.c | 6 ++++- lib_enc/hq_lr_enc_fx.c | 6 ++++- lib_enc/nelp_enc_fx.c | 45 +++++++++++++++++++++++++++------ 20 files changed, 186 insertions(+), 44 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index dcb5399b7..6aeb33ee2 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -339,8 +339,13 @@ void CNG_exc_fx( FOR ( i=0; i Q25 */ L_tmp = L_msu(L_tmp, code[1], tmp); /* Q12 * Q15 -> Q28 */ - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); + pt_exc2[0] = msu_r_sat(L_tmp, -32768, pt_exc2[0]); +#else + L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); pt_exc2[0] = msu_r(L_tmp, -32768, pt_exc2[0]); +#endif move16();/* in Q_exc */ FOR (i = 1; i < L_SUBFR-1; i++) diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 2602902d7..8e4794cda 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -129,8 +129,13 @@ void Inac_swtch_ematch_fx( FOR (j = 0; j < 8; j ++) { L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ + *pt_exc = round_fx_sat(L_tmp); +#else + L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ *pt_exc = round_fx(L_tmp); +#endif pt_exc++; } } @@ -139,8 +144,13 @@ void Inac_swtch_ematch_fx( FOR (j = 0; j < 16; j ++) { L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ + *pt_exc = round_fx_sat(L_tmp); /*Q_exc*/ +#else + L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ *pt_exc = round_fx(L_tmp); /*Q_exc*/ +#endif pt_exc++; } } diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 245f0f3e2..a06e5de4b 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -755,7 +755,12 @@ void Decimate_allpass_steep_fx( mem[ 2*ALLPASSSECTIONS_STEEP-1 ] = extract_h( Lacc1 ); /* Qx */ sum = mult_r( out_fx[0], 16384 ); /* Qx */ - out_fx[0] = add( sum, mult_r(temp[ALLPASSSECTIONS_STEEP-1], 16384 )); /* Qx */ move16(); +#ifdef BASOP_NOGLOB + out_fx[0] = add_sat( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ +#else + out_fx[0] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ +#endif + move16(); FOR ( k = 1; k < N/2; k++) diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 2f4c49c32..8a5d9c611 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -408,11 +408,17 @@ void tcx_windowing_synthesis_current_frame( tmp2 = mult_r(signal[i+overlap-acelp_mem_len], window_trans[tmp-1-i].v.re); /*Time TDAC: 1)forward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-tmp+i], mult_r(window_trans[tmp-1-i].v.im, window_trans[tmp-1-i].v.im))); - +#ifdef BASOP_NOGLOB + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); +#else + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); +#endif /*Time TDAC: 1)reward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[tmp-1-i].v.re, window_trans[tmp-1-i].v.im))); - +#ifdef BASOP_NOGLOB + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); +#else + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); +#endif move16(); signal[i+overlap-acelp_mem_len] = tmp2; } diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 9aa17c37d..03c569aa2 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -2453,8 +2453,11 @@ void pz_filter_dp_fx ( FOR ( j = PDR - 1; j >= 0; j-- ) Lacc = Msub_32_16( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ - s_mem = L_shl( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ - +#ifdef BASOP_NOGLOB + s_mem = L_shl_sat( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ +#else + s_mem = L_shl( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ +#endif Lacc = L_deposit_l(0); FOR ( j = PNR - 1; j >= 0; j-- ) Lacc = Madd_32_16( Lacc, buf[j], b[j + 1] ); @@ -2470,7 +2473,11 @@ void pz_filter_dp_fx ( buf[0] = s_mem; move16(); - Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ +#ifdef BASOP_NOGLOB + Ltemp1 = L_shr_sat( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ +#else + Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ +#endif y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ } } diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 3d8920c6a..9d9750f0d 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -1769,7 +1769,11 @@ static Word32 DTFS_setEngy_fx( expb = norm_l(en1_fx); - fracb = round_fx(L_shl(en1_fx,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( en1_fx, expb ) ); +#else + fracb = round_fx( L_shl( en1_fx, expb ) ); +#endif expb = sub(30, add(expb, shl(X_DTFS_FX->Q, 1))); diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index d79a53fba..2b64e7f41 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -359,8 +359,11 @@ void HQ_FEC_processing_fx( exp2 = norm_l(norm_values_fx[0]); tmp_fx = div_s(extract_h(L_shl(norm_p_fx[i], exp1)), extract_h(L_shl(norm_values_fx[0], exp2)));/*15 + (5 + exp1 - 16) - (12 + exp2 - 16)*/ - tmp_fx = shl(tmp_fx, add(6, sub(exp2, exp1)));/*14*/ - +#ifdef BASOP_NOGLOB + tmp_fx = shl_sat( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ +#else + tmp_fx = shl( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ +#endif if (GT_16(tmp_fx, 16384)) { tmp_fx = 16384; @@ -830,7 +833,11 @@ void HQ_FEC_Mem_update_fx( move16();/*15*/ L_tmp = Mult_32_16(tmp_energy_fx, tmp_fx);/*8 + 15 - 15*/ - hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h(L_shl(L_tmp, 16-8)); +#ifdef BASOP_NOGLOB + hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl_sat( L_tmp, 16 - 8 ) ); +#else + hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl( L_tmp, 16 - 8 ) ); +#endif /* Moving Average */ hHQ_nbfec->energy_MA_Curr_fx[0] = s_max(1,add(mult_r(26214, hHQ_nbfec->energy_MA_Curr_fx[0]), mult_r(6554, hHQ_nbfec->energy_MA_Curr_fx[1]))); diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 1d87971e4..af7b8fd09 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -463,8 +463,11 @@ void decoder_acelp( Ltmp = Mpy_32_16_1(gain_code2, code2[i]); Ltmp = L_shl(Ltmp, add(5,st->Q_exc)); Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); - exc2[i + i_subfr] = round_fx(L_shl(Ltmp, 1)); - +#ifdef BASOP_NOGLOB + exc2[i + i_subfr] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); +#else + exc2[i + i_subfr] = round_fx( L_shl( Ltmp, 1 ) ); +#endif Ltmp2 = Mpy_32_16_1(gain_code, code[i]); Ltmp2 = L_shl(Ltmp2, add(5,st->Q_exc)); Ltmp = L_add(Ltmp, Ltmp2); diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 7976bf649..8504e9453 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -262,8 +262,13 @@ void dec_pit_exc_fx( { FOR (i = 0; i < L_subfr_fx; i++) { - L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i+i_subfr_fx]), 1); /*Q16+Q_exc*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ +#else + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ +#endif } } ELSE @@ -273,7 +278,11 @@ void dec_pit_exc_fx( FOR (i = 0; i < L_subfr_fx; i++) { L_tmp = L_mult(gain_pitx2, exc_fx[i+i_subfr_fx]); /*Q16+Q_exc*/ - exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ +#ifdef BASOP_NOGLOB + exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ +#else + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ +#endif } } } diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 80385bcfb..c5e5728b6 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -856,7 +856,11 @@ static void pst_ltp( FOR (i = 0; i < L_SUBFR; i++) { /* nb_sh_sig may be >0, <0 or =0 */ - ptr_y_up[i] = shl(ptr_y_up[i], nb_sh_sig); +#ifdef BASOP_NOGLOB + ptr_y_up[i] = shl_sat( ptr_y_up[i], nb_sh_sig ); +#else + ptr_y_up[i] = shl( ptr_y_up[i], nb_sh_sig ); +#endif move16(); } } @@ -1467,7 +1471,11 @@ static void compute_ltp_l( L_acc = L_mult(y_up[0], y_up[0]); FOR (n = 1; n < L_SUBFR; n++) { - L_acc = L_mac(L_acc, y_up[n], y_up[n]); +#ifdef BASOP_NOGLOB + L_acc = L_mac_sat( L_acc, y_up[n], y_up[n] ); +#else + L_acc = L_mac( L_acc, y_up[n], y_up[n] ); +#endif } temp = sub(16, norm_l(L_acc)); temp = s_max(temp, 0); @@ -1720,11 +1728,18 @@ void Filt_mu( L_temp = L_mac(L_acc, 16384, *ptrs); /* sig_in(n) * 2**15 */ L_temp = Madd_32_16(L_fact, L_temp, ga); - L_temp = L_shr(L_temp, sh_fact); /* mult. temp x ga */ - +#ifdef BASOP_NOGLOB + L_temp = L_shr_sat( L_temp, sh_fact ); /* mult. temp x ga */ +#else + L_temp = L_shr( L_temp, sh_fact ); /* mult. temp x ga */ +#endif BASOP_SATURATE_WARNING_OFF_EVS; /*sig_out[n] = saturate(L_temp); move16();*/ - sig_out[n] = round_fx(L_temp); +#ifdef BASOP_NOGLOB + sig_out[n] = round_fx_sat( L_temp ); +#else + sig_out[n] = round_fx( L_temp ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c index eea94dea1..c3fc50516 100644 --- a/lib_enc/SNR_calc_fx.c +++ b/lib_enc/SNR_calc_fx.c @@ -320,7 +320,11 @@ void snr_calc( } *tsnr = VAD_Log2(tmp, minscale2); move32(); - *tsnr = L_add(*tsnr, MUL_F(*tsnr, 6226)); /* *tsnr *= 1.2; */ +#ifdef BASOP_NOGLOB + *tsnr = L_add_sat( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */ +#else + *tsnr = L_add( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */ +#endif move32(); } ELSE diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 1fb6f1feb..c635ce6f3 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -780,7 +780,11 @@ void dtx_hangover_control_fx( } exp = norm_l(enr_est); - fra = round_fx(L_shl(enr_est,exp)); +#ifdef BASOP_NOGLOB + fra = round_fx_sat( L_shl_sat( enr_est, exp ) ); +#else + fra = round_fx( L_shl( enr_est, exp ) ); +#endif exp2 = norm_s(weights); fra2 = shl(weights,exp2); exp = sub(sub(exp,16),exp2); diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index 01b5113f9..eb2c005a1 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -145,7 +145,11 @@ void encod_nelp_fx( * Updates: last value of new target is stored in mem_w0 *-----------------------------------------------------------------*/ - hLPDmem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = sub_sat( shr_sat( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); +#else + hLPDmem->mem_w0 = sub( shr( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); +#endif move16();/*Q_new-1 */ hLPDmem->tilt_code = 0; move16();/* purely unvoiced */ diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 466fa3b2a..8284f25a0 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -343,8 +343,13 @@ void enc_pit_exc_fx( } gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); +#ifdef BASOP_NOGLOB + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); +#else + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); +#endif IF( use_fcb != 0) { hLPDmem->tilt_code = Est_tilt2(&exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 5fd64a761..6f3c21ff7 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -246,9 +246,13 @@ Word16 encod_tran_fx( L_tmp = L_negate(L_tmp); L_tmp = L_mac(L_tmp, xn[L_SUBFR - 1], 16384); L_tmp = L_msu(L_tmp, y1[L_SUBFR - 1], gain_pit); - L_tmp = L_shl(L_tmp, sub(1, shift)); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat(L_tmp); /*Q_new-1*/ +#else + L_tmp = L_shl( L_tmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx(L_tmp); /*Q_new-1*/ - +#endif /*-----------------------------------------------------------------* * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 25e610e3d..ab9895e01 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -1498,7 +1498,11 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, s = sub(15-NOISE_HEADROOM,noiseExp); FOR (i=0; i Date: Mon, 11 Mar 2024 11:30:19 -0400 Subject: [PATCH 21/42] Correction on compl saturations for 26.444 --- lib_com/cng_exc_fx.c | 8 ++++- lib_com/enhancer_fx.c | 6 +++- lib_com/env_stab.c | 58 ++++++++++++++++-------------- lib_com/fft_rel_fx.c | 60 +++++++++++++++++++++++++------ lib_dec/FEC_fx.c | 18 ++++++++-- lib_dec/FEC_scale_syn_fx.c | 12 +++++-- lib_dec/LD_music_post_filter_fx.c | 7 ++-- lib_dec/bass_psfilter_fx.c | 16 +++++++-- lib_dec/d_gain2p_fx.c | 6 +++- lib_dec/er_dec_tcx_fx.c | 9 +++-- lib_dec/post_dec_fx.c | 15 ++++++-- 11 files changed, 160 insertions(+), 55 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 6aeb33ee2..ce781e363 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -546,9 +546,15 @@ void CNG_exc_fx( { L_tmp = L_mult0(*pt_fft_io, *pt_fft_io); pt_fft_io++; - L_tmp = L_mac0(L_tmp, *pt_fft_io, *pt_fft_io); /* 2*(Q_exc) */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ + pt_fft_io++; + L_tmp2 = L_add_sat(L_tmp2, L_shr(L_tmp, 7)); /* 2*(Q_exc)+1, divide by L_frame done here */ +#else + L_tmp = L_mac0( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ pt_fft_io++; L_tmp2 = L_add(L_tmp2, L_shr(L_tmp, 7)); /* 2*(Q_exc)+1, divide by L_frame done here */ +#endif } } ELSE /* L_FRAME16k */ diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 70fb6caca..43889fbf4 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -277,7 +277,11 @@ void enhancer_fx( FOR (i = 0; i < L_SUBFR; i++) { /* excp[i] += pt_exc2[i] */ - excp[i] = add(excp[i], pt_exc2[i]); +#ifdef BASOP_NOGLOB + excp[i] = add_sat( excp[i], pt_exc2[i] ); +#else + excp[i] = add( excp[i], pt_exc2[i] ); +#endif move16(); } agc2_fx(pt_exc2, excp, L_SUBFR); diff --git a/lib_com/env_stab.c b/lib_com/env_stab.c index c71340c67..751b9f992 100644 --- a/lib_com/env_stab.c +++ b/lib_com/env_stab.c @@ -219,39 +219,43 @@ Word16 env_stability_fx( /* in Q15 */ ELSE { /* Calculate envelope stability parameter */ -L_env_delta = L_deposit_l(0); -FOR(i = 0; i < nb_sfm; i++) -{ - tmp = sub(mem_norm[i], ynrm[i]); - L_env_delta = L_mac0(L_env_delta, tmp, tmp); - mem_norm[i] = ynrm[i]; - move16(); -} + L_env_delta = L_deposit_l(0); + FOR(i = 0; i < nb_sfm; i++) + { + tmp = sub(mem_norm[i], ynrm[i]); + L_env_delta = L_mac0(L_env_delta, tmp, tmp); + mem_norm[i] = ynrm[i]; + move16(); + } -inv_nb_sfm = 19418; /* Q19 */ move16(); -if (nb_sfm == 26) -{ - inv_nb_sfm = 20165; /* Q19 */ move16(); -} -exp = norm_l(L_env_delta); -L_env_delta = Mult_32_16(L_shl(L_env_delta, exp), inv_nb_sfm); /* 0+exp+19-15 */ + inv_nb_sfm = 19418; /* Q19 */ move16(); + if (nb_sfm == 26) + { + inv_nb_sfm = 20165; /* Q19 */ move16(); + } + exp = norm_l(L_env_delta); + L_env_delta = Mult_32_16(L_shl(L_env_delta, exp), inv_nb_sfm); /* 0+exp+19-15 */ -L_tmp = Sqrt_l(L_env_delta, &exp2); /* exp+4+31+exp2 */ + L_tmp = Sqrt_l(L_env_delta, &exp2); /* exp+4+31+exp2 */ -exp = add(35, add(exp, exp2)); -if (EQ_16(s_and(exp, 1), 1)) -{ - L_tmp = Mult_32_16(L_tmp, 23170); /* 1/sqrt(2) in Q15 */ -} -exp = shr(exp, 1); + exp = add(35, add(exp, exp2)); + if (EQ_16(s_and(exp, 1), 1)) + { + L_tmp = Mult_32_16(L_tmp, 23170); /* 1/sqrt(2) in Q15 */ + } + exp = shr(exp, 1); -env_delta = round_fx(L_shl(L_tmp, sub(26, exp))); /* Q10 */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + env_delta = round_fx_sat( L_shl_sat( L_tmp, sub( 26, exp ) ) ); /* Q10 */ +#else + env_delta = round_fx( L_shl( L_tmp, sub( 26, exp ) ) ); /* Q10 */ +#endif -L_tmp = L_mult0(26214, env_delta); /* 26214 is 0.1 in Q18. Q28 */ -L_tmp = L_mac(L_tmp, 29491, *mem_env_delta); /* 29491 is 0.9 in Q15. Q28 */ + L_tmp = L_mult0(26214, env_delta); /* 26214 is 0.1 in Q18. Q28 */ + L_tmp = L_mac(L_tmp, 29491, *mem_env_delta); /* 29491 is 0.9 in Q15. Q28 */ -*mem_env_delta = round_fx(L_tmp); /* Q12 */ -Overflow = 0; + *mem_env_delta = round_fx(L_tmp); /* Q12 */ + Overflow = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Overflow */ env_delta = round_fx_o(L_shl_o(L_tmp, 1, &Overflow), &Overflow); /* Q13 */ diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index fb63faecc..4a85f485d 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -416,8 +416,28 @@ void r_fft_fx_lc( FOR (i = 2; i <= SIZE2; i += 2) { Ltmp1_imag = L_mult(temp[i+1], 16384); - Ltmp1_imag = L_msu(Ltmp1_imag, *ptrDn, 16384); - tmp2_real = add(temp[i+1], *ptrDn--); +#ifdef BASOP_NOGLOB + Ltmp1_imag = L_msu_sat( Ltmp1_imag, *ptrDn, 16384 ); + tmp2_real = add_sat( temp[i + 1], *ptrDn-- ); + + Ltmp1_real = L_mult(temp[i], 16384); + Ltmp1_real = L_mac_sat( Ltmp1_real, *ptrDn, 16384 ); + tmp2_imag = sub(*ptrDn--, temp[i]); + + + *ptRealUp++ = msu_r_sat( L_mac_sat( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); + move16(); + *ptImaDn-- = mac_r_sat( L_mac_sat( Ltmp1_imag, tmp2_imag, phs_tbl[i] ), tmp2_real, phs_tbl[i + 1] ); + move16(); + Ltmp1 = L_mac_sat( L_negate( Ltmp1_imag ), tmp2_real, *phstbl_ptrDn ); + Ltmp1_real = L_mac_sat( Ltmp1_real, tmp2_imag, *phstbl_ptrDn-- ); + *ptImaUp++ = msu_r_sat( Ltmp1, tmp2_imag, *phstbl_ptrDn ); + move16(); + *ptRealDn-- = mac_r_sat( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); + move16(); +#else + Ltmp1_imag = L_msu( Ltmp1_imag, *ptrDn, 16384 ); + tmp2_real = add( temp[i + 1], *ptrDn-- ); Ltmp1_real = L_mult(temp[i], 16384); Ltmp1_real = L_mac(Ltmp1_real, *ptrDn, 16384); @@ -434,6 +454,7 @@ void r_fft_fx_lc( move16(); *ptRealDn-- = mac_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); move16(); +#endif } } ELSE /* The ifFT part */ @@ -461,15 +482,31 @@ void r_fft_fx_lc( /* Now, handle the remaining positive frequencies */ FOR (i = 2; i <= SIZE2; i += 2) { - Ltmp1_imag = L_mult(*ptImaDn, 16384); - Ltmp1_imag = L_msu(Ltmp1_imag, *ptImaUp, 16384); - tmp2_real = add(*ptImaDn--, *ptImaUp++); - Ltmp1_real = L_mult(*ptRealUp, 16384); - Ltmp1_real = L_mac(Ltmp1_real, *ptRealDn, 16384); - tmp2_imag = sub(*ptRealUp++, *ptRealDn--); - - - temp[i] = mac_r(L_msu(Ltmp1_real, tmp2_real, phs_tbl[i]), tmp2_imag, phs_tbl[i+1]); +#ifdef BASOP_NOGLOB + Ltmp1_imag = L_mult( *ptImaDn, 16384 ); + Ltmp1_imag = L_msu_sat( Ltmp1_imag, *ptImaUp, 16384 ); + tmp2_real = add_sat( *ptImaDn--, *ptImaUp++ ); + Ltmp1_real = L_mult( *ptRealUp, 16384 ); + Ltmp1_real = L_mac_sat( Ltmp1_real, *ptRealDn, 16384 ); + tmp2_imag = sub_sat( *ptRealUp++, *ptRealDn-- ); + temp[i] = mac_r_sat( L_msu_sat( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); + move16(); + temp[i + 1] = mac_r_sat( L_mac_sat( Ltmp1_imag, tmp2_imag, phs_tbl[i] ), tmp2_real, phs_tbl[i + 1] ); + move16(); + Ltmp1 = L_mac_sat( L_negate( Ltmp1_imag ), tmp2_real, *phstbl_ptrDn ); + Ltmp1_real = L_msu_sat( Ltmp1_real, tmp2_imag, *phstbl_ptrDn-- ); + *ptrDn-- = msu_r_sat( Ltmp1, tmp2_imag, *phstbl_ptrDn ); + move16(); + *ptrDn-- = msu_r_sat( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); + move16(); +#else + Ltmp1_imag = L_mult( *ptImaDn, 16384 ); + Ltmp1_imag = L_msu( Ltmp1_imag, *ptImaUp, 16384 ); + tmp2_real = add( *ptImaDn--, *ptImaUp++ ); + Ltmp1_real = L_mult( *ptRealUp, 16384 ); + Ltmp1_real = L_mac( Ltmp1_real, *ptRealDn, 16384 ); + tmp2_imag = sub( *ptRealUp++, *ptRealDn-- ); + temp[i] = mac_r( L_msu( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); move16(); temp[i+1] = mac_r(L_mac(Ltmp1_imag, tmp2_imag, phs_tbl[i]), tmp2_real, phs_tbl[i+1]); move16(); @@ -479,6 +516,7 @@ void r_fft_fx_lc( move16(); *ptrDn-- = msu_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); move16(); +#endif } /* Perform the complex ifFT */ diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 49b41ab41..8adf752fc 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -650,7 +650,11 @@ void FEC_exc_estim_fx( /* non-causal ringing of the FIR filter */ /**pt_exc++ *= (gain_inov * gain);*/ L_tmp = L_mult(tmp, *pt_exc); /* Q_exc+18 * Q-3 -> Q_exc+16 */ - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); +#ifdef BASOP_NOGLOB + *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); +#else + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); +#endif } FOR( i=0; i< L_frame; i++ ) @@ -658,7 +662,11 @@ void FEC_exc_estim_fx( /* the inner part of the FIR filter */ /* *pt_exc++ *= (gain_inov * gain); */ L_tmp = L_mult(tmp, *pt_exc); - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); +#ifdef BASOP_NOGLOB + *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); +#else + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); +#endif /* gain -= step; */ L_tmp2 = L_sub(L_tmp2, L_step); tmp = round_fx(L_tmp2); @@ -669,7 +677,11 @@ void FEC_exc_estim_fx( { /* *pt_exc++ *= (gain_inov * gain) */ L_tmp = L_mult(tmp, *pt_exc); - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); +#ifdef BASOP_NOGLOB + *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); +#else + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); +#endif } } diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 16d696f00..5f68c1932 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -351,7 +351,11 @@ void FEC_scale_syn_fx( exc[i] = mac_r(L_mult(exc[i], gain1), exc[i], gain1); move16(); /*exc2[i] *= gain1;*/ - exc2[i] = mac_r(L_mult(exc2[i], gain1), exc2[i], gain1); +#ifdef BASOP_NOGLOB + exc2[i] = mac_r_sat( L_mult( exc2[i], gain1 ), exc2[i], gain1 ); +#else + exc2[i] = mac_r( L_mult( exc2[i], gain1 ), exc2[i], gain1 ); +#endif move16(); } /* smoothing is done in excitation domain, so redo synthesis */ @@ -398,7 +402,11 @@ void FEC_scale_syn_fx( ( (EQ_16(clas,UNVOICED_CLAS))||(EQ_16(clas,INACTIVE_CLAS))))) /* unvoiced classification */ { /*if( enr_q > scaling * enr_old )enr_q = scaling * enr_old;*/ - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ +#ifdef BASOP_NOGLOB + L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#else + L_enr_q = L_min( L_enr_q, L_shl( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#endif } ELSE IF( GE_16(last_good,VOICED_TRANSITION)&<_16(last_good,INACTIVE_CLAS)&&GE_16(clas,VOICED_TRANSITION)&<_16(clas,INACTIVE_CLAS)) { diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index 9b29e8601..f4c04da3e 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -335,8 +335,11 @@ void LD_music_post_filter_fx tmp16 = s_min(max_ovf_2k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_2k, tmp16); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); - +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } FOR(; i < BIN_4KHZ; i++) diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 3f9497bc4..f636e5b2a 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -323,11 +323,19 @@ void bass_psfilter_fx( { Lcorr0 = L_mult0( syn_fx[j], syn2_fx[j]); Lener0 = L_mult0(syn2_fx[j], syn2_fx[j]); - Lcorr0 = L_mac0(Lcorr0, syn_fx[j+1], syn2_fx[j+1]); +#ifdef BASOP_NOGLOB + Lcorr0 = L_mac0_sat( Lcorr0, syn_fx[j + 1], syn2_fx[j + 1] ); + Lener0 = L_mac0_sat(Lener0, syn2_fx[j+1], syn2_fx[j+1]); + + Lcorr = L_add_sat(Lcorr, L_shr(Lcorr0, 4)); + Lener = L_add_sat(Lener, L_shr(Lener0, 4)); +#else + Lcorr0 = L_mac0( Lcorr0, syn_fx[j + 1], syn2_fx[j + 1] ); Lener0 = L_mac0(Lener0, syn2_fx[j+1], syn2_fx[j+1]); Lcorr = L_add(Lcorr, L_shr(Lcorr0, 4)); Lener = L_add(Lener, L_shr(Lener0, 4)); +#endif /* this loop is not efficient but it provide a respectable precision while avoiding overflow. */ } @@ -366,7 +374,11 @@ void bass_psfilter_fx( FOR (i=0; i< subfr_len; i++) { /* err[i] = syn_fx[i] - gain*syn2_fx[i] */ - err[i] = msu_r(L_shr(L_mult0(gain, syn2_fx[i]), exp2), syn_fx[i], 16384); +#ifdef BASOP_NOGLOB + err[i] = msu_r_sat( L_shr_sat( L_mult0( gain, syn2_fx[i] ), exp2 ), syn_fx[i], 16384 ); +#else + err[i] = msu_r( L_shr( L_mult0( gain, syn2_fx[i] ), exp2 ), syn_fx[i], 16384 ); +#endif move16(); /* the sign is inverted but it is not important because we calculate energy with 'err[i]' x 'err[i]' diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index 2c380170d..e35f52d39 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -198,7 +198,11 @@ static void gain_dec_uv( *-----------------------------------------------------------------*/ *past_gpit = *gain_pit; *past_gcode = L_tmp; - L_tmp = L_shl(Mpy_32_16_1(L_tmp, *gain_inov), 3); /* Q16*Q12 -> Q13 -> Q16 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( Mpy_32_16_1( L_tmp, *gain_inov ), 3 ); /* Q16*Q12 -> Q13 -> Q16 */ +#else + L_tmp = L_shl( Mpy_32_16_1( L_tmp, *gain_inov ), 3 ); /* Q16*Q12 -> Q13 -> Q16 */ +#endif *gain_code = L_tmp; move32(); diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 9ea6d2082..0e54b692d 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -775,8 +775,11 @@ void con_tcx( { gain32 = Mpy_32_16_1(gain32, 22938/*0.7f Q15*/); } - L_tmp = L_shl(gain32,1); - +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_shl_sat( gain32, 1 ); +#else + L_tmp = L_shl( gain32, 1 ); +#endif IF (GT_32(L_shl(L_deposit_h(gainCNG),sub(gainCNG_e,31-16)/*Q16*/) , L_tmp)) { gainCNG_e = sub(15+1,norm_l(L_tmp)); @@ -870,7 +873,7 @@ void con_tcx( FOR( i=0 ; i< tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat(exc[i], shl(noise[i + (L_FIR_FER2 / 2)], Q_exc + noise_e));/*Q1*/ move16(); + exc[i] = add_sat(exc[i], shl_sat(noise[i + (L_FIR_FER2 / 2)], Q_exc + noise_e));/*Q1*/ move16(); #else exc[i] = add(exc[i] , shl(noise[i+(L_FIR_FER2/2)],Q_exc+noise_e));/*Q1*/ move16(); #endif diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index 48e4e71b6..dec6dd1e4 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -419,9 +419,15 @@ static void bass_pf_1sf_delay( FOR (i = 0; i < lg; i++) { tmp32 = L_msu0(0, tmp16, syn[i+i_subfr-T]); - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr+T]); +#ifdef BASOP_NOGLOB + tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr + T] ); + tmp32 = L_mac_sat(tmp32, tmp16, syn[i+i_subfr]); + bpf_noise_buf[i+i_subfr] = round_fx_sat(tmp32); /* Q0 */ +#else + tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr + T] ); tmp32 = L_mac(tmp32, tmp16, syn[i+i_subfr]); bpf_noise_buf[i+i_subfr] = round_fx(tmp32); /* Q0 */ +#endif } } @@ -430,8 +436,13 @@ static void bass_pf_1sf_delay( FOR (i = lg; i < l_subfr; i++) { tmp32 = L_mult0(tmp16, syn[i+i_subfr]); - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr-T]); +#ifdef BASOP_NOGLOB + tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr - T] ); + bpf_noise_buf[i+i_subfr] = round_fx_sat(tmp32); /* Q0 */ +#else + tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); bpf_noise_buf[i+i_subfr] = round_fx(tmp32); /* Q0 */ +#endif } } } -- GitLab From baef6ba429e3121c259c4bf7c8083b66df380312 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 11:42:43 -0400 Subject: [PATCH 22/42] Correction on compl saturations for 26.444 --- lib_com/swb_bwe_com_lr_fx.c | 6 +++++- lib_com/swb_tbe_com_fx.c | 6 +++++- lib_enc/nelp_enc_fx.c | 12 ++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index eee46575d..9eb548b4b 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -2383,7 +2383,11 @@ void ton_ene_est_fx( L_E = sum2_fx(&xSynth_har_fx[sub(band_start[i], fLenLow)], band_width[i]); QE = add(shl(QxSynth_sft, 1), 1); - L_E = L_shl(L_E, sub(*QbeL, QE)); +#ifdef BASOP_NOGLOB + L_E = L_shl_sat( L_E, sub( *QbeL, QE ) ); +#else + L_E = L_shl( L_E, sub( *QbeL, QE ) ); +#endif QE = *QbeL; } ELSE diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 5b0ee65e8..2c64d08ae 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -4103,7 +4103,11 @@ void Estimate_mix_factors_fx( /* (Q_bwe_exc) */ /* temp_numer2[i] = sub(exc16kWhtnd[i], WN_exc_local[i]); */ - temp_numer2[i] = sub(exc16kWhtnd[i], round_fx(L_shl(L_tmp1, sc1 ))); +#ifdef BASOP_NOGLOB + temp_numer2[i] = sub_sat( exc16kWhtnd[i], round_fx_sat( L_shl_sat( L_tmp1, sc1 ) ) ); +#else + temp_numer2[i] = sub( exc16kWhtnd[i], round_fx( L_shl( L_tmp1, sc1 ) ) ); +#endif move16(); /* (Q_bwe_exc) */ } diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index bb340646e..46107913f 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -699,7 +699,11 @@ void nelp_encoder_fx( Ltemp1 = Mult_32_16(l_nelp_gain_mem, fdbck_fx);/*exp1+qGain-15 */ L_tmp = L_add(L_tmp, Ltemp1); L_tmp = L_shr_r(L_tmp, (exp1 - 15)); - Gains_fx[i] = round_fx(L_shl(L_tmp, 16)); +#ifdef BASOP_NOGLOB + Gains_fx[i] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); +#else + Gains_fx[i] = round_fx( L_shl( L_tmp, 16 ) ); +#endif move16(); l_nelp_gain_mem = L_tmp; } @@ -879,7 +883,11 @@ void nelp_encoder_fx( EH2_fx = L_deposit_l(0); FOR(i = 0; i < L_FRAME; i++) { - EH2_fx = L_mac0(EH2_fx, filtRes_fx[i], filtRes_fx[i]); /*Q(2*qEH2) */ +#ifdef BASOP_NOGLOB + EH2_fx = L_mac0_sat( EH2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH2) */ +#else + EH2_fx = L_mac0( EH2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH2) */ +#endif } qEH2 = 2 * qEH2; move16(); -- GitLab From 8127afeb469ceb2dbf5d90d75651e0da1d2edc4a Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 12:48:46 -0400 Subject: [PATCH 23/42] Correction on compl saturations for 26.444 --- lib_com/cng_exc_fx.c | 6 +++++- lib_dec/FEC_fx.c | 12 ++++++++++-- lib_dec/FEC_scale_syn_fx.c | 6 +++++- lib_dec/bass_psfilter_fx.c | 2 +- lib_dec/cng_dec_fx.c | 24 ++++++++++++++++++++---- lib_dec/dec_gen_voic_fx.c | 37 +++++++++++++++++++++++++++++++------ lib_dec/dec_tcx_fx.c | 2 +- lib_dec/er_dec_acelp_fx.c | 9 +++++++-- lib_dec/evs_dec_fx.c | 6 +++++- lib_dec/gain_dec_fx.c | 6 +++++- lib_dec/nelp_dec_fx.c | 6 +++++- lib_dec/rst_dec_fx.c | 6 +++++- 12 files changed, 100 insertions(+), 22 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index ce781e363..6b8e03ae4 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -198,7 +198,11 @@ void CNG_exc_fx( *------------------------------------------------------------*/ L_tmp = Mult_32_16(*lp_ener, Random(cng_ener_seed)); L_tmp = Mult_32_16(L_tmp, GAIN_VAR); - L_tmp = L_add(L_tmp, *lp_ener); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, *lp_ener ); +#else + L_tmp = L_add( L_tmp, *lp_ener ); +#endif L_tmp = L_max(L_tmp, 1); /* enr = dot_product( exc2, exc2, L_SUBFR ) + 0.01f */ diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 8adf752fc..7b0c42b13 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -718,9 +718,17 @@ void FEC_exc_estim_fx( L_tmp = L_mult(hp_filt[0], pt_exc[0]); FOR (j = 1; j < MODE1_L_FIR_FER; j++) { - L_tmp = L_mac(L_tmp, hp_filt[j], pt_exc[j]); +#ifdef BASOP_NOGLOB + L_tmp = L_mac_sat( L_tmp, hp_filt[j], pt_exc[j] ); +#else + L_tmp = L_mac( L_tmp, hp_filt[j], pt_exc[j] ); +#endif } - exc2[i] = msu_r(L_tmp, -32768, exc[i]); +#ifdef BASOP_NOGLOB + exc2[i] = msu_r_sat( L_tmp, -32768, exc[i] ); +#else + exc2[i] = msu_r( L_tmp, -32768, exc[i] ); +#endif move16(); pt_exc++; } diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 5f68c1932..4ab17558a 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -257,7 +257,11 @@ void FEC_scale_syn_fx( ( (prev_bfi) || ( (EQ_16(coder_type,GENERIC) ) && (EQ_16(LSF_Q_prediction,AUTO_REGRESSIVE) ) ) ) ) { /*if( enr_q > scaling * enr_old ){enr_q = scaling * enr_old;}*/ - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ +#ifdef BASOP_NOGLOB + L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#else + L_enr_q = L_min( L_enr_q, L_shl( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#endif } ELSE { diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index f636e5b2a..fa4d1238f 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -415,7 +415,7 @@ void bass_psfilter_fx( exp2 = sub(exp, exp2); /* exponent num - exponent denom */ /* alpha = corr / ener */ #ifdef BASOP_NOGLOB - alpha = shr_sat(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ + alpha = shr_sat(div_s(round_fx_sat(L_shl_sat(Ltmp, exp)), tmp2), exp2); /*Q15 */ #else alpha = shr(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ #endif diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index e8844a1da..86900069b 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -544,19 +544,31 @@ void CNG_dec_fx( FOR ( j=0; jlp_ener_fx; */ IF(EQ_16(m1,1)) { - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#endif } ELSE { tmp1 = div_s(1,m1); L_tmp = Mult_32_16(L_tmp,tmp1); - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#endif } env[i] = L_tmp; move32(); @@ -576,7 +588,11 @@ void CNG_dec_fx( { /* Update hangover memory during CNG */ test(); - IF ( *allow_cn_step == 0 && LT_32(hTdCngDec->Enew_fx,L_add(st_fx->lp_ener_fx,L_shr(st_fx->lp_ener_fx,1)))) +#ifdef BASOP_NOGLOB + IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#else + IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#endif { /* update the pointer to circular buffer of old LSP vectors */ hTdCngDec->ho_hist_ptr_fx = add(hTdCngDec->ho_hist_ptr_fx, 1); diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index d32daf514..d91538be7 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -251,16 +251,28 @@ ivas_error decod_gen_voic_fx( Ltmp1 = L_shl(Ltmp1,tmp1_fx); /* Q16 + Q_exc */ /* Compute exc2 */ - L_tmp = L_shl(L_mult(gain_pit_fx,exc_fx[i+i_subfr_fx]),1); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); + exc2_fx[i+i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); +#else + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); - +#endif /* code in Q9, gain_pit in Q14 */ L_tmp = L_mult(gain_code16, code_fx[i]); - L_tmp = L_shl(L_tmp, 5); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); + L_tmp = L_mac_sat(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); + L_tmp = L_shl_sat(L_tmp, 1); /* saturation can occur here */ + + exc_fx[i+i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); +#else + L_tmp = L_shl( L_tmp, 5 ); L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ exc_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); +#endif } } ELSE @@ -345,8 +357,13 @@ ivas_error decod_gen_voic_fx( curr_spch_nrg = L_deposit_l(1); FOR( i=0; iQ_exc */ +#ifdef BASOP_NOGLOB + curr_res_nrg = L_mac0_sat( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ + curr_spch_nrg = L_mac0_sat(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ +#else + curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ curr_spch_nrg = L_mac0(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ +#endif p_exc++; p_syn++; } @@ -359,7 +376,11 @@ ivas_error decod_gen_voic_fx( expa = sub(30,expa+(2*st_fx->prev_Q_exc_fr)); expb = norm_l(curr_res_nrg); - fracb = round_fx(L_shl(curr_res_nrg,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); +#else + fracb = round_fx( L_shl( curr_res_nrg, expb ) ); +#endif expb = sub(30,expb+(2*st_fx->Q_exc)); scale = shr(sub(fraca,fracb),15); @@ -384,7 +405,11 @@ ivas_error decod_gen_voic_fx( expa = sub(30,expa+(2*st_fx->prev_Q_syn_fr)); expb = norm_l(curr_spch_nrg); - fracb = round_fx(L_shl(curr_spch_nrg,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); +#else + fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); +#endif expb = sub(30,expb+(2*st_fx->Q_syn)); scale = shr(sub(fraca,fracb),15); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0eaa5a846..18b0d291f 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2123,7 +2123,7 @@ void IMDCT(Word32 *x, Word16 x_e, FOR (i=0; i < tmp1; i++) { #ifdef BASOP_NOGLOB - xn_buf[i + tmp4] = shl_sat( add( xn_buf[i + tmp4], shr( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); + xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], shr_sat( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); #else xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], shr( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); #endif diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index d01b229f0..5c2f22d4f 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -649,8 +649,13 @@ void con_acelp( /* gain_16 = gain_32 = gain_inov * gain */ gain_32 = Mpy_32_16_1(gain_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ - gain_32 = L_shl(gain_32, add(15, s_gain_inov)); /* Q31 */ - gain_16 = round_fx(gain_32); /* Q15 */ +#ifdef BASOP_NOGLOB + gain_32 = L_shl_sat( gain_32, add( 15, s_gain_inov ) ); /* Q31 */ + gain_16 = round_fx_sat( gain_32 ); /* Q15 */ +#else + gain_32 = L_shl( gain_32, add( 15, s_gain_inov ) ); /* Q31 */ + gain_16 = round_fx( gain_32 ); /* Q15 */ +#endif /* step_32 = gain_inov * step */ step_32 = Mpy_32_16_1(step_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index c74a026b4..624b6cbd8 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1018,7 +1018,11 @@ ivas_error evs_dec_fx( { FOR (i=0; i < st_fx->L_frame/2; i++) { - output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame/4] ); +#ifdef BASOP_NOGLOB + output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); +#else + output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); +#endif move16(); } } diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 08bde0c11..56de92d18 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -1128,7 +1128,11 @@ void gain_dec_SQ_fx( /**gain_code *= gcode0;*/ L_tmp = L_mult(tmp16,gcode0); /* Q0*Q0 -> Q1*/ /**gain_code = L_shl(L_tmp,add(expg,15)); Q16*/ - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#else + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#endif move32(); /*Q16*/ /**norm_gain_code = *gain_code / *gain_inov;*/ diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 02722e269..8dfa1dd7b 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -318,7 +318,11 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 E3 = L_deposit_l(1); FOR (i=0 ; ilp_gainc_fx = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ +#ifdef BASOP_NOGLOB + st_fx->lp_gainc_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ +#else + st_fx->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ +#endif } /* reset the pitch buffer in case of FRAME_NO_DATA or SID frames */ IF( EQ_16(st_fx->L_frame,L_FRAME)) -- GitLab From c757fa3607915cbc2acff3969a967c124de13e0d Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 13:11:38 -0400 Subject: [PATCH 24/42] Correction on compl saturations for 26.444 --- lib_com/modif_fs_fx.c | 48 +++++++++++++++++++++++++++------ lib_dec/dec_tcx_fx.c | 42 ++++++++++++++++++++++++----- lib_dec/er_dec_tcx_fx.c | 12 +++++++-- lib_dec/gain_dec_fx.c | 6 ++++- lib_dec/waveadjust_fec_dec_fx.c | 13 ++++++--- 5 files changed, 100 insertions(+), 21 deletions(-) diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index a06e5de4b..2693a74cb 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -1245,11 +1245,23 @@ void interpolate_3_over_1_allpass_fx( Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] ); mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] );*/ - Vu[0] = add(mem_fx[0], mult_r(filt_coeff_fx[0], sub(input_fx[i], mem_fx[1]))); +#ifdef BASOP_NOGLOB + Vu[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[0], sub_sat( input_fx[i], mem_fx[1] ) ) ); +#else + Vu[0] = add( mem_fx[0], mult_r( filt_coeff_fx[0], sub( input_fx[i], mem_fx[1] ) ) ); +#endif move16();/* all Vu's in : Q_current*/ - Vu[1] = add(mem_fx[1], mult_r(filt_coeff_fx[1], sub(Vu[0], mem_fx[2]))); +#ifdef BASOP_NOGLOB + Vu[1] = add_sat( mem_fx[1], mult_r( filt_coeff_fx[1], sub_sat( Vu[0], mem_fx[2] ) ) ); +#else + Vu[1] = add( mem_fx[1], mult_r( filt_coeff_fx[1], sub( Vu[0], mem_fx[2] ) ) ); +#endif move16(); - mem_fx[3] = add(mem_fx[2], mult_r(filt_coeff_fx[2], sub(Vu[1], mem_fx[3]))); +#ifdef BASOP_NOGLOB + mem_fx[3] = add_sat( mem_fx[2], mult_r( filt_coeff_fx[2], sub_sat( Vu[1], mem_fx[3] ) ) ); +#else + mem_fx[3] = add( mem_fx[2], mult_r( filt_coeff_fx[2], sub( Vu[1], mem_fx[3] ) ) ); +#endif move16(); @@ -1264,9 +1276,17 @@ void interpolate_3_over_1_allpass_fx( /* Vm[0] = mem[0] + filt_coeff[3] * (input[i]-mem[4]); Vm[1] = mem[4] + filt_coeff[4] * (Vm[0]-mem[5]); mem[6] = mem[5] + filt_coeff[5] * (Vm[1]-mem[6]); */ - Vm[0] = add(mem_fx[0], mult_r(filt_coeff_fx[3], sub(input_fx[i], mem_fx[4]))); +#ifdef BASOP_NOGLOB + Vm[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[3], sub_sat( input_fx[i], mem_fx[4] ) ) ); +#else + Vm[0] = add( mem_fx[0], mult_r( filt_coeff_fx[3], sub( input_fx[i], mem_fx[4] ) ) ); +#endif move16(); - Vm[1] = add(mem_fx[4], mult_r(filt_coeff_fx[4], sub(Vm[0], mem_fx[5]))); +#ifdef BASOP_NOGLOB + Vm[1] = add_sat( mem_fx[4], mult_r( filt_coeff_fx[4], sub_sat( Vm[0], mem_fx[5] ) ) ); +#else + Vm[1] = add( mem_fx[4], mult_r( filt_coeff_fx[4], sub( Vm[0], mem_fx[5] ) ) ); +#endif move16(); #ifdef BASOP_NOGLOB mem_fx[6] = add_sat( mem_fx[5], mult_r( filt_coeff_fx[5], sub_sat( Vm[1], mem_fx[6] ) ) ); @@ -1286,9 +1306,17 @@ void interpolate_3_over_1_allpass_fx( /* Vl[0] = mem[0] + filt_coeff[6] * (input[i]-mem[7]); Vl[1] = mem[7] + filt_coeff[7] * (Vl[0]-mem[8]); mem[9] = mem[8] + filt_coeff[8] * (Vl[1]-mem[9]); */ - Vl[0] = add(mem_fx[0], mult_r(filt_coeff_fx[6], sub(input_fx[i], mem_fx[7]))); +#ifdef BASOP_NOGLOB + Vl[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[6], sub_sat( input_fx[i], mem_fx[7] ) ) ); +#else + Vl[0] = add( mem_fx[0], mult_r( filt_coeff_fx[6], sub( input_fx[i], mem_fx[7] ) ) ); +#endif move16(); - Vl[1] = add(mem_fx[7], mult_r(filt_coeff_fx[7], sub(Vl[0], mem_fx[8]))); +#ifdef BASOP_NOGLOB + Vl[1] = add_sat( mem_fx[7], mult_r( filt_coeff_fx[7], sub_sat( Vl[0], mem_fx[8] ) ) ); +#else + Vl[1] = add( mem_fx[7], mult_r( filt_coeff_fx[7], sub( Vl[0], mem_fx[8] ) ) ); +#endif move16(); #ifdef BASOP_NOGLOB mem_fx[9] = add_sat( mem_fx[8], mult_r( filt_coeff_fx[8], sub_sat( Vl[1], mem_fx[9] ) ) ); @@ -1311,7 +1339,11 @@ void interpolate_3_over_1_allpass_fx( { mem_temp = out_fx[i]; move16(); - out_fx[i] = sub(mult_r(18768/*0.57276865021499168f Q15*/, add(mem_fx[12], mem_fx[11])), mult_r(2425/*0.074004974641176793f Q15*/,add(mem_temp,mem_fx[10]))); +#ifdef BASOP_NOGLOB + out_fx[i] = sub_sat( mult_r( 18768 /*0.57276865021499168f Q15*/, add_sat( mem_fx[12], mem_fx[11] ) ), mult_r( 2425 /*0.074004974641176793f Q15*/, add_sat( mem_temp, mem_fx[10] ) ) ); +#else + out_fx[i] = sub( mult_r( 18768 /*0.57276865021499168f Q15*/, add( mem_fx[12], mem_fx[11] ) ), mult_r( 2425 /*0.074004974641176793f Q15*/, add( mem_temp, mem_fx[10] ) ) ); +#endif mem_fx[10] = mem_fx[11]; move16(); mem_fx[11] = mem_fx[12]; diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 18b0d291f..6b7267fb1 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1491,7 +1491,11 @@ void decoder_tcx_post(Decoder_State *st_fx, #endif FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) { - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gainFB, synthFB[i]),1)); +#ifdef BASOP_NOGLOB + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) ); +#else + synthFB[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) ); +#endif move16(); #ifdef BASOP_NOGLOB conceal_eof_gainFB = L_sub_o(conceal_eof_gainFB, stepFB, &Overflow); @@ -1503,7 +1507,11 @@ void decoder_tcx_post(Decoder_State *st_fx, conceal_eof_gain32 = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ FOR( i=0; i < st_fx->L_frame; i++ ) { - xn_buf[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gain32 /*Q30*/, xn_buf[i]),1)); +#ifdef BASOP_NOGLOB + xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) ); +#else + xn_buf[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) ); +#endif move16(); #ifdef BASOP_NOGLOB conceal_eof_gain32 = L_sub_o(conceal_eof_gain32, step, &Overflow); @@ -2198,13 +2206,21 @@ void IMDCT(Word32 *x, Word16 x_e, FOR (i = 0; i < tmp3; i++) { tmp2 = add(xn_buf[i+tmp1], mult_r(old_syn_overl[i], tcx_mdct_window_half[i].v.re)); - xn_buf[i+tmp1] = shl(tmp2, TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = shl_sat( tmp2, TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp1] = shl( tmp2, TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { tmp2 = add(xn_buf[i+tmp1], mult_r(old_syn_overl[i], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im)); - xn_buf[i+tmp1] = shl(tmp2, TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = shl_sat( tmp2, TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp1] = shl( tmp2, TCX_IMDCT_HEADROOM ); +#endif move16(); } IF (LT_16(add(i, tmp1), L_frame)) @@ -2251,14 +2267,22 @@ void IMDCT(Word32 *x, Word16 x_e, tmp1 = shr(overlap, 1); FOR (i=0; i < tmp1; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } tmpP16 = xn_buf + tmp1; FOR (i=0; i < overlap; i++) { - tmpP16[i] = shl(add(tmpP16[i], old_syn_overl[i]), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + tmpP16[i] = shl_sat( add( tmpP16[i], old_syn_overl[i] ), TCX_IMDCT_HEADROOM ); +#else + tmpP16[i] = shl( add( tmpP16[i], old_syn_overl[i] ), TCX_IMDCT_HEADROOM ); +#endif move16(); } @@ -2266,7 +2290,11 @@ void IMDCT(Word32 *x, Word16 x_e, { FOR (i = add(i, tmp1); i < L_frame; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 0e54b692d..1b0c4f0bf 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1046,13 +1046,21 @@ void con_tcx( FOR (i=0; isyn_Overl_TDACFB[i] = add(buf[i] , buf[W1-1-i]); +#ifdef BASOP_NOGLOB + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[W1 - 1 - i] ); +#else + hTcxDec->syn_Overl_TDACFB[i] = add( buf[i], buf[W1 - 1 - i] ); +#endif move16(); } FOR (i=0; isyn_Overl_TDACFB[W2+i] = add(buf[W2+i] , buf[W1-1-W2-i]); +#ifdef BASOP_NOGLOB + hTcxDec->syn_Overl_TDACFB[W2 + i] = add_sat( buf[W2 + i], buf[W1 - 1 - W2 - i] ); +#else + hTcxDec->syn_Overl_TDACFB[W2 + i] = add( buf[W2 + i], buf[W1 - 1 - W2 - i] ); +#endif move16(); } diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 56de92d18..e610e08b3 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -174,7 +174,11 @@ void gain_dec_tc_fx( IF( GT_16(nBits,3)) { wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); - wgain_code = shl(wgain_code,add(expg,13)); /* wgain_code in Q13*/ +#ifdef BASOP_NOGLOB + wgain_code = shl_sat( wgain_code, add( expg, 13 ) ); /* wgain_code in Q13*/ +#else + wgain_code = shl( wgain_code, add( expg, 13 ) ); /* wgain_code in Q13*/ +#endif } ELSE /* nBits == 3 */ { diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index 323cd536a..5c655b2f1 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -1538,15 +1538,22 @@ void waveform_adj2_fix( Word16 *overlapbuf, ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); dat= shl(sbuf[i],s16MaxCoefNorm); temp_OUT= mult(*recovery_gain, sub(32767,ratio)); - outx_new[i]= round_fx(L_add(L_shr(L_mult(temp_OUT,dat ),s16MaxCoefNorm-1), L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2))); +#ifdef BASOP_NOGLOB + outx_new[i] = round_fx_sat( L_add_sat( L_shr( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); +#else + outx_new[i] = round_fx( L_add( L_shr( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); +#endif move16(); *recovery_gain =sub(*recovery_gain,shr_r(step_concealgain,1)); /* q14 */ } FOR (i = gain_zero_start; i < Framesize; i++) { ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); - outx_new[i] = round_fx(L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2)); - +#ifdef BASOP_NOGLOB + outx_new[i] = round_fx_sat( L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); +#else + outx_new[i] = round_fx( L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); +#endif } if (*recovery_gain < 0) -- GitLab From e30c53108a4731030e6df360e0818415787741f9 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 13:29:30 -0400 Subject: [PATCH 25/42] Correction on compl saturations for 26.444 --- lib_com/cldfb_evs.c | 12 ++++++++++-- lib_com/hq_tools_fx.c | 7 ++++++- lib_dec/dec_tcx_fx.c | 3 ++- lib_dec/er_dec_tcx_fx.c | 34 ++++++++++++++++++++++++++++++++-- lib_dec/fd_cng_dec_fx.c | 12 ++++++++++-- lib_dec/gain_dec_fx.c | 6 +++++- 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 63b3030fa..de635e018 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -505,7 +505,11 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, /* move and scale filter states */ FOR (i=0; iFilterStates_eg); FOR (i=0; i Q1*/ - *gain_code_fx = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#endif move32(); /*Q16*/ } ELSE -- GitLab From 0587f9d3722a8f10aabefc08ed12a616bcef543d Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 13:55:11 -0400 Subject: [PATCH 26/42] Correction on compl saturations for 26.444 --- lib_com/enhancer_fx.c | 6 ++++-- lib_com/swb_bwe_com_fx.c | 6 +++++- lib_com/tools_fx.c | 14 ++++++++++++-- lib_com/window_ola_fx.c | 6 +++++- lib_dec/FEC_HQ_phase_ecu_fx.c | 6 +++++- lib_dec/evs_dec_fx.c | 12 ++++++++++-- lib_dec/igf_dec_fx.c | 6 +++++- lib_dec/swb_bwe_dec_hr_fx.c | 12 ++++++++++-- lib_dec/swb_tbe_dec_fx.c | 6 +++++- lib_dec/waveadjust_fec_dec_fx.c | 4 ++-- 10 files changed, 63 insertions(+), 15 deletions(-) diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 43889fbf4..c044ee579 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -248,11 +248,13 @@ void enhancer_fx( /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */ L_tmp = L_msu(-32768, code[i], -32768); L_tmp = L_msu(L_tmp, code[i + 1], tmp); - tmp16 = msu_r(L_tmp, code[i - 1], tmp); - L_tmp = L_shl(L_mult(gain_code_hi, tmp16), sc); #ifdef BASOP_NOGLOB + tmp16 = msu_r_sat( L_tmp, code[i - 1], tmp ); + L_tmp = L_shl_sat( L_mult( gain_code_hi, tmp16 ), sc ); pt_exc2[i] = msu_r_sat( L_tmp, -32768, pt_exc2[i] ); #else + tmp16 = msu_r( L_tmp, code[i - 1], tmp ); + L_tmp = L_shl( L_mult( gain_code_hi, tmp16 ), sc ); pt_exc2[i] = msu_r( L_tmp, -32768, pt_exc2[i] ); #endif move16(); /* in Q_exc */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index e74e2a2bd..c604481cc 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -713,7 +713,11 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* *tilt_flt = (float)(r1/sqrt(r0)); */ exp2 = norm_l(L_ener); - L_temp = Mult_32_16(L_temp, round_fx(L_shl(L_ener, exp2))); +#ifdef BASOP_NOGLOB + L_temp = Mult_32_16( L_temp, round_fx_sat( L_shl_sat( L_ener, exp2 ) ) ); +#else + L_temp = Mult_32_16( L_temp, round_fx( L_shl( L_ener, exp2 ) ) ); +#endif exp2 = sub(exp2, tmp1); exp2 = add(exp2, exp_sp); diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 03c569aa2..ea4d38660 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -2500,16 +2500,26 @@ void Copy_Scale_sig32_16( { FOR (i = 0; i < len; i++ ) { - *dst++ = round_fx(*src++); +#ifdef BASOP_NOGLOB + *dst++ = round_fx_sat( *src++ ); +#else + *dst++ = round_fx( *src++ ); +#endif } return; } FOR (i = 0; i < len; i++ ) { - L_temp = L_shl(*src++, exp0); +#ifdef BASOP_NOGLOB + L_temp = L_shl_sat( *src++, exp0 ); + + *dst++ = round_fx_sat(L_temp); +#else + L_temp = L_shl( *src++, exp0 ); *dst++ = round_fx(L_temp); +#endif } } diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 4d4a211d2..3b4c9e467 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -29,7 +29,11 @@ void sinq_fx( tmp2 = round_fx(L_tmp); /*Q15 */ x[1] = sub(tmp1, tmp2); move16(); /* sin(x) approximated by (x-x^3/3!); Q15 */ - tmp1 = add(shl(tmp,1), phi); /*Q15 */ +#ifdef BASOP_NOGLOB + tmp1 = add_sat( shl_sat( tmp, 1 ), phi ); /*Q15 */ +#else + tmp1 = add( shl( tmp, 1 ), phi ); /*Q15 */ +#endif L_tmp = L_mult(tmp1, tmp1); /*Q31 */ L_tmp = Mult_32_16(L_tmp, tmp1); /*Q31 */ L_tmp = Mult_32_16(L_tmp, 5461); /*Q31; division by 6 */ diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 9b6c29a4f..d45b4af08 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -4516,7 +4516,11 @@ void fec_noise_filling_fx( tmp_fx = div_s(1, Rnd_N_noise); /*Q15 */ - tmp_fx = round_fx(L_shl(L_mult(tmp_fx, 25736),2)); /*Q15 */ +#ifdef BASOP_NOGLOB + tmp_fx = round_fx_sat( L_shl_sat( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ +#else + tmp_fx = round_fx( L_shl( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ +#endif #ifdef IVAS_FEC_ECU_TO_COMPLETE if (element_mode == EVS_MONO) { diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 624b6cbd8..48e330251 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -156,11 +156,19 @@ ivas_error evs_dec_fx( /* st_fx->old_out_fx, st_fx->L_frameTCX); */ FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - hHQ_core->old_out_fx[i] = shl(mult_r(hHQ_core->old_out_fx[i] , st_fx->plcInfo.recovery_gain), 1); +#ifdef BASOP_NOGLOB + hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#else + hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#endif } FOR( i = 0; i < st_fx->L_frame; i++ ) { - hHQ_core->old_out_LB_fx[i] = shl(mult_r(hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain), 1); +#ifdef BASOP_NOGLOB + hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#else + hHQ_core->old_out_LB_fx[i] = shl( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#endif } /* attenuate PLC buffers, if no aldo window is used and if no sid or zero frame is received */ diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index cb50388bd..6d342c33b 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -1643,7 +1643,11 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* calc square root of L_tmp and store result in dN */ L_tmp = Sqrt32(L_tmp, &L_tmp_e); - dN[sfb] = round_fx(L_tmp); +#ifdef BASOP_NOGLOB + dN[sfb] = round_fx_sat( L_tmp ); +#else + dN[sfb] = round_fx( L_tmp ); +#endif dN_e[sfb] = L_tmp_e; move16(); dN[sfb+1] = dN[sfb]; diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index eeb3c833b..f7848545d 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -914,7 +914,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ move16(); FOR( i = 0; i < Nsv*WIDTH_BAND; i++ ) { - t_audio_tmp[i] = shl(x_norm[i], t_audio_exp); +#ifdef BASOP_NOGLOB + t_audio_tmp[i] = shl_sat( x_norm[i], t_audio_exp ); +#else + t_audio_tmp[i] = shl( x_norm[i], t_audio_exp ); +#endif move16(); } @@ -1262,7 +1266,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ FOR( i=0; iprev_ener_shb_fx, inv_ener), sub(9, exp_ener)); /*Q: 1+26-exp-9+exp = 18 */ +#ifdef BASOP_NOGLOB + prev_ener_ratio_fx = L_shr_sat( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ +#else + prev_ener_ratio_fx = L_shr( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ +#endif } IF(EQ_16(st_fx->nbLostCmpt, 1)) diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index 5c655b2f1..72c8f7a7e 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -1539,7 +1539,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, dat= shl(sbuf[i],s16MaxCoefNorm); temp_OUT= mult(*recovery_gain, sub(32767,ratio)); #ifdef BASOP_NOGLOB - outx_new[i] = round_fx_sat( L_add_sat( L_shr( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); + outx_new[i] = round_fx_sat( L_add_sat( L_shr_sat( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); #else outx_new[i] = round_fx( L_add( L_shr( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); #endif @@ -1550,7 +1550,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, { ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); #ifdef BASOP_NOGLOB - outx_new[i] = round_fx_sat( L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); + outx_new[i] = round_fx_sat( L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); #else outx_new[i] = round_fx( L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); #endif -- GitLab From 924879c761ceb0c90cd95b14b4dab8ba8456d913 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 11 Mar 2024 15:35:50 -0400 Subject: [PATCH 27/42] Correction on compl saturations for 26.444 --- lib_com/cng_exc_fx.c | 7 ++++++- lib_com/fft_fx_evs.c | 6 +++++- lib_com/stat_noise_uv_mod_fx.c | 7 +++++-- lib_com/swb_bwe_com_fx.c | 25 ++++++++++++++++++++----- lib_com/swb_tbe_com_fx.c | 19 ++++++++++++++++--- lib_com/tcx_utils_fx.c | 10 ++++++++-- lib_dec/FEC_HQ_phase_ecu_fx.c | 13 +++++++++++-- lib_dec/cng_dec_fx.c | 6 +++++- lib_dec/er_dec_acelp_fx.c | 7 +++++-- lib_dec/swb_tbe_dec_fx.c | 18 +++++++++++++++--- lib_dec/waveadjust_fec_dec_fx.c | 6 +++++- 11 files changed, 101 insertions(+), 23 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 6b8e03ae4..49dc473d1 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -383,8 +383,13 @@ void CNG_exc_fx( /* itmp[i] += own_random( cng_ener_seed1 )*denv[i]*0.000011f + denv[i]; */ L_tmp = Mult_32_16(denv[i], Random(cng_ener_seed1)); L_tmp = Mult_32_16(L_tmp, GAIN_VAR); - L_tmp = L_add(L_tmp, denv[i]); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, denv[i] ); + itmp[i] = L_add_sat(L_tmp, itmp[i]); +#else + L_tmp = L_add( L_tmp, denv[i] ); itmp[i] = L_add(L_tmp, itmp[i]); +#endif move32();/* Q6 */ if (itmp[i] < 0) diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index 53ad86ae4..857bb45a4 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -2783,7 +2783,11 @@ void fft3_fx(const Word16 X[], Word16 Y[], const Word16 n) /* special case: i = 0 */ acc = L_mult(*RZ0++, 0x4000); acc = L_mac(acc, *RZ1++, 0x4000); - *RY++ = mac_r(acc, *RZ2++, 0x4000); +#ifdef BASOP_NOGLOB + *RY++ = mac_r_sat( acc, *RZ2++, 0x4000 ); +#else + *RY++ = mac_r( acc, *RZ2++, 0x4000 ); +#endif move16(); /* first 3/12-- from 1 to (3*m/8)-1 */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index f6df457ba..2c23cfbf2 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -290,8 +290,11 @@ void stat_noise_uv_mod_fx( L_tmp = L_mult(Exc2_local[i], alpha); /* Q_local + 16 */ L_tmp = L_mac(L_tmp, randval, alpha_m1); /* Q_local + 16 */ L_tmp3 = Mult_32_16(L_tmp, Noimix_fract); /* Q_local+16+15-15 */ - L_tmp = L_add(L_tmp3, L_shl(Mult_32_16(L_tmp, tmp_res), 1)); /* Q_local+16+14-15+1 */ - +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ +#else + L_tmp = L_add( L_tmp3, L_shl( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ +#endif Exc2_local[i] = extract_h(L_tmp); /*Q_local */ } *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index c604481cc..76036a1f1 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -722,8 +722,11 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ exp2 = add(exp2, exp_sp); /* Put in Q24 */ - L_temp = L_shr(L_temp, sub(exp2, 24)); - +#ifdef BASOP_NOGLOB + L_temp = L_shr_sat( L_temp, sub( exp2, 24 ) ); +#else + L_temp = L_shr( L_temp, sub( exp2, 24 ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS return L_temp; @@ -2025,7 +2028,11 @@ void SWB_BWE_decoding_fx( FOR(; n_freq < tmp2; n_freq++) { L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, tmp - 1 ); +#endif move32(); /*15+Qsyn */ #ifdef BASOP_NOGLOB factor = add_sat( factor, factor1 ); /*Q1 */ @@ -2044,7 +2051,11 @@ void SWB_BWE_decoding_fx( FOR(; n_freq < tmp2; n_freq++) { L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1,13); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, 13 ); +#endif move32();/*15+Qsyn */ factor = add(factor,factor1); /*Q1 */ } @@ -2058,7 +2069,11 @@ void SWB_BWE_decoding_fx( FOR(; n_freq < tmp2; n_freq++) { L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1,13); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, 13 ); +#endif move32(); /*15+Qsyn */ } } diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 2c64d08ae..3ab0e54f5 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3826,8 +3826,13 @@ void elliptic_bpf_48k_generic_fx( FOR( j=0; j<4; j++ ) { - memory2_fx_2[j] =L_shl(memory_fx2[2][j],sub(add(add(*Q_input_fx,6),Q_temp) ,memory_fx_Q[2])); +#ifdef BASOP_NOGLOB + memory2_fx_2[j] = L_shl_sat( memory_fx2[2][j], sub( add( add( *Q_input_fx, 6 ), Q_temp ), memory_fx_Q[2] ) ); + memory2_fx_3[j] =L_shl_sat(memory_fx2[3][j],sub(add(add(*Q_input_fx,1) ,Q_temp) ,memory_fx_Q[3])); +#else + memory2_fx_2[j] = L_shl( memory_fx2[2][j], sub( add( add( *Q_input_fx, 6 ), Q_temp ), memory_fx_Q[2] ) ); memory2_fx_3[j] =L_shl(memory_fx2[3][j],sub(add(add(*Q_input_fx,1) ,Q_temp) ,memory_fx_Q[3])); +#endif } L_tmpX = L_shr(Mult_32_16(memory2_fx_2[0],full_band_bpf_fx[2][4]),3);/* *Q_input_fx+6 +Q_temp +13 -15 -3 */ L_tmpX = L_add(L_shr(Mult_32_16(memory2_fx_2[1],full_band_bpf_fx[2][3]),3),L_tmpX);/*Q_input_fx + 6 +Q_temp+13 -15 -3*/ @@ -4023,11 +4028,19 @@ void synthesise_fb_high_band_fx( L_tmp = Mult_32_16(ratio2,tmp[i]);/* Q(16-exp+exp_tmp-15 = 1-exp+exp_tmp) */ IF( L_tmp < 0 ) { - output[i] = negate(extract_h(L_shl(L_negate(L_tmp),tmp3)));/*Qout*/ +#ifdef BASOP_NOGLOB + output[i] = negate( extract_h( L_shl_sat( L_negate( L_tmp ), tmp3 ) ) ); /*Qout*/ +#else + output[i] = negate( extract_h( L_shl( L_negate( L_tmp ), tmp3 ) ) ); /*Qout*/ +#endif } ELSE { - output[i] = extract_h(L_shl(L_tmp,tmp3));/*Qout*/ +#ifdef BASOP_NOGLOB + output[i] = extract_h( L_shl_sat( L_tmp, tmp3 ) ); /*Qout*/ +#else + output[i] = extract_h( L_shl( L_tmp, tmp3 ) ); /*Qout*/ +#endif } } return; diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 8a5d9c611..ad6c276f4 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -393,11 +393,17 @@ void tcx_windowing_synthesis_current_frame( tmp2 = mult_r(signal[i+overlap-acelp_mem_len], window_trans[i].v.im); /*Time TDAC: 1)forward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-tmp+i], mult_r(window_trans[i].v.re, window_trans[i].v.re))); +#ifdef BASOP_NOGLOB + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); /*Time TDAC: 1)reward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); + tmp2 = add_sat(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); +#else + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); + /*Time TDAC: 1)reward part of ACELP*/ + tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); +#endif move16(); signal[i+overlap-acelp_mem_len] = tmp2; } diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index d45b4af08..0f93c2fe7 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -1893,7 +1893,11 @@ static void spec_ana_fx( man = mult_r(man,FEC_HQ_ECU_ROOT2); /* FEC_HQ_ECU_ROOT2 is sqrt(2) in Q14 */ expoBy2 = sub(expoBy2, 1); } - *pXfp++ = shr(man, expoBy2); +#ifdef BASOP_NOGLOB + *pXfp++ = shr_sat( man, expoBy2 ); +#else + *pXfp++ = shr( man, expoBy2 ); +#endif move16();/* Denormalize the mantissa back to Q0. */ } } @@ -2771,8 +2775,13 @@ static void subst_spec_fx( IF(EQ_16(element_mode, EVS_MONO)) #endif { - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); +#ifdef BASOP_NOGLOB + tmp = sub_sat( mult_r( re, cos_F ), mult_r( im, sin_F ) ); + im = add_sat(mult_r(re, sin_F), mult_r(im, cos_F)); +#else + tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); im = add(mult_r(re, sin_F), mult_r(im, cos_F)); +#endif } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 86900069b..666956e1a 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -936,7 +936,11 @@ static void shb_CNG_decod_fx( IF ( st_fx->trans_cnt_fx > 0 ) { i = extract_l(L_mult0(st_fx->trans_cnt_fx, 17)); /*Q0 */ - ener_fx = add(st_fx->shb_cng_ener_fx, mult(sin_table256_fx[i], sub(st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx))); /*Q8 */ +#ifdef BASOP_NOGLOB + ener_fx = add_sat( st_fx->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx ) ) ); /*Q8 */ +#else + ener_fx = add( st_fx->shb_cng_ener_fx, mult( sin_table256_fx[i], sub( st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx ) ) ); /*Q8 */ +#endif st_fx->trans_cnt_fx = sub(st_fx->trans_cnt_fx, 1); } diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index 5c2f22d4f..fd5801f00 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -531,8 +531,11 @@ void con_acelp( gain_32 = st->Mode2_lp_gainc; /*15Q16 *//* start-of-the-frame gain */ move16(); - ftmp = round_fx(L_shl(gain_32,1));/*Q0*/ - +#ifdef BASOP_NOGLOB + ftmp = round_fx_sat( L_shl_sat( gain_32, 1 ) ); /*Q0*/ +#else + ftmp = round_fx( L_shl( gain_32, 1 ) ); /*Q0*/ +#endif BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmp_16 = sub(shl_sat(gainCNG,sub(gainCNG_e,5/*Q5*/)),ftmp); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 8e8981c97..50b61488d 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -2683,7 +2683,11 @@ void swb_tbe_dec_fx( /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } L_tmp = L_mult0(st_fx->prev_ener_shb_fx, inv_ener); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr(L_tmp, sub(9, exp_ener)); /*27 -exp_ener -(9-exp_ener )= Q18*/ +#ifdef BASOP_NOGLOB + GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ +#else + GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ +#endif } ELSE { @@ -3173,7 +3177,11 @@ void swb_tbe_dec_fx( move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation[add(i,i_mult(j,40))] = shl(mult_r( shaped_shb_excitation[add(i,i_mult(j,40))], scale) ,3); +#ifdef BASOP_NOGLOB + shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl_sat( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); +#else + shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); +#endif move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -4340,7 +4348,11 @@ void fb_tbe_dec_fx( /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ FOR (i=0; i Date: Tue, 12 Mar 2024 12:51:00 -0400 Subject: [PATCH 28/42] fix more encoder possible saturation --- lib_com/cldfb_evs.c | 7 +++++- lib_enc/acelp_enc_util_fx.c | 17 ++++++++++++++- lib_enc/bass_psfilter_enc_fx.c | 7 +++++- lib_enc/cng_enc_fx.c | 40 +++++++++++++++++++++++++++++----- lib_enc/cod_tcx_fx.c | 12 ++++++++-- lib_enc/enc_acelpx_fx.c | 13 ++++++++--- lib_enc/enc_higher_acelp_fx.c | 7 +++++- lib_enc/gaus_enc_fx.c | 3 ++- lib_enc/ltd_stable_fx.c | 6 ++++- lib_enc/nelp_enc_fx.c | 6 ++++- lib_enc/q_gain2p_fx.c | 6 ++++- lib_enc/tcx_utils_enc_fx.c | 7 +++++- lib_enc/tns_base_enc_fx.c | 10 ++++++++- 13 files changed, 120 insertions(+), 21 deletions(-) diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index de635e018..14cd4dcb6 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -1171,8 +1171,13 @@ AnalysisPostSpectrumScaling_Fx (HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle { FOR (j=0; j < cldfbBank->no_channels; j++) { - rSubband16[i][j] = round_fx(L_shl(rSubband32[i][j], headRoom)); +#ifdef BASOP_NOGLOB + rSubband16[i][j] = round_fx_sat( L_shl_sat( rSubband32[i][j], headRoom ) ); + iSubband16[i][j] = round_fx_sat(L_shl_sat(iSubband32[i][j], headRoom)); +#else + rSubband16[i][j] = round_fx( L_shl( rSubband32[i][j], headRoom ) ); iSubband16[i][j] = round_fx(L_shl(iSubband32[i][j], headRoom)); +#endif } } diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index 89399a711..b5cb95dc0 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -78,7 +78,21 @@ Word16 E_ACELP_toeplitz_mul_fx( L_maxloc = L_shr(L_maxloc, 2); /* Do not warn saturation of L_tot, since its for headroom estimation. */ BASOP_SATURATE_WARNING_OFF_EVS - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ +#ifdef BASOP_NOGLOB + L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ + L_maxloc = L_shr(L_maxloc, 1); + L_tot = L_add_sat(L_tot, L_maxloc); /* +max/8 */ + if ( highrate ) + { + L_tot = L_add_sat(L_tot, L_maxloc); /* +max/8 */ + } + L_maxloc = L_shr(L_maxloc, 1); + if ( highrate ) + { + L_tot = L_add_sat(L_tot, L_maxloc); /* +max/16 */ + } +#else + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ L_maxloc = L_shr(L_maxloc, 1); L_tot = L_add(L_tot, L_maxloc); /* +max/8 */ if ( highrate ) @@ -90,6 +104,7 @@ Word16 E_ACELP_toeplitz_mul_fx( { L_tot = L_add(L_tot, L_maxloc); /* +max/16 */ } +#endif BASOP_SATURATE_WARNING_ON_EVS } diff --git a/lib_enc/bass_psfilter_enc_fx.c b/lib_enc/bass_psfilter_enc_fx.c index 4173a2ac6..68995ca33 100644 --- a/lib_enc/bass_psfilter_enc_fx.c +++ b/lib_enc/bass_psfilter_enc_fx.c @@ -399,8 +399,13 @@ Word16 bass_pf_enc_fx( /* *gain_factor_param = (int)(-2.f*(cross_n_d/nrg_n)+0.5f); */ tmp16 = BASOP_Util_Divide3232_Scale(cross_n_d, nrg_n, &st); /* Q15-st-s3+s4 */ BASOP_SATURATE_WARNING_OFF_EVS; - tmp16 = shl(negate(tmp16), add(sub(add(st, s3), s4), 1-14)); /* Q1 */ +#ifdef BASOP_NOGLOB + tmp16 = shl_sat( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */ + tmp16 = shr(add_sat(tmp16, 1), 1); /* Q0 */ +#else + tmp16 = shl( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */ tmp16 = shr(add(tmp16, 1), 1); /* Q0 */ +#endif BASOP_SATURATE_WARNING_ON_EVS; *gain_factor_param = tmp16; diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 58ccae7d9..5db72e0c3 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -657,19 +657,31 @@ void CNG_enc_fx( FOR ( j=0; jlp_ener_fx; */ IF(EQ_16(m1,1)) { - L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#endif } ELSE { tmp1 = div_s(1,m1); L_tmp = Mult_32_16(L_tmp,tmp1); - L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#endif } env[i] = L_tmp; @@ -795,9 +807,15 @@ void CNG_enc_fx( L_tmp = L_mult0(tmpv, tmpv); pt_res++; tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ +#else + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ +#endif } } ELSE /* L_FRAME16k */ @@ -808,9 +826,15 @@ void CNG_enc_fx( L_tmp = L_mult0(tmpv, tmpv); pt_res++; tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat(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 */ +#else + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /* 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 */ +#endif } } /* convert log2 of residual signal energy */ @@ -1365,7 +1389,11 @@ static Word16 shb_DTX_fx( shb_ener_fx = L_deposit_l(0); FOR ( i=0; iy1y1 + 2 * (*gain_code) * g_coeff->y1y2); */ s = norm_l(L_tmp1); - tmp = round_fx(L_shl(L_tmp1, s)); +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( L_tmp1, s ) ); +#else + tmp = round_fx( L_shl( L_tmp1, s ) ); +#endif s = sub(15, s); c_e = BASOP_Util_Add_MantExp(mult_r(tmp, g_coeff->y1y1), add(s, g_coeff->y1y1_e), diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index cc96f9c27..d3f5bac3e 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -738,8 +738,13 @@ void tcx_scalar_quantization_fx( FOR (; i >= 0; i--) { offs32 = Mpy_32_16_1(L_abs(x[i]), gain); /* multiply */ - offs32 = L_shl(offs32, s); /* convert to 15Q16 */ +#ifdef BASOP_NOGLOB + offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r_sat(offs32, offset, 1); /* add offset and truncate */ +#else + offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ tmp16 = mac_r(offs32, offset, 1); /* add offset and truncate */ +#endif if (x[i] < 0) tmp16 = negate(tmp16); /* restore sign */ xq[i] = tmp16; diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index 994ac19c3..7245ee42e 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -150,11 +150,19 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, facs_e[iFilter][iSubdivisions] = shl(sub(tmp, shifts[iFilter][iSubdivisions]), 1); tmp = sub(1, shl(tmp, 1)); /* exponent of autocorrelation */ - L_tmp = L_shl(L_tmp, sub(shift, tmp)); /* shift L_tmp to that exponent */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ + + /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ + move16(); + facs[iFilter][iSubdivisions] = div_s(0x2000, round_fx_sat(L_tmp)); /* L_tmp is >= 0x2000000 */ +#else + L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ move16(); facs[iFilter][iSubdivisions] = div_s(0x2000, round_fx(L_tmp)); /* L_tmp is >= 0x2000000 */ +#endif } } -- GitLab From 974ce8be8a44f9befd5ed77bd691340cc402936c Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 12 Mar 2024 13:59:15 -0400 Subject: [PATCH 29/42] fix more possible saturation --- lib_com/arith_coder_fx.c | 2 +- lib_com/basop_util.c | 19 ++++++++++++++++--- lib_com/cldfb_evs.c | 7 ++++++- lib_com/codec_tcx_common.c | 6 +++++- lib_com/est_tilt_fx.c | 28 +++++++++++++++++++++++----- lib_com/lpc_tools_fx.c | 7 ++++++- lib_com/lsf_tools_fx.c | 2 +- lib_com/swb_bwe_com_fx.c | 13 ++++++++++--- lib_com/tcx_utils_fx.c | 10 +++++++++- lib_dec/FEC_clas_estim_fx.c | 6 +++++- lib_dec/FEC_fx.c | 6 +++++- lib_dec/dec_post_fx.c | 6 +++++- lib_dec/dec_tcx_fx.c | 6 +++++- lib_dec/er_dec_acelp_fx.c | 6 +++++- lib_dec/igf_dec_fx.c | 19 ++++++++++++++++--- lib_dec/tonalMDCTconcealment_fx.c | 22 +++++++++++++++++++--- lib_enc/arith_coder_enc_fx.c | 6 +++++- lib_enc/cod_tcx_fx.c | 6 +++++- lib_enc/enc_acelp_fx.c | 7 ++++++- lib_enc/enc_uv_fx.c | 11 ++++++++++- lib_enc/fd_cng_enc_fx.c | 6 +++++- lib_enc/igf_enc_fx.c | 27 +++++++++++++++++++++++---- lib_enc/lp_exc_e_fx.c | 6 +++++- lib_enc/lsf_msvq_ma_enc_fx.c | 7 ++++++- lib_enc/vlpc_1st_cod_fx.c | 18 +++++++++++++++--- 25 files changed, 217 insertions(+), 42 deletions(-) diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 5fd4b472e..ee2bfd0fd 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -29,7 +29,7 @@ Word32 expfp( /* o: Q31 */ xf = extract_l(L_tmp); BASOP_SATURATE_WARNING_OFF_EVS; - xf = negate(xf); + xf = negate( xf ); BASOP_SATURATE_WARNING_ON_EVS; /* Fractional part */ diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index bf25f1b0c..37bf62d01 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -370,7 +370,11 @@ static Word32 Sqrt32_common(Word32 m, if (m != 0) { BASOP_SATURATE_WARNING_OFF_EVS; - m = L_mac(SqrtTable[index], SqrtDiffTable[index], frac); +#ifdef BASOP_NOGLOB + m = L_mac_sat( SqrtTable[index], SqrtDiffTable[index], frac ); +#else + m = L_mac( SqrtTable[index], SqrtDiffTable[index], frac ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -654,8 +658,13 @@ void BASOP_Util_Sqrt_InvSqrt_MantExp(Word16 mantissa, /*!< mantissa */ /* interpolate */ BASOP_SATURATE_WARNING_OFF_EVS; - m = mac_r(SqrtTable[index], SqrtDiffTable[index], frac); +#ifdef BASOP_NOGLOB + m = mac_r_sat( SqrtTable[index], SqrtDiffTable[index], frac ); + mi = msu_r_sat(ISqrtTable[index], ISqrtDiffTable[index], frac); +#else + m = mac_r( SqrtTable[index], SqrtDiffTable[index], frac ); mi = msu_r(ISqrtTable[index], ISqrtDiffTable[index], frac); +#endif BASOP_SATURATE_WARNING_ON_EVS; /* handle even/odd exponents */ @@ -2035,7 +2044,11 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of compari } BASOP_SATURATE_WARNING_OFF_EVS - diff_m = L_sub(a_m, b_m); +#ifdef BASOP_NOGLOB + diff_m = L_sub_sat( a_m, b_m ); +#else + diff_m = L_sub( a_m, b_m ); +#endif BASOP_SATURATE_WARNING_ON_EVS diff_e = sub(a_e, b_e); diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 14cd4dcb6..d98c33b5b 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -1417,8 +1417,13 @@ GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | p sm = sub(s_min(s, 44), 1); BASOP_SATURATE_WARNING_OFF_EVS /* nrg + 6.1e-5f => value 0x40000000, scale 44 */ - *energyLookahead = L_add(L_shr(nrg, sub(s, sm)), +#ifdef BASOP_NOGLOB + *energyLookahead = L_add_sat( L_shr_sat( nrg, sub( s, sm ) ), + L_shr_sat(0x40000000, s_max(-31, s_min(31, sub(44, sm))))); +#else + *energyLookahead = L_add( L_shr( nrg, sub( s, sm ) ), L_shr(0x40000000, s_max(-31, s_min(31, sub(44, sm))))); +#endif move32(); BASOP_SATURATE_WARNING_ON_EVS *sf_energyLookahead = sm; diff --git a/lib_com/codec_tcx_common.c b/lib_com/codec_tcx_common.c index 5a83b4561..c6c81d9e0 100644 --- a/lib_com/codec_tcx_common.c +++ b/lib_com/codec_tcx_common.c @@ -41,7 +41,11 @@ Word16 tcxGetNoiseFillingTilt( Copy_Scale_sig(A, As, lpcorder + 1, sub(norm_s(A[0]),2)); tmp = get_gain(As + 1, As, lpcorder); BASOP_SATURATE_WARNING_OFF_EVS; - *noiseTiltFactor = add(round_fx(L_shl(tmp, 15)), 3072/*0.09375f Q15*/); +#ifdef BASOP_NOGLOB + *noiseTiltFactor = add_sat( round_fx_sat( L_shl_sat( tmp, 15 ) ), 3072 /*0.09375f Q15*/ ); +#else + *noiseTiltFactor = add( round_fx( L_shl( tmp, 15 ) ), 3072 /*0.09375f Q15*/ ); +#endif move16(); BASOP_SATURATE_WARNING_ON_EVS; } diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index addad1aee..0c5df1ee1 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -70,8 +70,13 @@ Word16 est_tilt_fx( /* o : tilt of the code Q15 * i = sub(exp1, exp2); BASOP_SATURATE_WARNING_OFF_EVS - ener1 = shr(ener1, sub(1, s_min(i, 0))); +#ifdef BASOP_NOGLOB + ener1 = shr_sat( ener1, sub( 1, s_min( i, 0 ) ) ); + ener2 = shr_sat(ener2, add(s_max(0, i), 1)); +#else + ener1 = shr( ener1, sub( 1, s_min( i, 0 ) ) ); ener2 = shr(ener2, add(s_max(0, i), 1)); +#endif BASOP_SATURATE_WARNING_ON_EVS tmp = sub(ener1, ener2); ener1 = add(add(ener1, ener2), 1); @@ -155,10 +160,15 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 i = sub(exp1, exp2); BASOP_SATURATE_WARNING_OFF_EVS - ener1 = shr(ener1, sub(1, s_min(i, 0))); +#ifdef BASOP_NOGLOB + ener1 = shr_sat( ener1, sub( 1, s_min( i, 0 ) ) ); + ener2 = shr_sat(ener2, add(s_max(0, i), 1)); +#else + ener1 = shr( ener1, sub( 1, s_min( i, 0 ) ) ); ener2 = shr(ener2, add(s_max(0, i), 1)); +#endif BASOP_SATURATE_WARNING_ON_EVS - tmp = sub(ener1, ener2); + tmp = sub(ener1, ener2); ener1 = add(add(ener1, ener2), 1); /* find voice factor (1=voiced, -1=unvoiced) */ @@ -331,13 +341,21 @@ void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitatio IF(i >= 0) { ener = L_shr(ener,1); - tmp = L_shr(tmp, add(1,i)); +#ifdef BASOP_NOGLOB + tmp = L_shr_sat( tmp, add( 1, i ) ); +#else + tmp = L_shr( tmp, add( 1, i ) ); +#endif } ELSE { tmp = L_shr(tmp,1); BASOP_SATURATE_WARNING_OFF_EVS - ener = L_shr(ener, sub(1,i)); +#ifdef BASOP_NOGLOB + ener = L_shr_sat( ener, sub( 1, i ) ); +#else + ener = L_shr( ener, sub( 1, i ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS } diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index 1733137c7..162459de9 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -1404,8 +1404,13 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 * Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i])); Word16 ImBr = extract_h((L_negate(L_add(ImagFFT[i], ImagFFT[N/2-i])))); BASOP_SATURATE_WARNING_OFF_EVS - tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im); +#ifdef BASOP_NOGLOB + tmpw15.v.re = mac_r_sat( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); + tmpw15.v.im = msu_r_sat(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); +#else + tmpw15.v.re = mac_r( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); +#endif BASOP_SATURATE_WARNING_ON_EVS RealOut[i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); move16(); diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index e844a58ef..5e7f5f44c 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -159,7 +159,7 @@ static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift) BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, shift, &Overflow); /* Qx to Q30 with saturation */ + t0 = L_shl_o(t0, shift, &Overflow); /* Qx to Q30 with saturation */ cheb = round_fx_o(t0, &Overflow); /* Result in Q14 */ #else /* BASOP_NOGLOB */ t0 = L_shl(t0, shift); /* Qx to Q30 with saturation */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 76036a1f1..8f3bd7626 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -833,13 +833,20 @@ Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* *tilt_flt = (float)(r1/sqrt(r0)); */ exp2 = norm_l(L_ener); - L_temp = Mult_32_16(L_temp, round_fx(L_shl(L_ener, exp2))); +#ifdef BASOP_NOGLOB + L_temp = Mult_32_16( L_temp, round_fx( L_shl_sat( L_ener, exp2 ) ) ); +#else + L_temp = Mult_32_16( L_temp, round_fx( L_shl( L_ener, exp2 ) ) ); +#endif exp2 = sub(exp2, tmp_exp); exp2 = add(exp2, exp_sp); /* Put in Q24 */ - L_temp = L_shr(L_temp, sub(exp2, 24)); - +#ifdef BASOP_NOGLOB + L_temp = L_shr_sat( L_temp, sub( exp2, 24 ) ); +#else + L_temp = L_shr( L_temp, sub( exp2, 24 ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS return L_temp; diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index ad6c276f4..4501fa273 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -1702,7 +1702,11 @@ void tcx_noise_filling( tmp32 = BASOP_Util_Log2(L_deposit_h(s_max(0x3000, tiltCompFactor))); /* 6Q25 */ tmp32 = L_shr(Mpy_32_16_1(tmp32, tmp1), 6); BASOP_SATURATE_WARNING_OFF_EVS; - tilt_factor = round_fx(BASOP_Util_InvLog2(tmp32)); +#ifdef BASOP_NOGLOB + tilt_factor = round_fx_sat( BASOP_Util_InvLog2( tmp32 ) ); +#else + tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS; /* find last nonzero line below iFirstLine, use it as start offset */ @@ -1846,7 +1850,11 @@ void tcx_noise_filling_with_shift( tmp32 = BASOP_Util_Log2( L_deposit_h( s_max( 0x3000, tiltCompFactor ) ) ); /* 6Q25 */ tmp32 = L_shr( Mpy_32_16_1( tmp32, tmp1 ), 6 ); BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef BASOP_NOGLOB + tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); +#else tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS; /* find last nonzero line below iFirstLine, use it as start offset */ diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index 786912b4c..f00683788 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -353,7 +353,11 @@ void FEC_clas_estim_fx( tmp_x = extract_h(L_shl(Ltmp, exp2)); exp2 = sub(31-1+3, exp2); BASOP_SATURATE_WARNING_OFF_EVS - tmpS = shr(sub(tmp_x, tmp_y), 16); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ +#ifdef BASOP_NOGLOB + tmpS = shr( sub_sat( tmp_x, tmp_y ), 16 ); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ +#else + tmpS = shr( sub( tmp_x, tmp_y ), 16 ); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ +#endif BASOP_SATURATE_WARNING_ON_EVS tmp_y = shl(tmp_y, tmpS); exp1 = sub(exp1, tmpS); diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 7b0c42b13..6e0986388 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -817,7 +817,11 @@ static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 tmp_pit2 = L_mult(Tc,4915/*0.15f Q15*/);/*Q16*/ BASOP_SATURATE_WARNING_OFF_EVS /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ - tmp_pit2 = L_shl(L_negate(tmp_pit2),sub(15-16,tmp_pit_e)); +#ifdef BASOP_NOGLOB + tmp_pit2 = L_shl_sat( L_negate( tmp_pit2 ), sub( 15 - 16, tmp_pit_e ) ); +#else + tmp_pit2 = L_shl( L_negate( tmp_pit2 ), sub( 15 - 16, tmp_pit_e ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS *cond3 = L_sub(L_mult0(-1, tmp_pit),tmp_pit2); } diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index c5e5728b6..de4afc8c4 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -1838,7 +1838,11 @@ void Filt_mu_fx( BASOP_SATURATE_WARNING_OFF_EVS; /*sig_out[n] = saturate(L_temp); move16();*/ - sig_out[n] = round_fx(L_temp); +#ifdef BASOP_NOGLOB + sig_out[n] = round_fx_sat( L_temp ); +#else + sig_out[n] = round_fx( L_temp ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 079fc9a0e..be8c46a61 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2200,7 +2200,11 @@ void IMDCT(Word32 *x, Word16 x_e, tmp3 = shr(tcx_mdct_window_half_length, 1); FOR (i=0; i < tmp1; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR (i = 0; i < tmp3; i++) diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index fd5801f00..cb17a05cf 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -205,7 +205,11 @@ void con_acelp( Tc = round_fx(tmp_tc); BASOP_SATURATE_WARNING_OFF_EVS /*if this ever saturates, it doesn't matter*/ - tmp = sub(shl(abs_s(sub(T0,Tc)),6) , mult(19661/*0.15f Q17*/,shl(Tc,4)) /*Q6*/); +#ifdef BASOP_NOGLOB + tmp = sub( shl_sat( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl_sat( Tc, 4 ) ) /*Q6*/ ); +#else + tmp = sub( shl( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl( Tc, 4 ) ) /*Q6*/ ); +#endif BASOP_SATURATE_WARNING_ON_EVS test(); test(); diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 6d342c33b..8131fcac3 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -1703,8 +1703,13 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* Build a threshold and compare with L_tmp. Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ BASOP_SATURATE_WARNING_OFF_EVS - L_tmp2 = L_shl(L_negate(Mpy_32_16_1(sNlocal, 33/*0.001f Q15*/)), sub(sNlocal_e,L_tmp_e)); +#ifdef BASOP_NOGLOB + L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); + L_tmp2 = L_sub_sat(L_tmp2, L_negate(L_tmp)); +#else + L_tmp2 = L_shl( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); L_tmp2 = L_sub(L_tmp2, L_negate(L_tmp)); +#endif BASOP_SATURATE_WARNING_ON_EVS IF (L_tmp2 < 0 ) @@ -1972,7 +1977,11 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* gain[sfb] = min(gain[sfb], 12.f); */ BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ - tmp = shl(gain[sfb], sub(gain_e[sfb], 15 - 5)); /* 10Q5 | tmp is in 10Q5 */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#else + tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#endif BASOP_SATURATE_WARNING_ON_EVS IF (tmp > 384) /* 10Q5 | 384 = 12 in 10Q5 */ @@ -2619,7 +2628,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* gain[sfb] = min(gain[sfb], 12.f); */ BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ - tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#else + tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#endif BASOP_SATURATE_WARNING_ON_EVS IF( tmp > 384 ) /* 10Q5 | 384 = 12 in 10Q5 */ diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index c5879539b..1122fc614 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1389,7 +1389,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ +#ifdef BASOP_NOGLOB + tiltFactor = shl_sat( tiltFactor, exp ); +#else tiltFactor = shl( tiltFactor, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = MAX16B; move16(); @@ -1913,7 +1917,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] - hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1 ), 15, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ - tmp = shl( tmp, exp ); +#ifdef BASOP_NOGLOB + tmp = shl_sat( tmp, exp ); +#else + tmp = shl( tmp, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = mult_r( tilt, tmp ); @@ -2323,7 +2331,11 @@ void TonalMDCTConceal_InsertNoise( inv_samples = Inv16(hTonalMDCTConc->lastBlockData.nSamples, &inv_exp); tiltFactor = round_fx(BASOP_Util_fPow(L_max(L_tmp, L_deposit_h(tiltCompFactor)), 0, L_deposit_h(inv_samples),inv_exp, &exp)); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ - tiltFactor = shl(tiltFactor, exp); +#ifdef BASOP_NOGLOB + tiltFactor = shl_sat( tiltFactor, exp ); +#else + tiltFactor = shl( tiltFactor, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = 32767/*1.0f Q15*/; @@ -2498,7 +2510,11 @@ void TonalMDCTConceal_InsertNoise( tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI_fix->upperIndex[hTonalMDCTConc->pTCI_fix->numIndexes-1]-hTonalMDCTConc->pTCI_fix->lowerIndex[hTonalMDCTConc->pTCI_fix->numIndexes-1]+1),15, &exp)); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ - tmp = shl(tmp, exp); +#ifdef BASOP_NOGLOB + tmp = shl_sat( tmp, exp ); +#else + tmp = shl( tmp, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = mult_r(tilt,tmp); diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 9a6bb3e77..ef4c39dfd 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -92,7 +92,11 @@ static Word16 tcx_arith_estimate_scale( /* scale and accumulate */ BASOP_SATURATE_WARNING_OFF_EVS; - accu = L_add(accu, L_shr(L_tmp, sub(tmp, s))); +#ifdef BASOP_NOGLOB + accu = L_add_sat( accu, L_shr( L_tmp, sub( tmp, s ) ) ); +#else + accu = L_add( accu, L_shr( L_tmp, sub( tmp, s ) ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } s = sub(shl(add(abs_spectrum_e, envelope_e), 1), s); diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index a62ce8957..c203dd2bb 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1688,7 +1688,11 @@ void QuantizeSpectrum_fx( IF (tmp2 >= 0) { BASOP_SATURATE_WARNING_OFF_EVS; - tmp2 = sub(sqGain, shr(tmp1, tmp2)); +#ifdef BASOP_NOGLOB + tmp2 = sub_sat( sqGain, shr_sat( tmp1, tmp2 ) ); +#else + tmp2 = sub( sqGain, shr( tmp1, tmp2 ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } ELSE diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index d234a1dd9..450a27671 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -466,8 +466,13 @@ static void E_ACELP_xh_corr(Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr) L_maxloc = L_shr(L_maxloc, 2); /* Do not warn saturation of L_tot, since its for headroom estimation. */ BASOP_SATURATE_WARNING_OFF_EVS - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ +#ifdef BASOP_NOGLOB + L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add_sat(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ +#else + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ L_tot = L_add(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ +#endif BASOP_SATURATE_WARNING_ON_EVS } diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 1b7bcd264..cbe7bbe5f 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -196,7 +196,11 @@ void encod_unvoiced_fx( hLPDmem->mem_w0 = sub(xn_fx[L_SUBFR - 1], round_fx(L_shl(Ltmp, 1))); move16(); BASOP_SATURATE_WARNING_OFF_EVS; - hLPDmem->mem_w0 = shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#else + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#endif BASOP_SATURATE_WARNING_ON_EVS; /*-------------------------------------------------------* @@ -220,10 +224,15 @@ void encod_unvoiced_fx( Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code_fx[i]); Ltmp2 = L_shl(Ltmp2, Q_new_p5); Ltmp = L_add(Ltmp, Ltmp2); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat(Ltmp, 1); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx_sat(Ltmp); +#else BASOP_SATURATE_WARNING_OFF_EVS Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ BASOP_SATURATE_WARNING_ON_EVS exc_fx[i + i_subfr] = round_fx(Ltmp); +#endif } tmp2 = L_SUBFR; move16(); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index ab9895e01..7978ae278 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -808,7 +808,11 @@ static void msvq_encoder (const Word16 * const cb[], /* i : Codebook (indexed c tmp = L_add(dist[0][c], L_sub(en, L_shl(t1, 1))); BASOP_SATURATE_WARNING_OFF_EVS - t1 = L_sub(tmp,dist[1][p_max]); +#ifdef BASOP_NOGLOB + t1 = L_sub_sat( tmp, dist[1][p_max] ); +#else + t1 = L_sub( tmp, dist[1][p_max] ); +#endif BASOP_SATURATE_WARNING_ON_EVS IF ( t1 <= 0 ) /* IF (L_sub(L_shr(tmp,1), L_shr(dist[1][p_max],1) ) <= 0 ) */ diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 7ff0116c4..857e08038 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -490,7 +490,11 @@ static void IGF_ErodeSpectrum(Word16 *highPassEner_e { /* May overflow - just for threshold comparison */ BASOP_SATURATE_WARNING_OFF_EVS - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); +#else + L_tmp = L_add( pPowerSpectrum[i], highPassEner_Ovfl ); +#endif BASOP_SATURATE_WARNING_ON_EVS IF (L_tmp < 0) @@ -515,7 +519,11 @@ static void IGF_ErodeSpectrum(Word16 *highPassEner_e /* May overflow - just for threshold comparison */ BASOP_SATURATE_WARNING_OFF_EVS - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); +#else + L_tmp = L_add( pPowerSpectrum[i], highPassEner_Ovfl ); +#endif BASOP_SATURATE_WARNING_ON_EVS IF (L_tmp < 0) { @@ -622,8 +630,13 @@ static Word16 IGF_getCrest( /* limit crest factor to a lower bound of 1, may overflow */ BASOP_SATURATE_WARNING_OFF_EVS - tmp = shl(-1, sub(15, *crest_exp)); /* build negative threshold */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ + tmp = add_sat( crest, tmp ); +#else + tmp = shl( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ tmp = add(crest, tmp); +#endif BASOP_SATURATE_WARNING_ON_EVS if (tmp < 0) { @@ -855,7 +868,13 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc BASOP_SATURATE_WARNING_OFF_EVS /*SFM = min(2.7f, SFM);*/ /*Overflow possible in shift, intended*/ - SFM = s_min(22118/*2.7f Q13*/,extract_h(L_shr(SFM32,16-29)/*->Q29*/)/*->Q13*/ ); +#ifdef BASOP_NOGLOB + tmp = add_sat( crest, tmp ); + SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr_sat( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); +#else + tmp = add( crest, tmp ); + SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); +#endif BASOP_SATURATE_WARNING_ON_EVS hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ move32(); diff --git a/lib_enc/lp_exc_e_fx.c b/lib_enc/lp_exc_e_fx.c index b118da9d7..6cddd32aa 100644 --- a/lib_enc/lp_exc_e_fx.c +++ b/lib_enc/lp_exc_e_fx.c @@ -419,7 +419,11 @@ Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ /* Note: shl works as shl or shr. */ exp_xx = sub(exp_xx,1); BASOP_SATURATE_WARNING_OFF_EVS - gain_p_snr = round_fx(L_shl(Mpy_32_16_1( 1717986944l/*ACELP_GAINS_CONST Q31*/, tmp), exp_xx)); +#ifdef BASOP_NOGLOB + gain_p_snr = round_fx_sat( L_shl_sat( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_xx ) ); +#else + gain_p_snr = round_fx( L_shl( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_xx ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS gain = s_min(gain, gain_p_snr); diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 57106caa0..0d0cecb67 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -340,8 +340,13 @@ void msvq_enc_fx BASOP_SATURATE_WARNING_OFF_EVS /*NOTE: as long as a shorter distance is found, saturation can be accepted.*/ - tmp = L_add(dist[0][c], L_sub(en, L_shl(t1,1))); +#ifdef BASOP_NOGLOB + tmp = L_add_sat( dist[0][c], L_sub_sat( en, L_shl( t1, 1 ) ) ); + t1 = L_sub_sat(tmp ,dist[1][p_max]); +#else + tmp = L_add( dist[0][c], L_sub( en, L_shl( t1, 1 ) ) ); t1 = L_sub(tmp ,dist[1][p_max]); +#endif BASOP_SATURATE_WARNING_ON_EVS IF (t1 <= 0) diff --git a/lib_enc/vlpc_1st_cod_fx.c b/lib_enc/vlpc_1st_cod_fx.c index 7c633039b..afbb03923 100644 --- a/lib_enc/vlpc_1st_cod_fx.c +++ b/lib_enc/vlpc_1st_cod_fx.c @@ -55,14 +55,26 @@ static void lsf_weight( FOR (i=1; i<(M-2); i+=2) /*for (i=1; i<(M-2); i+=2)*/ { inv_di1 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*0Q15*/ /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ - w[i-1] = add(inv_di0,inv_di1); +#ifdef BASOP_NOGLOB + w[i - 1] = add_sat( inv_di0, inv_di1 ); +#else + w[i - 1] = add( inv_di0, inv_di1 ); +#endif move16(); /*0Q15*/ /*w[i-1] = inv_di0 + inv_di1;*/ inv_di0 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i+1],lsfq[i]))); /*0Q15*/ /*inv_di0 = 1.0f / (lsfq[i+1] - lsfq[i]);*/ - w[i] = add(inv_di1,inv_di0); +#ifdef BASOP_NOGLOB + w[i] = add_sat( inv_di1, inv_di0 ); +#else + w[i] = add( inv_di1, inv_di0 ); +#endif move16(); /*0Q15*/ /*w[i] = inv_di1 + inv_di0;*/ } inv_di1 = div_s(ISF_ONE, s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ - w[i-1] = add(inv_di0,inv_di1); +#ifdef BASOP_NOGLOB + w[i - 1] = add_sat( inv_di0, inv_di1 ); +#else + w[i - 1] = add( inv_di0, inv_di1 ); +#endif move16(); /*w[i-1] = inv_di0 + inv_di1;*/ inv_di0 = div_s(ISF_ONE, s_max(ISF_ONE, sub(FREQ_MAX,lsfq[i]))); /*inv_di0 = 1.0f / (FREQ_MAX - lsfq[i]);*/ #ifdef BASOP_NOGLOB -- GitLab From 108ffa09231ba53c5a10a65b85830e41f12da66f Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 12 Mar 2024 14:56:53 -0400 Subject: [PATCH 30/42] more saturation fixes on decode side --- lib_com/env_stab.c | 8 +++- lib_com/hq_tools_fx.c | 15 ++++++-- lib_com/swb_bwe_com_fx.c | 6 ++- lib_com/swb_tbe_com_fx.c | 71 ++++++++++++++++++++++++++++++++++- lib_dec/FEC_HQ_phase_ecu_fx.c | 31 ++++++++++++--- lib_dec/er_dec_acelp_fx.c | 6 ++- lib_dec/evs_dec_fx.c | 12 +++++- lib_dec/gain_dec_fx.c | 6 ++- lib_dec/post_dec_fx.c | 13 ++++++- 9 files changed, 150 insertions(+), 18 deletions(-) diff --git a/lib_com/env_stab.c b/lib_com/env_stab.c index 751b9f992..e2a78ff18 100644 --- a/lib_com/env_stab.c +++ b/lib_com/env_stab.c @@ -252,9 +252,15 @@ Word16 env_stability_fx( /* in Q15 */ #endif L_tmp = L_mult0(26214, env_delta); /* 26214 is 0.1 in Q18. Q28 */ - L_tmp = L_mac(L_tmp, 29491, *mem_env_delta); /* 29491 is 0.9 in Q15. Q28 */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_mac_sat( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */ + + *mem_env_delta = round_fx_sat(L_tmp); /* Q12 */ +#else + L_tmp = L_mac( L_tmp, 29491, *mem_env_delta ); /* 29491 is 0.9 in Q15. Q28 */ *mem_env_delta = round_fx(L_tmp); /* Q12 */ +#endif Overflow = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Overflow */ diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index a27483de8..a992f96dc 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -2442,12 +2442,21 @@ void hq_wb_nf_bwe_fx( test(); test(); test(); - IF(GT_32(L_abs(L_coeff_out[i]), L_shl(L_abs(*p_prev_coeff_out), 2)) +#ifdef BASOP_NOGLOB + IF( GT_32( L_abs( L_coeff_out[i] ), L_shl_sat( L_abs( *p_prev_coeff_out ), 2 ) ) + || LT_32(L_abs(L_coeff_out[i]), L_shr(L_abs(*p_prev_coeff_out), 2)) + || ((R[sfm] == 0 || *prev_R == 0) && add_sat(R[sfm], *prev_R) != 0)) +#else + IF( GT_32( L_abs( L_coeff_out[i] ), L_shl( L_abs( *p_prev_coeff_out ), 2 ) ) || LT_32(L_abs(L_coeff_out[i]), L_shr(L_abs(*p_prev_coeff_out), 2)) || ((R[sfm] == 0 || *prev_R == 0) && add(R[sfm], *prev_R) != 0)) +#endif { - L_tmp = L_add(L_shr(L_abs(L_coeff_out[i]), 1), L_shr(L_abs(*p_prev_coeff_out), 1)); - +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); +#else + L_tmp = L_add( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); +#endif if (L_coeff_out[i] <= 0) { L_tmp = L_negate(L_tmp); diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 8f3bd7626..6bdeec171 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2004,7 +2004,11 @@ void SWB_BWE_decoding_fx( FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp2; n_freq++) { L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, tmp - 1 ); +#endif move32();/*15+Qsyn */ factor = add(factor, factor1); /*Q3 */ } diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 3ab0e54f5..2f6ff57a3 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3834,7 +3834,74 @@ void elliptic_bpf_48k_generic_fx( memory2_fx_3[j] =L_shl(memory_fx2[3][j],sub(add(add(*Q_input_fx,1) ,Q_temp) ,memory_fx_Q[3])); #endif } - L_tmpX = L_shr(Mult_32_16(memory2_fx_2[0],full_band_bpf_fx[2][4]),3);/* *Q_input_fx+6 +Q_temp +13 -15 -3 */ +#ifdef BASOP_NOGLOB + L_tmpX = L_shr( Mult_32_16( memory2_fx_2[0], full_band_bpf_fx[2][4] ), 3 ); /* *Q_input_fx+6 +Q_temp +13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[1], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[2], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[3], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[2], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[1], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + L_output[0] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[0], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + move32(); + L_tmpMax = L_abs(L_output[0]); + + L_tmpX = L_shr(Mult_32_16(memory2_fx_2[1],full_band_bpf_fx[2][4]),3);/*Q_input_fx + 6 +Q_temp +13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[2], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[3], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[1], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx+Q_temp + 6 +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[0], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[2], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + L_output[1] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[1], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + move32(); + L_tmpMax = L_max(L_tmpMax,L_abs(L_output[1])); + + L_tmpX = L_shr(Mult_32_16(memory2_fx_2[2],full_band_bpf_fx[2][4]),3);/*Q_input_fx + 6 +Q_temp+13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[3], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[1], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp + 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[2], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp + 6 +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[1], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[0], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1+Q_temp +13 -15 + 2*/ + L_output[2] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[2], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + move32(); + L_tmpMax = L_max(L_tmpMax,L_abs(L_output[2])); + + L_tmpX = L_shr(Mult_32_16(memory2_fx_2[3],full_band_bpf_fx[2][4]),3);/*Q_input_fx + 6 +Q_temp +13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[1], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[2], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[3], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[2], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[1], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[0], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_output[3] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + move32(); + L_tmpMax = L_max(L_tmpMax,L_abs(L_output[3])); + + FOR( i=4; iMode2_lp_gainc, gain_inov), add(15, s_gain_inov)))); /* norm_s for gain*gain_inov at the end of the following loops */ +#ifdef BASOP_NOGLOB + g_e = norm_s( round_fx_sat( L_shl_sat( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ +#else + g_e = norm_s( round_fx( L_shl( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ +#endif g_e = s_min(norm_s(gain_16), g_e); gain_16 = shl(gain_16, g_e); gain_32 = L_shl(gain_32, g_e); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 48e330251..33a4dd9b4 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -184,7 +184,11 @@ ivas_error evs_dec_fx( FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { - hTcxDec->syn_OverlFB[i] = shl(mult(tmp1, hTcxDec->syn_OverlFB[i]), add(s,1)); +#ifdef BASOP_NOGLOB + hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); +#else + hTcxDec->syn_OverlFB[i] = shl( mult( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); +#endif move16(); } @@ -193,7 +197,11 @@ ivas_error evs_dec_fx( tmp1 = extract_l(L_shr_r(f,s)); FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ ) { - hTcxDec->syn_Overl[i] = shl(mult(tmp1, hTcxDec->syn_Overl[i]),s); +#ifdef BASOP_NOGLOB + hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); +#else + hTcxDec->syn_Overl[i] = shl( mult( tmp1, hTcxDec->syn_Overl[i] ), s ); +#endif move16(); } } diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index c73f01753..885ddeb6f 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -607,7 +607,11 @@ void gain_dec_lbr_fx( move16(); L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); +#endif move16(); /* Q10 -> Q16*/ gc_mem[0] = *gain_code_fx; diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index dec6dd1e4..b15ab373d 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -345,7 +345,17 @@ static void bass_pf_1sf_delay( Word64 ener2_64 = W_deposit32_l( ener2 ); FOR (i = lg; i < l_subfr; i++) { - tmp32 = L_mult0(gain, syn[i+i_subfr]); +#ifdef BASOP_NOGLOB + tmp32 = L_mult0( gain, syn[i + i_subfr] ); + tmp32 = L_msu0_sat(tmp32, gain, syn[i+i_subfr-T]); /* Q0 */ + tmp16 = round_fx_sat(tmp32); + + lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); + lp_error = L_mac_sat(lp_error, tmp16, 0x1000); /* Q13 */ + + tmp16 = round_fx_sat(L_shl_sat(lp_error, s1)); /* Q0+s1-3 */ +#else + tmp32 = L_mult0( gain, syn[i + i_subfr] ); tmp32 = L_msu0(tmp32, gain, syn[i+i_subfr-T]); /* Q0 */ tmp16 = round_fx(tmp32); @@ -353,6 +363,7 @@ static void bass_pf_1sf_delay( lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ +#endif ener2_64 = W_mac0_16_16(ener2_64, tmp16, tmp16); /* Q0+(s1-3)*2 */ } ener2 = W_sat_l(ener2_64); -- GitLab From 9f1a30fcb6ce66a8de66cf731bad2419f1267e74 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 13 Mar 2024 11:34:55 -0400 Subject: [PATCH 31/42] more staturation fixes based on a different saturation level --- lib_com/igf_base_fx.c | 6 +++++- lib_com/stat_noise_uv_mod_fx.c | 6 +++++- lib_com/wi_fx.c | 6 +++++- lib_enc/hq_lr_enc_fx.c | 6 +++++- lib_enc/ltd_stable_fx.c | 12 ++++++++++-- lib_enc/swb_bwe_enc_fx.c | 18 +++++++++++++++--- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index c10429a84..14d21b7e9 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -1116,7 +1116,11 @@ void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, FOR (i = sqrtBgn; i < sqrtEnd; i++) { - tmp = round_fx(L_shl(mdctSpec[i], s1)); +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); +#else + tmp = round_fx( L_shl( mdctSpec[i], s1 ) ); +#endif mdctSquareSpec[j++] = L_mult0(tmp, tmp); move32(); } diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 2c23cfbf2..3b2edce7c 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -264,7 +264,11 @@ void stat_noise_uv_mod_fx( tmp_res = div_s(1<<14, tmp_den); /* 15+14-Q_local-tmp_shift-Q_ge+16 */ L_tmp_res = Mult_32_16(*ge_sm, tmp_res); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ L_tmp_res = Mult_32_16(L_tmp_res, sub(32767, beta)); /*30-Q_local-tmp_shift+15-15 */ - L_tmp_res = L_add(L_shl(L_tmp_res, sub(add(Q_local, tmp_shift), 15)), beta); /* Q15 */ +#ifdef BASOP_NOGLOB + L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ +#else + L_tmp_res = L_add( L_shl( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ +#endif #ifdef BASOP_NOGLOB tmp_res = extract_h(L_shl_o(L_tmp_res, 15, &Overflow)); /* 15+15-16=14 */ #else diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 9d9750f0d..35f1d6578 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -3538,7 +3538,11 @@ Word16 ppp_extract_pitch_period_fx( expb = norm_l(Lacc); - fracb = round_fx(L_shl(Lacc,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( Lacc, expb ) ); +#else + fracb = round_fx( L_shl( Lacc, expb ) ); +#endif expb = sub(30, add(expb,Qres)); scale1 = shr(sub(fraca,fracb),15); diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 351f725c3..4079e2700 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -545,7 +545,11 @@ void hq_lr_enc_fx( IF(EQ_16(hHQ_core->last_bitalloc_max_band[j++], 1)) { L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = extract_h(L_shl(L_tmp,14));/*Q-2 */ +#ifdef BASOP_NOGLOB + tmp = extract_h( L_shl_sat( L_tmp, 14 ) ); /*Q-2 */ +#else + tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-2 */ +#endif IF(tmp != 0) { exp = norm_s(tmp); diff --git a/lib_enc/ltd_stable_fx.c b/lib_enc/ltd_stable_fx.c index ebb404310..decf40e20 100644 --- a/lib_enc/ltd_stable_fx.c +++ b/lib_enc/ltd_stable_fx.c @@ -408,12 +408,20 @@ void ltd_stable_fx( FOR(i=0; i<8; i++) { tmp = extract_h(tmp32[i]); - tmp_mul = L_mult(tmp,tmp); +#ifdef BASOP_NOGLOB + tmp_mul = L_mult_sat( tmp, tmp ); +#else + tmp_mul = L_mult( tmp, tmp ); +#endif tmp_mul = L_shr(tmp_mul, 3); dif32 = L_add(dif32, tmp_mul); tmp = extract_h(mid_frame_amp32[i]); - mid_frame_amp_mul = L_mult(tmp,tmp); +#ifdef BASOP_NOGLOB + mid_frame_amp_mul = L_mult_sat( tmp, tmp ); +#else + mid_frame_amp_mul = L_mult( tmp, tmp ); +#endif mid_frame_amp_mul = L_shr(mid_frame_amp_mul,3); apow32 = L_add(apow32, mid_frame_amp_mul); } diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index c402aeb28..5a1c26f0e 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -2184,7 +2184,11 @@ static Word16 SWB_BWE_encoding_fx( } /*SWB_tenv_fx[pos] = add(SWB_tenv_fx[pos], mult_r(SWB_tenv_fx[pos], 164)); move16();//Q3 */ - SWB_tenv_fx[pos] = round_fx(L_mac(L_mult(SWB_tenv_fx[pos],32767), SWB_tenv_fx[pos], 164)); /*Q3 */ +#ifdef BASOP_NOGLOB + SWB_tenv_fx[pos] = round_fx_sat( L_mac_sat( L_mult_sat( SWB_tenv_fx[pos], 32767 ), SWB_tenv_fx[pos], 164 ) ); /*Q3 */ +#else + SWB_tenv_fx[pos] = round_fx( L_mac( L_mult( SWB_tenv_fx[pos], 32767 ), SWB_tenv_fx[pos], 164 ) ); /*Q3 */ +#endif IF(LT_32(energy_fx, SWB_tenv_fx[pos])) { @@ -2202,12 +2206,20 @@ static Word16 SWB_BWE_encoding_fx( IF(GT_16(SWB_tenv_fx[n_band-1], SWB_tenv_fx[n_band])) { /*SWB_tenv_fx[n_band-1] = add(mult_r(SWB_tenv_fx[n_band-1], 16384), mult_r(SWB_tenv_fx[n_band], 16384)); move16();//Q3 */ - SWB_tenv_fx[n_band-1] = round_fx(L_mac(L_mult(SWB_tenv_fx[n_band-1], 16384), SWB_tenv_fx[n_band], 16384)); /*Q3 */ +#ifdef BASOP_NOGLOB + SWB_tenv_fx[n_band - 1] = round_fx_sat( L_mac_sat( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ +#else + SWB_tenv_fx[n_band - 1] = round_fx( L_mac( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ +#endif } ELSE { /*SWB_tenv_fx[n_band] = add(mult_r(SWB_tenv_fx[n_band-1], 16384), mult_r(SWB_tenv_fx[n_band], 16384)); move16();//Q3 */ - SWB_tenv_fx[n_band] = round_fx(L_mac(L_mult(SWB_tenv_fx[n_band-1], 16384), SWB_tenv_fx[n_band], 16384)); /*Q3 */ +#ifdef BASOP_NOGLOB + SWB_tenv_fx[n_band] = round_fx_sat( L_mac_sat( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ +#else + SWB_tenv_fx[n_band] = round_fx( L_mac( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ +#endif } } -- GitLab From 332f377ad2bcd36fc2fc91862087756eb7d7a68d Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 13 Mar 2024 12:56:12 -0400 Subject: [PATCH 32/42] more staturation fixes based on a different saturation level --- lib_enc/core_enc_init_fx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 3adad6489..7e2efe970 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -414,8 +414,13 @@ static void init_tcx_fx( move16(); } +#ifdef BASOP_NOGLOB /*pit = pit_old * (float)st->L_frame/(float)L_frame_old;*/ + pit = shl_sat(mult_r(pit_old, div_s(st->L_frame, shl(L_frame_old, 2))), 2); +/* Note : the saturation here that can happens when FS == 32kHz*/ +#else pit = shl(mult_r(pit_old, div_s(st->L_frame, shl(L_frame_old, 2))), 2); +#endif /* assert(pit <= st->L_frame);*/ hTcxEnc->tcxltp_pitch_int_past = pit; -- GitLab From 9e8e03c8466286f6dfd6935d3a3fa2ded28e2140 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 13 Mar 2024 13:46:06 -0400 Subject: [PATCH 33/42] more staturation fixes based on a different saturation level --- lib_com/hq_tools_fx.c | 6 +++++- lib_com/stab_est_fx.c | 6 +++++- lib_dec/dec_tcx_fx.c | 6 +++++- lib_dec/hq_lr_dec_fx.c | 7 ++++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index a992f96dc..89d127c8a 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -2348,7 +2348,11 @@ void hq_wb_nf_bwe_fx( #endif } - IF(GT_32(L_tmp2, L_shl(min_coef_fx, sub(exp, 13))))/*exp */ +#ifdef BASOP_NOGLOB + IF( GT_32( L_tmp2, L_shl_sat( min_coef_fx, sub( exp, 13 ) ) ) ) /*exp */ +#else + IF( GT_32( L_tmp2, L_shl( min_coef_fx, sub( exp, 13 ) ) ) ) /*exp */ +#endif { L_tmp2 = L_shr(min_coef_fx, 1); exp = 12; diff --git a/lib_com/stab_est_fx.c b/lib_com/stab_est_fx.c index e6b55fe71..de997e5c4 100644 --- a/lib_com/stab_est_fx.c +++ b/lib_com/stab_est_fx.c @@ -74,7 +74,11 @@ Word16 stab_est_fx( { /*fcorr += ftmp_c*ftmp_c;*/ tmp16 = sub(lt_diff_etot[i], mean_diff); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, tmp16, tmp16 ); +#else + L_tmp = L_mac0( L_tmp, tmp16, tmp16 ); +#endif } /*------------------------------------------------------------------------* * Update diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index be8c46a61..fe356a70a 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -574,7 +574,11 @@ void decoder_tcx( /* gainCompensate = st->last_gain_syn_deemph/(float)sqrt(dot_product( h1, h1, L_SUBFR)); */ tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gainCompensate_e)/*Q15, gainCompensate_e*/; gainCompensate_e = add(gainCompensate_e,10/*scaling of h1[0] and E_UTIL:synthesis*/); - gainCompensate = round_fx(Sqrt32(tmp32,&gainCompensate_e))/*Q15, gainCompensate_e*/; +#ifdef BASOP_NOGLOB + gainCompensate = round_fx_sat( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; +#else + gainCompensate = round_fx( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; +#endif BASOP_Util_Divide_MantExp ( st->last_gain_syn_deemph, st->last_gain_syn_deemph_e, gainCompensate, diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index f3781547e..3d1909d85 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -511,11 +511,12 @@ void hq_lr_dec_fx( IF(EQ_16(last_bitalloc_max_band[j++], 1)) { L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = Calc_inv(L_shl(L_tmp,14), &exp); #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(Mult_32_16(Ep_avrg_fx, tmp), sub(14, exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + tmp = Calc_inv( L_shl_sat( L_tmp, 14 ), &exp ); + L_tmp = L_shl_sat( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #else - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + tmp = Calc_inv( L_shl( L_tmp, 14 ), &exp ); + L_tmp = L_shl( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #endif L_tmp =L_max(L_tmp,16384); /*14 */ tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ -- GitLab From b8a936076f1ac8609dd3fee6a5d805b0c6c00dd2 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 13 Mar 2024 14:06:31 -0400 Subject: [PATCH 34/42] more staturation fixes based on a different saturation level --- lib_com/swb_bwe_com_fx.c | 6 +++++- lib_dec/cng_dec_fx.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 6bdeec171..a73fc9c21 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2410,7 +2410,11 @@ void time_reduce_pre_echo_fx( L_tmp = L_sub(L_tmp1, Ltmp_ener); /*Q(30-exp) */ L_tmp = Mult_32_16(L_tmp, tmpi); /*Q(30-exp) */ L_tmp = L_add(Ltmp_ener, L_tmp); /*Q(30-exp) */ - tmp = round_fx(L_shl(Mult_32_16(L_tmp, *pit), add(1, exp))); /*Q0 */ +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */ +#else + tmp = round_fx( L_shl( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */ +#endif *pit++ = tmp; } } diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 666956e1a..2c49ade9a 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -954,7 +954,11 @@ static void shb_CNG_decod_fx( move32(); } fra = L_Extract_lc(L_tmp, &exp); - L_tmp = L_shl(Pow2(exp, fra), 5); /*Q5 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( Pow2( exp, fra ), 5 ); /*Q5 */ +#else + L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ +#endif L_tmp = L_shr(L_tmp, 10); if( L_tmp == 0 ) { -- GitLab From e61af58df5f6a5a26a56c67a4031219cd0e24799 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 13 Mar 2024 14:33:40 -0400 Subject: [PATCH 35/42] more staturation fixes based on a different saturation level --- lib_dec/swb_tbe_dec_fx.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 50b61488d..51e7ef91b 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -1367,7 +1367,11 @@ void wb_tbe_dec_fx( prev_pow = 0; FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { +#ifdef BASOP_NOGLOB + prev_pow = L_mac0_sat( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#else prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#endif } rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); @@ -1376,7 +1380,11 @@ void wb_tbe_dec_fx( sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { +#ifdef BASOP_NOGLOB + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); +#else bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); +#endif } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); @@ -1394,8 +1402,13 @@ void wb_tbe_dec_fx( curr_pow = 0; FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { +#ifdef BASOP_NOGLOB + curr_pow = L_mac0_sat( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ +#else curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ +#endif } if( GT_16( voice_factors[0], 24576 )) -- GitLab From c52c6f41c3f1850e08511844b7cf94b7d542a728 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 13 Mar 2024 16:31:43 -0400 Subject: [PATCH 36/42] more staturation fixes based on a different scaling level --- lib_com/lsf_tools_fx.c | 6 +++++- lib_com/tec_com.c | 6 +++++- lib_enc/lsf_msvq_ma_enc_fx.c | 23 +++++++++++++++++++++-- lib_enc/pit_enc_fx.c | 6 +++++- lib_enc/pvq_encode_fx.c | 6 +++++- lib_enc/spec_flatness_fx.c | 6 +++++- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index 5e7f5f44c..9c7bc5141 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -2378,7 +2378,11 @@ void lsf2lsp_fx( { offset = negate(offset); } - L_tmp = L_mult(sub(offset, lsf_tmp), round_fx(L_shl(L_and(L_tmp, 0xFFFF), 15))); +#ifdef BASOP_NOGLOB + L_tmp = L_mult( sub_sat( offset, lsf_tmp ), round_fx( L_shl( L_and( L_tmp, 0xFFFF ), 15 ) ) ); +#else + L_tmp = L_mult( sub( offset, lsf_tmp ), round_fx( L_shl( L_and( L_tmp, 0xFFFF ), 15 ) ) ); +#endif L_tmp = L_msu(L_tmp, lsf_tmp, -32768); lsp[i] = round_fx(L_tmp); } diff --git a/lib_com/tec_com.c b/lib_com/tec_com.c index da968995e..70390c3c0 100644 --- a/lib_com/tec_com.c +++ b/lib_com/tec_com.c @@ -335,7 +335,11 @@ static void calcHiTempEnv_Fx( FOR (k=lowSubband; k < highSubband; k++) { - nrg = L_add(nrg,L_shr(pCldfbPow[timeIndex][k], s1)); +#ifdef BASOP_NOGLOB + nrg = L_add_sat( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); +#else + nrg = L_add( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); +#endif } diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 0d0cecb67..7bc52b96e 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -44,7 +44,21 @@ FOR (i = 0; i < N; i+=4) { depack_4_values(cbp+i_mult(shr(i,2),3), val0, val1, val2, val3) - Tmp[i+0] = mult_r(shl(w[i+0],2),val0); +#ifdef BASOP_NOGLOB + Tmp[i + 0] = mult_r( shl_sat( w[i + 0], 2 ), val0 ); + move16(); + en = L_mac_sat( en, val0, Tmp[i + 0] ); + Tmp[i + 1] = mult_r( shl_sat( w[i + 1], 2 ), val1 ); + move16(); + en = L_mac_sat( en, val1, Tmp[i + 1] ); + Tmp[i + 2] = mult_r( shl_sat( w[i + 2], 2 ), val2 ); + move16(); + en = L_mac_sat( en, val2, Tmp[i + 2] ); + Tmp[i + 3] = mult_r( shl_sat( w[i + 3], 2 ), val3 ); + move16(); + en = L_mac_sat( en, val3, Tmp[i + 3] ); +#else + Tmp[i + 0] = mult_r( shl( w[i + 0], 2 ), val0 ); move16(); en = L_mac(en, val0, Tmp[i+0]); Tmp[i+1] = mult_r(shl(w[i+1],2),val1); @@ -56,6 +70,7 @@ Tmp[i+3] = mult_r(shl(w[i+3],2),val3); move16(); en = L_mac(en, val3, Tmp[i+3]); +#endif } return en; @@ -245,7 +260,11 @@ void msvq_enc_fx move16(); FOR (j=1; j Date: Thu, 14 Mar 2024 12:43:18 -0400 Subject: [PATCH 37/42] more saturation fixes --- lib_com/wi_fx.c | 8 +++++++- lib_enc/energy_fx.c | 7 ++++++- lib_enc/pitch_ol2_fx.c | 7 ++++++- lib_enc/swb_bwe_enc_fx.c | 18 +++++++++++++++--- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 35f1d6578..4805532bb 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -2568,9 +2568,15 @@ void DTFS_to_erb_fx( tmp = div_s(fracb,fraca); exp = sub(expb,expa); - L_tmp = L_shl(tmp, add(exp,14)); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( tmp, add( exp, 14 ) ); + + out_fx[i] = round_fx_sat(L_tmp); +#else + L_tmp = L_shl( tmp, add( exp, 14 ) ); out_fx[i] = round_fx(L_tmp); +#endif } } return; diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index 06638aa5e..487aa3412 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -62,8 +62,13 @@ void est_energy_fx( FOR(i = 2; i < BandNum; i++) { Ltmp32 = L_shr(sb_power[i],shr_tmp); - frame_energy2 = L_add(frame_energy2, Ltmp32 ); +#ifdef BASOP_NOGLOB + frame_energy2 = L_add_sat( frame_energy2, Ltmp32 ); + if(i > 6) HB_Power = L_add_sat(HB_Power, Ltmp32 ); +#else + frame_energy2 = L_add( frame_energy2, Ltmp32 ); if(i > 6) HB_Power = L_add(HB_Power, Ltmp32 ); +#endif } frame_energy2 = L_sub(frame_energy2, Ltmp32 ); diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index 91c6df713..08155342d 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -169,8 +169,13 @@ void pitch_ol2_fx( R2 = L_mult(wsp_fr_fx[0], wsp_fr_fx[0]); FOR (j = 1; j < L_SUBFR; j++) { - R1 = L_mac(R1, pt_wsp_fx[j], pt_wsp_fx[j]); +#ifdef BASOP_NOGLOB + R1 = L_mac_sat( R1, pt_wsp_fx[j], pt_wsp_fx[j] ); + R2 = L_mac_sat(R2, wsp_fr_fx[j], wsp_fr_fx[j]); +#else + R1 = L_mac( R1, pt_wsp_fx[j], pt_wsp_fx[j] ); R2 = L_mac(R2, wsp_fr_fx[j], wsp_fr_fx[j]); +#endif } /* *voicing_fr = cor_max * inv_sqrt(enr_wsp * enr_old) */ diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 5a1c26f0e..5ad0b1749 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -934,7 +934,11 @@ static void freq_weights_fx( { exp = norm_s(tmp); tmp = div_s(shl(1,sub(14,exp)), tmp); /*(21-exp) */ - tmp = shl(tmp, sub(exp, 6)); /*Q15 */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( tmp, sub( exp, 6 ) ); /*Q15 */ +#else + tmp = shl( tmp, sub( exp, 6 ) ); /*Q15 */ +#endif } ELSE { @@ -1633,7 +1637,11 @@ static void calculate_Tonality_fx( l_shift = norm_s(max); FOR( n_coeff=0; n_coeff Date: Thu, 14 Mar 2024 14:30:37 -0400 Subject: [PATCH 38/42] fixes more saturations --- lib_com/wi_fx.c | 13 ++++++++++--- lib_enc/hf_cod_amrwb_fx.c | 2 +- lib_enc/igf_enc_fx.c | 6 +++++- lib_enc/set_impulse_fx.c | 3 ++- lib_enc/swb_tbe_enc_fx.c | 15 ++++++++++++++- lib_enc/voiced_enc_fx.c | 6 +++++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 4805532bb..d6386fa05 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -442,11 +442,18 @@ Word16 DTFS_alignment_full_fx( /* Calculating the expected alignment shift */ Eshift = mult_r(ph_offset_fx, shl(X2_DTFS_fx.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */ find_rem((Word16)L_FRAME, shr(add(X2_DTFS_fx.lag_fx, X1_DTFS_fx.lag_fx), 1), &temp); - temp = add(shl(temp, 7), Eshift); /* Q7 */ - +#ifdef BASOP_NOGLOB + temp = add_sat( shl( temp, 7 ), Eshift ); /* Q7 */ +#else + temp = add( shl( temp, 7 ), Eshift ); /* Q7 */ +#endif IF (temp<0) { - temp = add(temp, shl(X1_DTFS_fx.lag_fx, 7)); /* Q7 */ +#ifdef BASOP_NOGLOB + temp = add_sat( temp, shl_sat( X1_DTFS_fx.lag_fx, 7 ) ); /* Q7 */ +#else + temp = add( temp, shl( X1_DTFS_fx.lag_fx, 7 ) ); /* Q7 */ +#endif } find_rem(temp, shl(X1_DTFS_fx.lag_fx, 7), &Eshift); /* Q7 */ Eshift=shl(shr(Eshift,7),1); /* Q1 but integer */ diff --git a/lib_enc/hf_cod_amrwb_fx.c b/lib_enc/hf_cod_amrwb_fx.c index ac65954d2..20a1296f9 100644 --- a/lib_enc/hf_cod_amrwb_fx.c +++ b/lib_enc/hf_cod_amrwb_fx.c @@ -193,7 +193,7 @@ void hf_cod_fx( L_tmp = L_mult(ener_hf_fx, HF_calc_gain_fx); /*30-q1+q2 */ q2 = sub(q1, q2); /*30-q2 */ #ifdef BASOP_NOGLOB - HF_calc_gain_fx = round_fx_o(Isqrt(L_shl(L_tmp, sub(q2, 20))), &Overflow); /*Q10 */ + HF_calc_gain_fx = round_fx_o(Isqrt(L_shl_sat(L_tmp, sub(q2, 20))), &Overflow); /*Q10 */ #else /* BASOP_NOGLOB */ HF_calc_gain_fx = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 20)))); /*Q10 */ #endif diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 857e08038..6415ba476 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -253,7 +253,11 @@ static void IGF_CalculateEnvelope(const IGF_ENC_INSTANCE_HANDLE hInstanc zeroNrg = 1; move16(); } - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyR[sfb]), +#ifdef BASOP_NOGLOB + BASOP_Util_Divide_MantExp( round_fx_sat( sfbEnergyR[sfb] ), +#else + BASOP_Util_Divide_MantExp( round_fx( sfbEnergyR[sfb] ), +#endif sfbEnergyR_exp[sfb], width, 15, diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index ad603ae7e..fdc92195d 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -161,11 +161,12 @@ void set_impulse_fx( #ifdef BASOP_NOGLOB Lrr = L_mac_o(Lrr, gh_fx[0], gh_fx[0], &Overflow); Ldd = L_mac_o(Ldd, gh_fx[0], xn_fx[0], &Overflow); + dd_fx[i] = round_fx_sat( Ldd ); #else /* BASOP_NOGLOB */ Lrr = L_mac(Lrr, gh_fx[0], gh_fx[0]); Ldd = L_mac(Ldd, gh_fx[0], xn_fx[0]); + dd_fx[i] = round_fx( Ldd ); #endif - dd_fx[i] = round_fx(Ldd); rr_fx[i] = L_max(Lrr, 1); move32(); /* move rr and dd into rr[i] and dd[i] */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 997154a61..6648f4ed1 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -2385,18 +2385,31 @@ static void EstimateSHBGainShape_fx( FOR( k = 0; k < length / 2; k++ ) { sig = mult_r( oriSHB[j + k], subwin[2 * k + 2] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ +#ifdef BASOP_NOGLOB + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + k], subwin[2 * k + 2] ); /* Q_synSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ +#else + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ sig = mult_r( synSHB[j + k], subwin[2 * k + 2] ); /* Q_synSHB */ synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ +#endif } FOR( k = length / 2; k < length; k++ ) { sig = oriSHB[j + k]; move16(); +#ifdef BASOP_NOGLOB + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = synSHB[j + k]; + move16(); + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ +#else oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ sig = synSHB[j + k]; move16(); synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ +#endif } } ELSE diff --git a/lib_enc/voiced_enc_fx.c b/lib_enc/voiced_enc_fx.c index 3281637ee..fa9c51bd5 100644 --- a/lib_enc/voiced_enc_fx.c +++ b/lib_enc/voiced_enc_fx.c @@ -515,7 +515,11 @@ ivas_error ppp_voiced_encoder_fx( tmp = div_s(fracb,fraca); exp = sub(expb,expa); - sp_enratio_fx = L_shl(tmp, exp); /* Q15 */ +#ifdef BASOP_NOGLOB + sp_enratio_fx = L_shl_sat( tmp, exp ); /* Q15 */ +#else + sp_enratio_fx = L_shl( tmp, exp ); /* Q15 */ +#endif } } ELSE -- GitLab From 47e007c749f340e172766454f474db8426e776a5 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 14 Mar 2024 15:13:04 -0400 Subject: [PATCH 39/42] fixes more saturations --- lib_dec/evs_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 33a4dd9b4..524bdc2a6 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1374,7 +1374,7 @@ ivas_error evs_dec_fx( FOR (i = delta; i < tmps; i++) { #ifdef BASOP_NOGLOB - output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); + output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); #else output_sp[i] = msu_r( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); #endif -- GitLab From c6a8959c2a253647916ec4190ec061cbd240ee22 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 18 Mar 2024 09:42:24 -0400 Subject: [PATCH 40/42] more saturation fixes --- lib_com/swb_bwe_com_fx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index a73fc9c21..8a3173d00 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2993,8 +2993,11 @@ void hq_generic_decoding_fx( tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ - +#ifdef BASOP_NOGLOB + tmp3_fx = shr_sat( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ +#else + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ +#endif if (LT_16(tmp3_fx, 307)) { tmp3_fx = 307; -- GitLab From 61a6b182f16c4885e1b5a5264718fbd127367589 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 18 Mar 2024 13:02:40 -0400 Subject: [PATCH 41/42] complete an interrupted commit --- lib_com/swb_bwe_com_fx.c | 138 +++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 64 deletions(-) diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 422285711..447129576 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -732,7 +732,7 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ return L_temp; } #ifdef IVAS_FLOAT_FIXED -Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ const Word32 *sp, /* i : input signal */ const Word16 exp_sp, /* i : Exp of inp signal */ const Word16 N /* i : signal length */ @@ -741,6 +741,7 @@ Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ Word16 i, j; Word32 L_ener, L_ener_tot, L_temp; Word32 tmp1, tmp2; + Word16 sign = 0; const Word32 *ptr; Word16 exp2, tmp_exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -762,61 +763,33 @@ Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* Divide Frame Length by 32 */ FOR(j = shr(N, 5); j > 0; j--) { -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - Word16 tmp = mult_ro( (Word16) *ptr++, 8192, &Overflow ); /* Divide by 4 */ -#else - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ -#endif - L_ener = L_mult0( tmp, tmp ); + Word32 tmp = *ptr++; /* Divide by 4 */ + L_ener = Mpy_32_32( tmp, tmp ); /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ FOR(i = 1; i < 32; i++) { - tmp1 = L_mls_o(*ptr++, 8192, &Overflow); /* Divide by 4 */ + tmp1 = *ptr++; /* Divide by 4 */ L_ener = Madd_32_32(L_ener, tmp1, tmp1); } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener = L_shr_o(L_ener, exp2, &Overflow); - L_temp = L_add_o(L_ener_tot, L_ener, &Overflow); -#else - L_ener = L_shr(L_ener, exp2); L_temp = L_add(L_ener_tot, L_ener); -#endif - IF(Overflow != 0) - { - L_ener_tot = L_shr(L_ener_tot, 1); - L_ener = L_shr(L_ener, 1); - exp2 = add(exp2, 1); - /* this is required, do not remove */ - Overflow = 0; - move16(); - } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener_tot = L_add_o(L_ener_tot, L_ener, &Overflow); -#else + L_ener_tot = L_add(L_ener_tot, L_ener); -#endif } -#ifdef BASOP_NOGLOB - L_ener = (L_abs(L_sub_o(sp[1], sp[0], &Overflow))); -#else - L_ener = L_deposit_l(abs_s(sub(sp[1], sp[0]))); -#endif + L_ener = L_abs(L_sub(sp[1], sp[0])); + FOR(i = 2; i < N; i++) { /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ -#ifdef BASOP_NOGLOB - tmp1 = L_sub_o(sp[i], sp[i - 1], &Overflow); - tmp2 = L_sub_o(sp[i - 1], sp[i - 2], &Overflow); -#else - tmp1 = sub(sp[i], sp[i - 1]); - tmp2 = sub(sp[i - 1], sp[i - 2]); -#endif - tmp2 = mult(tmp1, tmp2); - tmp1 = abs_s(tmp1); + tmp1 = L_sub(sp[i], sp[i - 1]); + tmp2 = L_sub(sp[i - 1], sp[i - 2]); + + tmp2 = Mpy_32_32(tmp1, tmp2); + tmp1 = L_abs(tmp1); /* to Get either 0 or -1 in 'tmp2' */ - tmp2 = shr(tmp2, 15); + tmp2 = L_shr(tmp2, 31); + sign = extract_l(L_shl(tmp2, Q15)); /* this allows this code */ - L_ener = L_msu0(L_ener, tmp2, tmp1); + L_ener = Msub_32_16(L_ener, tmp1, sign); /* instead of this one */ /* test(); */ /* if (tmp2 < 0) */ @@ -826,30 +799,24 @@ Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* it saves one op */ } - tmp_exp = norm_l(L_ener_tot); - L_temp = L_shl(L_ener_tot, tmp_exp); - tmp1 = sub(add(31 + 4, exp2), add(tmp_exp, shl(exp_sp, 1))); - L_temp = Isqrt_lc(L_temp, &tmp_exp); + L_temp = L_ener_tot; + tmp_exp = sub(Q31, sub(shl(exp_sp, 1), Q31)); + L_temp = Sqrt32(L_temp, &tmp_exp); + L_temp = L_shl(L_temp, sub(exp_sp, sub(Q31, tmp_exp))); /* *tilt_flt = (float)(r1/sqrt(r0)); */ - exp2 = norm_l(L_ener); -#ifdef BASOP_NOGLOB - L_temp = Mult_32_16( L_temp, round_fx( L_shl_sat( L_ener, exp2 ) ) ); -#else - L_temp = Mult_32_16( L_temp, round_fx( L_shl( L_ener, exp2 ) ) ); -#endif - exp2 = sub(exp2, tmp_exp); - exp2 = add(exp2, exp_sp); - - /* Put in Q24 */ -#ifdef BASOP_NOGLOB - L_temp = L_shr_sat( L_temp, sub( exp2, 24 ) ); -#else - L_temp = L_shr( L_temp, sub( exp2, 24 ) ); -#endif + L_temp = L_deposit_l(BASOP_Util_Divide3232_Scale(L_ener, L_temp, &exp2)); + IF (GT_16(sub(exp2, 4) , norm_l(L_temp))) + { + L_temp = MAX_16; + } + ELSE + { + L_temp = L_shl(L_temp, sub(exp2, 4)); // Output is expected in Q11 + } BASOP_SATURATE_WARNING_ON_EVS - return L_temp; + return extract_l(L_temp); } #endif @@ -3166,4 +3133,47 @@ void hq_generic_decoding_fx( FOR(; n_freq < fb_bwe_subband[DIM_FB]; n_freq++) { L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1 \ No newline at end of file + coeff_out_fx[n_freq] = L_shr(L_tmp, 1); + move32();/*12 */ + } + } + } + + return; +} + + + +/*-------------------------------------------------------------------* + * save_old_syn() + * + * Save and delay the ACELP core synthesis signal by + * DELAY_FD_BWE_ENC_xxkx to be used by SWB BWE + *-------------------------------------------------------------------*/ + +void save_old_syn_fx( + const Word16 L_frame, /* i : frame length */ + const Word16 syn[], /* i : ACELP synthesis */ + Word16 old_syn[], /* o : old synthesis buffer */ + Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ + const Word16 preemph_fac, /* i : preemphasis factor */ + Word16 *mem_deemph /* i/o: deemphasis filter memory */ +) +{ + Word16 tmps; + + tmps = NS2SA(16000, DELAY_FD_BWE_ENC_16k_NS); + move16(); + if (EQ_16(L_frame, L_FRAME)) + { + tmps = NS2SA(12800, DELAY_FD_BWE_ENC_12k8_NS); + move16(); + } + Copy(old_syn_mem, old_syn, tmps); + Copy(syn, old_syn + tmps, L_frame - tmps); + Copy(syn + L_frame - tmps, old_syn_mem, tmps); + + deemph_fx(old_syn, preemph_fac, L_frame, mem_deemph); + + return; +} -- GitLab From 7fdc6b310679c4515dcd2cfd60308051381c669f Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 19 Mar 2024 09:23:49 -0400 Subject: [PATCH 42/42] some more saturation fixes --- lib_com/fft_fx_evs.c | 14 ++++++++++---- lib_com/tools_fx.c | 5 +++++ lib_dec/er_dec_tcx_fx.c | 6 +++++- lib_dec/voiced_dec_fx.c | 7 ++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index cedad05f4..db7e290dc 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -1183,13 +1183,19 @@ static void fft5_shift4_16fx( /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ L_tmp = Mult_32_16(KP951056516_16FX,Ts); L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Tt); - T2 = round_fx(L_tmp); - +#ifdef BASOP_NOGLOB + T2 = round_fx_sat( L_tmp ); +#else + T2 = round_fx( L_tmp ); +#endif /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ L_tmp = Mult_32_16(KP951056516_16FX,Tt); L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Ts); - T3 = round_fx(L_tmp); - +#ifdef BASOP_NOGLOB + T3 = round_fx_sat( L_tmp ); +#else + T3 = round_fx( L_tmp ); +#endif #ifdef BASOP_NOGLOB T6 = sub_sat(To, shr(Tp, 2)); T4 = add_sat(Tn, T6); diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 5a621af50..23b76555d 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -2050,8 +2050,13 @@ void pz_filter_sp_fx ( Lacc = L_deposit_l(0); FOR ( j = PNR - 1; j >= 0; j-- ) +#ifdef BASOP_NOGLOB + Lacc = L_mac_sat( Lacc, buf[j], b[j + 1] ); + Lacc = L_mac_sat( Lacc, s_mem, b[0] ); +#else Lacc = L_mac( Lacc, buf[j], b[j + 1] ); Lacc = L_mac( Lacc, s_mem, b[0] ); +#endif /* Lacc in Q(1+Qc+Qn-Qa)*/ FOR ( j = s_max(PDR, PNR ) - 1; j > 0; j-- ) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 12be4932c..9c9888f88 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -855,7 +855,11 @@ void con_tcx( tmp_e = norm_l(L_tmp); L_tmp = L_shl(L_tmp,tmp_e); gain_inov_e = add(sub(gain_inov_e,tmp_e),31-29);/*->Q31*/ - gain_inov = round_fx(L_tmp);/*Q15,gain_inov_e*/ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ +#else + gain_inov = round_fx( L_tmp ); /*Q15,gain_inov_e*/ +#endif } st->Mode2_lp_gainp = L_shr(L_deposit_h(alpha/*Q14*/)/*Q14+16*/,1);/*Q29*/ diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index f06c12985..f0c5d9305 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -323,8 +323,13 @@ ivas_error ppp_voiced_decoder_fx( /* temp32_fx = (Word32)divide_dp((Word40)819200,(Word40)L_shl((Word32)CURRP_Q_D_FX->lag_fx,6),-23,1);//Q6 */ exp = norm_s(CURRP_Q_D_FX->lag_fx); tmp = div_s(shl(1,sub(14,exp)),CURRP_Q_D_FX->lag_fx);/*29-exp */ - L_tmp =L_shl(L_mult0(tmp,12800),exp - 7); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult0( tmp, 12800 ), exp - 7 ); + temp32_fx = round_fx_sat( L_tmp ); +#else + L_tmp = L_shl( L_mult0( tmp, 12800 ), exp - 7 ); temp32_fx = round_fx(L_tmp); +#endif diff = round_fx(L_shl(temp32_fx,16-6));/*Q0 */ CURRP_Q_D_FX->nH_fx = find_rem(upper_cut_off_freq,diff,&rem_fx);/*Q0 */ -- GitLab