From a4a26f8cb09e240a365b8d4b474ed2cc173bbe73 Mon Sep 17 00:00:00 2001 From: Hiromi Sekine Date: Fri, 25 Apr 2025 09:43:33 +0900 Subject: [PATCH 01/54] =?UTF-8?q?Enhanced=20accuracy=20by=20renormalizatio?= =?UTF-8?q?n=20in=20the=20frequency=20domain.=E3=80=80=20Added=20WMOPS=20c?= =?UTF-8?q?ounter=20#estimate=5Fitd=5Fwnd=5Ffft=5Ffx,#calc=5Fpoc=5Ffx,#fin?= =?UTF-8?q?d=5Fpoc=5Fpeak=5Ffx,#estimate=5Fitd=5Ffx,#weighted=5Fave=5Ffx,#?= =?UTF-8?q?calc=5Fenergy=5Ffx,#adapt=5Fgain=5Ffx,#create=5FM=5Fsignal=5Ffx?= =?UTF-8?q?,#stereo=5Fdmx=5Fevs=5Fenc=5Ffx.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib_com/options.h | 12 +-- lib_enc/ivas_stereo_dmx_evs_fx.c | 147 +++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2f1e82de8..b297f0d1a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -53,12 +53,12 @@ #define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ -/*#define WMOPS*/ /* Activate complexity and memory counters */ +#define WMOPS /* Activate complexity and memory counters */ #ifdef WMOPS -/*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ -/*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ -/*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ -/*#define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ +#define WMOPS_PER_FRAME /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ +#define WMOPS_DETAIL /* Output detailed complexity printout for every function. Increases runtime overhead */ +#define WMOPS_WC_FRAME_ANALYSIS /* Output detailed complexity analysis for the worst-case frame */ +/*define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ #endif /* #################### End DEBUGGING switches ############################ */ @@ -94,6 +94,8 @@ #define FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic_STAGE2 /*FhG: reduces WMOPS*/ #define FIX_1481_HARDCODE_DIV /* FhG: hardcode division results in stereo_dmx_evs_init_encoder_fx() */ #define FIX_1486_IND_SHB_RES /* VA: Fix for issue 1486: align the usage of IND_SHB_RES_GS indices with float code */ +#define FIX_1511_RENORM +#define FIX_1511_WMOPS #define TEST_HR #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ diff --git a/lib_enc/ivas_stereo_dmx_evs_fx.c b/lib_enc/ivas_stereo_dmx_evs_fx.c index 13ecbba00..21f5f48aa 100644 --- a/lib_enc/ivas_stereo_dmx_evs_fx.c +++ b/lib_enc/ivas_stereo_dmx_evs_fx.c @@ -223,6 +223,10 @@ void estimate_itd_wnd_fft_fx( Word16 step, bias; Word16 rshift; +#ifdef FIX_1511_WMOPS + push_wmops("estimate_itd_wnd_fft_fx"); +#endif + n0 = shr( input_frame, 1 ); IF( EQ_16( input_frame, L_FRAME16k ) ) { @@ -269,6 +273,10 @@ void estimate_itd_wnd_fft_fx( speci[n0] = 0; move32(); +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return; } @@ -322,6 +330,10 @@ static void calc_poc_fx( Word64 W_tmp; Word16 W_tmp_q; +#ifdef FIX_1511_WMOPS + push_wmops("calc_poc_fx"); +#endif + /* Initialization */ // iN = 1.0f / (float) input_frame; s = hPOC->sin_fx; @@ -412,6 +424,23 @@ static void calc_poc_fx( Rr = L_add( L_add( specRr[i], Mpy_32_32_r( specLr[i], eps_cos ) ), Mpy_32_32_r( specLi[i], eps_sin ) ); Ri = L_add( L_sub( specRi[i], Mpy_32_32_r( specLr[i], eps_sin ) ), Mpy_32_32_r( specLi[i], eps_cos ) ); +#ifdef FIX_1511_RENORM + { + Word32 TH1 = 65536 * 512; + Word16 SHIFT1 = 4; + IF((LT_32(L_abs(Lr), TH1)) && + (LT_32(L_abs(Li), TH1)) && + (LT_32(L_abs(Rr), TH1)) && + (LT_32(L_abs(Ri), TH1))) + { + Lr = L_shl(Lr, SHIFT1); + Li = L_shl(Li, SHIFT1); + Rr = L_shl(Rr, SHIFT1); + Ri = L_shl(Ri, SHIFT1); + } + } +#endif + specPOr[i] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); specPOi[i] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e @@ -424,6 +453,23 @@ static void calc_poc_fx( Rr = L_add( L_sub( specRr[j], Mpy_32_32_r( specLr[j], eps_cos ) ), Mpy_32_32_r( specLi[j], eps_sin ) ); Ri = L_sub( L_sub( specRi[j], Mpy_32_32_r( specLr[j], eps_sin ) ), Mpy_32_32_r( specLi[j], eps_cos ) ); +#ifdef FIX_1511_RENORM + { + Word32 TH1 = 65536 * 512; + Word16 SHIFT1 = 4; + IF((LT_32(L_abs(Lr), TH1)) && + (LT_32(L_abs(Li), TH1)) && + (LT_32(L_abs(Rr), TH1)) && + (LT_32(L_abs(Ri), TH1))) + { + Lr = L_shl(Lr, SHIFT1); + Li = L_shl(Li, SHIFT1); + Rr = L_shl(Rr, SHIFT1); + Ri = L_shl(Ri, SHIFT1); + } + } +#endif + specPOr[j] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); specPOi[j] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e @@ -444,6 +490,24 @@ static void calc_poc_fx( Li = L_add( L_sub( specLi[i], Mpy_32_32_r( specRr[i], eps_sin ) ), Mpy_32_32_r( specRi[i], eps_cos ) ); Rr = L_add( L_add( specRr[i], Mpy_32_32_r( specLr[i], eps_cos ) ), Mpy_32_32_r( specLi[i], eps_sin ) ); Ri = L_add( L_sub( specRi[i], Mpy_32_32_r( specLr[i], eps_sin ) ), Mpy_32_32_r( specLi[i], eps_cos ) ); + +#ifdef FIX_1511_RENORM + { + Word32 TH1 = 65536 * 512; + Word16 SHIFT1 = 4; + IF((LT_32(L_abs(Lr), TH1)) && + (LT_32(L_abs(Li), TH1)) && + (LT_32(L_abs(Rr), TH1)) && + (LT_32(L_abs(Ri), TH1))) + { + Lr = L_shl(Lr, SHIFT1); + Li = L_shl(Li, SHIFT1); + Rr = L_shl(Rr, SHIFT1); + Ri = L_shl(Ri, SHIFT1); + } + } +#endif + specPOr[i] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); specPOi[i] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e @@ -454,6 +518,24 @@ static void calc_poc_fx( Li = L_sub( L_sub( specLi[j], Mpy_32_32_r( specRr[j], eps_sin ) ), Mpy_32_32_r( specRi[j], eps_cos ) ); Rr = L_add( L_sub( specRr[j], Mpy_32_32_r( specLr[j], eps_cos ) ), Mpy_32_32_r( specLi[j], eps_sin ) ); Ri = L_sub( L_sub( specRi[j], Mpy_32_32_r( specLr[j], eps_sin ) ), Mpy_32_32_r( specLi[j], eps_cos ) ); + +#ifdef FIX_1511_RENORM + { + Word32 TH1 = 65536 * 512; + Word16 SHIFT1 = 4; + IF((LT_32(L_abs(Lr), TH1)) && + (LT_32(L_abs(Li), TH1)) && + (LT_32(L_abs(Rr), TH1)) && + (LT_32(L_abs(Ri), TH1))) + { + Lr = L_shl(Lr, SHIFT1); + Li = L_shl(Li, SHIFT1); + Rr = L_shl(Rr, SHIFT1); + Ri = L_shl(Ri, SHIFT1); + } + } +#endif + specPOr[j] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); specPOi[j] = L_sub( Mpy_32_32_r( Lr, Ri ), Mpy_32_32_r( Li, Rr ) ); // 2*spec_e @@ -1125,6 +1207,10 @@ static void calc_poc_fx( } } +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return; } @@ -1144,6 +1230,11 @@ static Word32 find_poc_peak_fx( Word16 itd_cand[CPE_CHANNELS], i, n, cnt[CPE_CHANNELS], Lh, peak_range, *on, *itdLR, prev_off[CPE_CHANNELS], eps_fx; Word32 Q_fx[CPE_CHANNELS], aQ_fx[CPE_CHANNELS], cQ_fx[CPE_CHANNELS], width_fx, *peak_width_fx, *peakQ_fx, cconfidence_fx, *P_fx, tmpf_fx, eps2_fx; Word16 tmpf_e = 0, eps2_e = 0, Q_e[CPE_CHANNELS], eps_e = 15, peakQ_e[CPE_CHANNELS]; + +#ifdef FIX_1511_WMOPS + push_wmops("find_poc_peak_fx"); +#endif + move16(); move16(); move16(); @@ -1434,6 +1525,10 @@ static Word32 find_poc_peak_fx( hPOC->confidence_fx = L_add( cconfidence_var1, L_shl( cconfidence_var2, 1 ) ); // Q31 move32(); +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return hPOC->confidence_fx; } @@ -1459,6 +1554,10 @@ static ivas_error estimate_itd_fx( Word16 rfft_coef_step; ivas_error error; +#ifdef FIX_1511_WMOPS + push_wmops("estimate_itd_fx"); +#endif + error = IVAS_ERR_OK; move32(); @@ -1515,6 +1614,10 @@ static ivas_error estimate_itd_fx( *corr = round_fx( find_poc_peak_fx( hPOC, itd, input_frame, STEREO_DMX_EVS_POC_W_FORGETTING_FX ) ); move16(); +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return error; } @@ -1535,6 +1638,11 @@ static void weighted_ave_fx( { Word16 i, len; Word32 gain_tmp_fx = 0, gain_sub_fx; + +#ifdef FIX_1511_WMOPS + push_wmops("weighted_ave_fx"); +#endif + move32(); len = shr( input_frame, 4 ); gain_sub_fx = L_sub( gain_fx, old_gain_fx ); @@ -1550,6 +1658,10 @@ static void weighted_ave_fx( move32(); } +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return; } /*-------------------------------------------------------------------* @@ -1569,6 +1681,11 @@ static void calc_energy_fx( Word32 E_32_fx, wnd_fx, wnd_diff_fx; Word16 i, adaptlen; Word64 E_fx; + +#ifdef FIX_1511_WMOPS + push_wmops("calc_energy_fx"); +#endif + /* Initialization */ E_fx = 0; move32(); @@ -1630,6 +1747,11 @@ static void calc_energy_fx( // *energy = *energy * ratio_float + ( E / (float) input_frame ) * ( 1.0f - ratio_float ); *energy_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( *energy_fx, ratio_float_fx ), *energy_fx_e, Mpy_32_32( temp32, L_sub( MAX_32, ratio_float_fx ) ), sub( 31, q_temp32 ), energy_fx_e ); move32(); + +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return; } @@ -1650,6 +1772,10 @@ static void adapt_gain_fx( Word16 i, len; Word32 gain_tmp_fx, gain_sub_fx; +#ifdef FIX_1511_WMOPS + push_wmops("adapt_gain_fx"); +#endif + len = shr( input_frame, 4 ); // gain_sub = gain - old_gain; gain_sub_fx = L_sub( gain_fx, old_gain_fx ); // Q31 @@ -1668,6 +1794,10 @@ static void adapt_gain_fx( move32(); } +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return; } @@ -1696,6 +1826,11 @@ static void create_M_signal_fx( Word32 temp32_1, temp32_2; Word16 temp_e; Word16 temp_e_1, temp_e_2; + +#ifdef FIX_1511_WMOPS + push_wmops("create_M_signal_fx"); +#endif + /* Initialization */ eps_fx = 1024; // 1024.0f in Q0 move32(); @@ -1761,6 +1896,10 @@ static void create_M_signal_fx( w_prev_fx[2] = amp_mod_fx[1]; move32(); +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return; } @@ -1799,6 +1938,10 @@ void stereo_dmx_evs_enc_fx( Word64 W_tmp; Word16 W_tmp_q; +#ifdef FIX_1511_WMOPS + push_wmops("stereo_dmx_evs_enc_fx"); +#endif + if ( is_binaural ) { /* use of is_binaural flag is to be considered */ @@ -2150,6 +2293,10 @@ void stereo_dmx_evs_enc_fx( Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); // Q26->Q15 +#ifdef FIX_1511_WMOPS + pop_wmops(); +#endif + return; } -- GitLab From 9aa816c470adf5b4a65d64f6c13edb2637f67f78 Mon Sep 17 00:00:00 2001 From: Arnaud Lefort Date: Mon, 12 May 2025 15:13:34 +0200 Subject: [PATCH 02/54] Fix 1511 - POC renorm cleaned and tuned. --- lib_com/options.h | 3 +- lib_enc/ivas_stereo_dmx_evs_fx.c | 189 ++++++++++--------------------- 2 files changed, 58 insertions(+), 134 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 1ca29ab76..fb32b2240 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -95,8 +95,7 @@ #define FIX_1481_HARDCODE_DIV /* FhG: hardcode division results in stereo_dmx_evs_init_encoder_fx() */ #define VEC_ARITH_OPT_v1 #define FIX_1486_IND_SHB_RES /* VA: Fix for issue 1486: align the usage of IND_SHB_RES_GS indices with float code */ -#define FIX_1511_RENORM -#define FIX_1511_WMOPS +#define FIX_1511_POC_RENORM /* NTT: Fix for issue 1511: Renorm for POC. */ #define TEST_HR #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ diff --git a/lib_enc/ivas_stereo_dmx_evs_fx.c b/lib_enc/ivas_stereo_dmx_evs_fx.c index 21f5f48aa..36315d2ed 100644 --- a/lib_enc/ivas_stereo_dmx_evs_fx.c +++ b/lib_enc/ivas_stereo_dmx_evs_fx.c @@ -98,6 +98,11 @@ #define STEREO_DMX_EVS_TRNS_EGY_FORGETTING_Q15 24576 +#ifdef FIX_1511_POC_RENORM +#define STEREO_DMX_EVS_POC_RENORM_TH 33554432 // 65536 << 9 +#define STEREO_DMX_EVS_POC_RENORM_SHIFT 3 +#endif + const Word32 ipd_ff_Q31[STEREO_DMX_EVS_NB_SUBBAND_MAX] = { 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, 2027355264, @@ -223,10 +228,6 @@ void estimate_itd_wnd_fft_fx( Word16 step, bias; Word16 rshift; -#ifdef FIX_1511_WMOPS - push_wmops("estimate_itd_wnd_fft_fx"); -#endif - n0 = shr( input_frame, 1 ); IF( EQ_16( input_frame, L_FRAME16k ) ) { @@ -273,10 +274,6 @@ void estimate_itd_wnd_fft_fx( speci[n0] = 0; move32(); -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return; } @@ -330,10 +327,6 @@ static void calc_poc_fx( Word64 W_tmp; Word16 W_tmp_q; -#ifdef FIX_1511_WMOPS - push_wmops("calc_poc_fx"); -#endif - /* Initialization */ // iN = 1.0f / (float) input_frame; s = hPOC->sin_fx; @@ -424,22 +417,18 @@ static void calc_poc_fx( Rr = L_add( L_add( specRr[i], Mpy_32_32_r( specLr[i], eps_cos ) ), Mpy_32_32_r( specLi[i], eps_sin ) ); Ri = L_add( L_sub( specRi[i], Mpy_32_32_r( specLr[i], eps_sin ) ), Mpy_32_32_r( specLi[i], eps_cos ) ); -#ifdef FIX_1511_RENORM - { - Word32 TH1 = 65536 * 512; - Word16 SHIFT1 = 4; - IF((LT_32(L_abs(Lr), TH1)) && - (LT_32(L_abs(Li), TH1)) && - (LT_32(L_abs(Rr), TH1)) && - (LT_32(L_abs(Ri), TH1))) - { - Lr = L_shl(Lr, SHIFT1); - Li = L_shl(Li, SHIFT1); - Rr = L_shl(Rr, SHIFT1); - Ri = L_shl(Ri, SHIFT1); - } - } -#endif +#ifdef FIX_1511_POC_RENORM + IF( ( LT_32( L_abs( Lr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Li ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Rr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Ri ), STEREO_DMX_EVS_POC_RENORM_TH ) ) ) + { + Lr = L_shl( Lr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Li = L_shl( Li, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Rr = L_shl( Rr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Ri = L_shl( Ri, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + } +#endif specPOr[i] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); @@ -453,22 +442,18 @@ static void calc_poc_fx( Rr = L_add( L_sub( specRr[j], Mpy_32_32_r( specLr[j], eps_cos ) ), Mpy_32_32_r( specLi[j], eps_sin ) ); Ri = L_sub( L_sub( specRi[j], Mpy_32_32_r( specLr[j], eps_sin ) ), Mpy_32_32_r( specLi[j], eps_cos ) ); -#ifdef FIX_1511_RENORM - { - Word32 TH1 = 65536 * 512; - Word16 SHIFT1 = 4; - IF((LT_32(L_abs(Lr), TH1)) && - (LT_32(L_abs(Li), TH1)) && - (LT_32(L_abs(Rr), TH1)) && - (LT_32(L_abs(Ri), TH1))) - { - Lr = L_shl(Lr, SHIFT1); - Li = L_shl(Li, SHIFT1); - Rr = L_shl(Rr, SHIFT1); - Ri = L_shl(Ri, SHIFT1); - } - } -#endif +#ifdef FIX_1511_POC_RENORM + IF( ( LT_32( L_abs( Lr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Li ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Rr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Ri ), STEREO_DMX_EVS_POC_RENORM_TH ) ) ) + { + Lr = L_shl( Lr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Li = L_shl( Li, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Rr = L_shl( Rr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Ri = L_shl( Ri, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + } +#endif specPOr[j] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); @@ -491,22 +476,18 @@ static void calc_poc_fx( Rr = L_add( L_add( specRr[i], Mpy_32_32_r( specLr[i], eps_cos ) ), Mpy_32_32_r( specLi[i], eps_sin ) ); Ri = L_add( L_sub( specRi[i], Mpy_32_32_r( specLr[i], eps_sin ) ), Mpy_32_32_r( specLi[i], eps_cos ) ); -#ifdef FIX_1511_RENORM - { - Word32 TH1 = 65536 * 512; - Word16 SHIFT1 = 4; - IF((LT_32(L_abs(Lr), TH1)) && - (LT_32(L_abs(Li), TH1)) && - (LT_32(L_abs(Rr), TH1)) && - (LT_32(L_abs(Ri), TH1))) - { - Lr = L_shl(Lr, SHIFT1); - Li = L_shl(Li, SHIFT1); - Rr = L_shl(Rr, SHIFT1); - Ri = L_shl(Ri, SHIFT1); - } - } -#endif +#ifdef FIX_1511_POC_RENORM + IF( ( LT_32( L_abs( Lr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Li ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Rr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Ri ), STEREO_DMX_EVS_POC_RENORM_TH ) ) ) + { + Lr = L_shl( Lr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Li = L_shl( Li, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Rr = L_shl( Rr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Ri = L_shl( Ri, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + } +#endif specPOr[i] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); @@ -519,22 +500,18 @@ static void calc_poc_fx( Rr = L_add( L_sub( specRr[j], Mpy_32_32_r( specLr[j], eps_cos ) ), Mpy_32_32_r( specLi[j], eps_sin ) ); Ri = L_sub( L_sub( specRi[j], Mpy_32_32_r( specLr[j], eps_sin ) ), Mpy_32_32_r( specLi[j], eps_cos ) ); -#ifdef FIX_1511_RENORM - { - Word32 TH1 = 65536 * 512; - Word16 SHIFT1 = 4; - IF((LT_32(L_abs(Lr), TH1)) && - (LT_32(L_abs(Li), TH1)) && - (LT_32(L_abs(Rr), TH1)) && - (LT_32(L_abs(Ri), TH1))) - { - Lr = L_shl(Lr, SHIFT1); - Li = L_shl(Li, SHIFT1); - Rr = L_shl(Rr, SHIFT1); - Ri = L_shl(Ri, SHIFT1); - } - } -#endif +#ifdef FIX_1511_POC_RENORM + IF( ( LT_32( L_abs( Lr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Li ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Rr ), STEREO_DMX_EVS_POC_RENORM_TH ) ) && + ( LT_32( L_abs( Ri ), STEREO_DMX_EVS_POC_RENORM_TH ) ) ) + { + Lr = L_shl( Lr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Li = L_shl( Li, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Rr = L_shl( Rr, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + Ri = L_shl( Ri, STEREO_DMX_EVS_POC_RENORM_SHIFT ); + } +#endif specPOr[j] = L_add( Mpy_32_32_r( Lr, Rr ), Mpy_32_32_r( Li, Ri ) ); // 2*spec_e move32(); @@ -1207,10 +1184,6 @@ static void calc_poc_fx( } } -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return; } @@ -1231,10 +1204,6 @@ static Word32 find_poc_peak_fx( Word32 Q_fx[CPE_CHANNELS], aQ_fx[CPE_CHANNELS], cQ_fx[CPE_CHANNELS], width_fx, *peak_width_fx, *peakQ_fx, cconfidence_fx, *P_fx, tmpf_fx, eps2_fx; Word16 tmpf_e = 0, eps2_e = 0, Q_e[CPE_CHANNELS], eps_e = 15, peakQ_e[CPE_CHANNELS]; -#ifdef FIX_1511_WMOPS - push_wmops("find_poc_peak_fx"); -#endif - move16(); move16(); move16(); @@ -1525,10 +1494,6 @@ static Word32 find_poc_peak_fx( hPOC->confidence_fx = L_add( cconfidence_var1, L_shl( cconfidence_var2, 1 ) ); // Q31 move32(); -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return hPOC->confidence_fx; } @@ -1554,10 +1519,6 @@ static ivas_error estimate_itd_fx( Word16 rfft_coef_step; ivas_error error; -#ifdef FIX_1511_WMOPS - push_wmops("estimate_itd_fx"); -#endif - error = IVAS_ERR_OK; move32(); @@ -1614,10 +1575,6 @@ static ivas_error estimate_itd_fx( *corr = round_fx( find_poc_peak_fx( hPOC, itd, input_frame, STEREO_DMX_EVS_POC_W_FORGETTING_FX ) ); move16(); -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return error; } @@ -1639,10 +1596,6 @@ static void weighted_ave_fx( Word16 i, len; Word32 gain_tmp_fx = 0, gain_sub_fx; -#ifdef FIX_1511_WMOPS - push_wmops("weighted_ave_fx"); -#endif - move32(); len = shr( input_frame, 4 ); gain_sub_fx = L_sub( gain_fx, old_gain_fx ); @@ -1658,10 +1611,6 @@ static void weighted_ave_fx( move32(); } -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return; } /*-------------------------------------------------------------------* @@ -1682,10 +1631,6 @@ static void calc_energy_fx( Word16 i, adaptlen; Word64 E_fx; -#ifdef FIX_1511_WMOPS - push_wmops("calc_energy_fx"); -#endif - /* Initialization */ E_fx = 0; move32(); @@ -1748,10 +1693,6 @@ static void calc_energy_fx( *energy_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( *energy_fx, ratio_float_fx ), *energy_fx_e, Mpy_32_32( temp32, L_sub( MAX_32, ratio_float_fx ) ), sub( 31, q_temp32 ), energy_fx_e ); move32(); -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return; } @@ -1772,10 +1713,6 @@ static void adapt_gain_fx( Word16 i, len; Word32 gain_tmp_fx, gain_sub_fx; -#ifdef FIX_1511_WMOPS - push_wmops("adapt_gain_fx"); -#endif - len = shr( input_frame, 4 ); // gain_sub = gain - old_gain; gain_sub_fx = L_sub( gain_fx, old_gain_fx ); // Q31 @@ -1794,10 +1731,6 @@ static void adapt_gain_fx( move32(); } -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return; } @@ -1827,10 +1760,6 @@ static void create_M_signal_fx( Word16 temp_e; Word16 temp_e_1, temp_e_2; -#ifdef FIX_1511_WMOPS - push_wmops("create_M_signal_fx"); -#endif - /* Initialization */ eps_fx = 1024; // 1024.0f in Q0 move32(); @@ -1896,10 +1825,6 @@ static void create_M_signal_fx( w_prev_fx[2] = amp_mod_fx[1]; move32(); -#ifdef FIX_1511_WMOPS - pop_wmops(); -#endif - return; } @@ -1938,8 +1863,8 @@ void stereo_dmx_evs_enc_fx( Word64 W_tmp; Word16 W_tmp_q; -#ifdef FIX_1511_WMOPS - push_wmops("stereo_dmx_evs_enc_fx"); +#ifdef FIX_1511_POC_RENORM + push_wmops( "stereo_dmx_evs_enc_fx" ); #endif if ( is_binaural ) @@ -2293,8 +2218,8 @@ void stereo_dmx_evs_enc_fx( Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); // Q26->Q15 -#ifdef FIX_1511_WMOPS - pop_wmops(); +#ifdef FIX_1511_POC_RENORM + pop_wmops(); #endif return; -- GitLab From e6ee6c58dfcd22133883e20609e6e3834bcaa9bc Mon Sep 17 00:00:00 2001 From: Arnaud Lefort Date: Tue, 13 May 2025 12:17:33 +0200 Subject: [PATCH 03/54] clang formatted. --- lib_debug/debug.c | 2 +- lib_debug/wmc_auto.c | 8 ++--- lib_debug/wmc_auto.h | 52 +++++++++++++++++--------------- lib_enc/ivas_stereo_dmx_evs_fx.c | 1 + 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lib_debug/debug.c b/lib_debug/debug.c index aafc1b663..ee6040faf 100644 --- a/lib_debug/debug.c +++ b/lib_debug/debug.c @@ -788,7 +788,7 @@ char *fname( #ifdef DEBUG_FORCE_DIR size_t len; len = strlen( tmp_fname ); - if (tmp_fname[len - 1] != '/' && tmp_fname[len - 1] != '\\' ) + if ( tmp_fname[len - 1] != '/' && tmp_fname[len - 1] != '\\' ) { /* add trailing '/' slash */ strcat( tmp_fname, "/" ); diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index d357c03dd..9a4b371fc 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -1018,7 +1018,7 @@ int push_stack( const char *filename, const char *fctname ) } /* Check, if This is the New Worst-Case RAM (stack + heap) */ - current_stack_size = ( int32_t )( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); + current_stack_size = (int32_t) ( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); if ( current_stack_size < 0 ) { @@ -1226,7 +1226,7 @@ void *mem_alloc( current_heap_size += ptr_record->block_size; /* Check, if this is the new Worst-Case RAM (stack + heap) */ - current_stack_size = ( int32_t )( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); + current_stack_size = (int32_t) ( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); if ( current_stack_size + current_heap_size > wc_ram_size ) { wc_ram_size = current_stack_size + current_heap_size; @@ -2416,7 +2416,7 @@ int EQ_64( long long int L64_var1, long long int L64_var2 ) #endif return F_ret; } -int NE_64( long long int L64_var1, long long int L64_var2 ) +int NE_64( long long int L64_var1, long long int L64_var2 ) { int F_ret = 0; @@ -2503,7 +2503,7 @@ void Reset_BASOP_WMOPS_counter( unsigned int counterId ) /* reset the current BASOP operation counter */ ptr = (unsigned int *) &multiCounter[counterId]; - for ( i = 0; i < (int) (sizeof(BASIC_OP) / sizeof(unsigned int)); i++ ) + for ( i = 0; i < (int) ( sizeof( BASIC_OP ) / sizeof( unsigned int ) ); i++ ) { *ptr++ = 0; } diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index 59bbc5bbf..8c6396313 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -34,7 +34,7 @@ #define ENH_64_BIT_OPERATOR #define ENH_U_32_BIT_OPERATOR #define COMPLEX_OPERATOR -#define CONTROL_CODE_OPS /* enable control code operators such as LT_16, GT_16, ... */ +#define CONTROL_CODE_OPS /* enable control code operators such as LT_16, GT_16, ... */ #define WMOPS_DISABLE_FCN_CALL_PENALIZATION /* do not count the complexity of function calls */ #ifdef WMOPS @@ -258,7 +258,7 @@ void update_mem( void ); { \ ops_cnt += ( 2 * _TRANS_C * ( x ) ); \ inst_cnt[_TRANS] += ( x ); \ - } + } #else @@ -335,29 +335,29 @@ extern int cntr_push_pop; #endif /* Define all Macros without '{' & '}' (None of these should be called externally!) */ -#define ABS_( x ) OP_COUNT_( _ABS, ( x ) ) -#define ADD_( x ) OP_COUNT_( _ADD, ( x ) ) -#define MULT_( x ) OP_COUNT_( _MULT, ( x ) ) -#define MAC_( x ) OP_COUNT_( _MAC, ( x ) ) -#define MOVE_( x ) OP_COUNT_( _MOVE, ( x ) ) -#define STORE_( x ) OP_COUNT_( _STORE, ( x ) ) -#define LOGIC_( x ) OP_COUNT_( _LOGIC, ( x ) ) -#define SHIFT_( x ) OP_COUNT_( _SHIFT, ( x ) ) -#define BRANCH_( x ) OP_COUNT_( _BRANCH, ( x ) ) -#define DIV_( x ) OP_COUNT_( _DIV, ( x ) ) -#define SQRT_( x ) OP_COUNT_( _SQRT, ( x ) ) -#define TRANS_( x ) OP_COUNT_( _TRANS, ( x ) ) +#define ABS_( x ) OP_COUNT_( _ABS, ( x ) ) +#define ADD_( x ) OP_COUNT_( _ADD, ( x ) ) +#define MULT_( x ) OP_COUNT_( _MULT, ( x ) ) +#define MAC_( x ) OP_COUNT_( _MAC, ( x ) ) +#define MOVE_( x ) OP_COUNT_( _MOVE, ( x ) ) +#define STORE_( x ) OP_COUNT_( _STORE, ( x ) ) +#define LOGIC_( x ) OP_COUNT_( _LOGIC, ( x ) ) +#define SHIFT_( x ) OP_COUNT_( _SHIFT, ( x ) ) +#define BRANCH_( x ) OP_COUNT_( _BRANCH, ( x ) ) +#define DIV_( x ) OP_COUNT_( _DIV, ( x ) ) +#define SQRT_( x ) OP_COUNT_( _SQRT, ( x ) ) +#define TRANS_( x ) OP_COUNT_( _TRANS, ( x ) ) #define POWER_( x ) TRANS_( x ) #define LOG_( x ) TRANS_( x ) -#define LOOP_( x ) OP_COUNT_( _LOOP, ( x ) ) -#define INDIRECT_( x ) OP_COUNT_( _INDIRECT, ( x ) ) -#define PTR_INIT_( x ) OP_COUNT_( _PTR_INIT, ( x ) ) +#define LOOP_( x ) OP_COUNT_( _LOOP, ( x ) ) +#define INDIRECT_( x ) OP_COUNT_( _INDIRECT, ( x ) ) +#define PTR_INIT_( x ) OP_COUNT_( _PTR_INIT, ( x ) ) #ifdef WMOPS_DISABLE_FCN_CALL_PENALIZATION -#define FUNC_( x ) ( x ) +#define FUNC_( x ) ( x ) #else -#define FUNC_( x ) ( OP_COUNT_( _MOVE, ( x ) ), OP_COUNT_( _FUNC, 1 ) ) +#define FUNC_( x ) ( OP_COUNT_( _MOVE, ( x ) ), OP_COUNT_( _FUNC, 1 ) ) #endif -#define MISC_( x ) ABS_( x ) +#define MISC_( x ) ABS_( x ) /* Math Operations */ #define abs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), abs ) @@ -401,8 +401,8 @@ extern int cntr_push_pop; #define frexp_ OP_COUNT_WRAPPER1_( MISC_( 2 ), frexp ) #define frexpf_ OP_COUNT_WRAPPER1_( MISC_( 2 ), frexpf ) -/* the macros below are instrumented versions of user-defined macros that might be used in the source code - representing some well-known and recognized mathematical operations (that are not defined in math.h) +/* the macros below are instrumented versions of user-defined macros that might be used in the source code + representing some well-known and recognized mathematical operations (that are not defined in math.h) Note: the 'wmc_flag_=wmc_flag_' is used to avoid warning: left-hand operand of comma expression has no effect with gcc */ #define min_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), min( ( a ), ( b ) ) ) @@ -928,7 +928,7 @@ typedef struct unsigned int Madd_32_32_r; /* Complexity Weight of 1 */ unsigned int Msub_32_32; /* Complexity Weight of 1 */ unsigned int Msub_32_32_r; /* Complexity Weight of 1 */ -#endif /* #ifdef ENH_32_BIT_OPERATOR */ +#endif /* #ifdef ENH_32_BIT_OPERATOR */ #ifdef ENH_U_32_BIT_OPERATOR unsigned int UL_addNs; /* Complexity Weight of 1 */ @@ -938,7 +938,7 @@ typedef struct unsigned int Mpy_32_16_uu; /* Complexity Weight of 2 */ unsigned int norm_ul_float; /* Complexity Weight of 1 */ unsigned int UL_deposit_l; /* Complexity Weight of 1 */ -#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ +#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ #ifdef CONTROL_CODE_OPS unsigned int LT_16; /* Complexity Weight of 1 */ @@ -1095,7 +1095,9 @@ void incrIf( const char *func_name ); #ifndef WMOPS #define ELSE else #else /* ifndef WMOPS */ -#define ELSE else if ( incrElse( __func__ ), 0 ); else +#define ELSE \ + else if ( incrElse( __func__ ), 0 ); \ + else void incrElse( const char *func_name ); #endif /* ifndef WMOPS */ diff --git a/lib_enc/ivas_stereo_dmx_evs_fx.c b/lib_enc/ivas_stereo_dmx_evs_fx.c index 793f204d8..f84f90e46 100644 --- a/lib_enc/ivas_stereo_dmx_evs_fx.c +++ b/lib_enc/ivas_stereo_dmx_evs_fx.c @@ -2214,6 +2214,7 @@ void stereo_dmx_evs_enc_fx( } Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); // Q26->Q15 + pop_wmops(); return; -- GitLab From a2f8fbf18f04e7660cc87a609fea23d3ce1a7372 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 23 May 2025 17:46:17 +0530 Subject: [PATCH 04/54] Fix for 3GPP issue 1475: 160 kbit/s ISM4 Encoder: FB BWE lacking energy Link #1475 --- lib_enc/swb_tbe_enc_fx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 903f3a46c..a4230db46 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -7548,7 +7548,7 @@ void fb_tbe_enc_ivas_fx( move16(); temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ - temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( q_input_fhb, hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb + temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb exp = W_norm( temp1 ); @@ -7605,7 +7605,6 @@ void fb_tbe_enc_ivas_fx( { push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); } - return; } void tbe_write_bitstream_fx( -- GitLab From e26eb7288617bc285cf2e2ec22cd02f2183b8664 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 23 May 2025 18:15:50 +0530 Subject: [PATCH 05/54] Clang formatting changes --- lib_enc/swb_tbe_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index a4230db46..9d0f16ee9 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -7547,7 +7547,7 @@ void fb_tbe_enc_ivas_fx( hBWE_TD->old_input_fhb_fx_Q = exp_temp; move16(); - temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ + temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb -- GitLab From fcb912776046556313cd96c5e26b828fed633dfc Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 26 May 2025 14:58:39 -0400 Subject: [PATCH 06/54] possible fix to 1713, icBWE exp --- lib_com/options.h | 2 ++ lib_enc/ivas_stereo_icbwe_enc_fx.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 20a1dc555..0932d2434 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -101,4 +101,6 @@ #define TEST_HR #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ +#define FIX_1713_EXP /* VA: proposed correction to exp in ic-BWE*/ + #endif diff --git a/lib_enc/ivas_stereo_icbwe_enc_fx.c b/lib_enc/ivas_stereo_icbwe_enc_fx.c index eba30f762..706cac13f 100644 --- a/lib_enc/ivas_stereo_icbwe_enc_fx.c +++ b/lib_enc/ivas_stereo_icbwe_enc_fx.c @@ -828,7 +828,11 @@ void stereo_icBWE_enc_ivas_fx( ELSE { +#ifndef FIX_1713_EXP max_e = s_max( hStereoICBWE->mem_shb_speech_nonref_e, shb_speech_nonref_e ); +#else + max_e = s_max( hStereoICBWE->mem_shb_speech_ref_e, shb_speech_ref_e ); +#endif Copy_Scale_sig( hStereoICBWE->mem_shb_speech_ref_fx, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) ); // mem_shb_speech_ref_e set32_fx( shb_frame_ref_fx, 0, L_LOOK_16k + L_FRAME16k ); @@ -854,8 +858,11 @@ void stereo_icBWE_enc_ivas_fx( /* shb_frame_ref_ICBWE @ (8.75 - shb_speech_delay (=1.25) ms) after shb_speech */ Copy_Scale_sig32( shb_speech_nonref_fx, shb_frame_nonref_fx + L_LOOK_16k - nonRefMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_nonref_e ) ) ); /* Q31-max_e */ +#ifndef FIX_1713_EXP Copy_Scale_sig_32_16( shb_frame_nonref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_nonref_fx, L_LOOK_16k, sub( negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ), Q16 ) ); // mem_shb_speech_ref_e - +#else + Copy_Scale_sig_32_16( shb_frame_nonref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_nonref_fx, L_LOOK_16k, sub( negate( sub( max_e, hStereoICBWE->mem_shb_speech_nonref_e ) ), Q16 ) ); // mem_shb_speech_ref_e +#endif /* core switching reset */ test(); -- GitLab From ae6c1839a8830c6d8eabd56e8c359399c01400dd Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 26 May 2025 15:03:08 -0400 Subject: [PATCH 07/54] clang format --- lib_enc/ivas_stereo_icbwe_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_stereo_icbwe_enc_fx.c b/lib_enc/ivas_stereo_icbwe_enc_fx.c index 706cac13f..95c49aeae 100644 --- a/lib_enc/ivas_stereo_icbwe_enc_fx.c +++ b/lib_enc/ivas_stereo_icbwe_enc_fx.c @@ -857,7 +857,7 @@ void stereo_icBWE_enc_ivas_fx( move16(); /* shb_frame_ref_ICBWE @ (8.75 - shb_speech_delay (=1.25) ms) after shb_speech */ - Copy_Scale_sig32( shb_speech_nonref_fx, shb_frame_nonref_fx + L_LOOK_16k - nonRefMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_nonref_e ) ) ); /* Q31-max_e */ + Copy_Scale_sig32( shb_speech_nonref_fx, shb_frame_nonref_fx + L_LOOK_16k - nonRefMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_nonref_e ) ) ); /* Q31-max_e */ #ifndef FIX_1713_EXP Copy_Scale_sig_32_16( shb_frame_nonref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_nonref_fx, L_LOOK_16k, sub( negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ), Q16 ) ); // mem_shb_speech_ref_e #else -- GitLab From d5d3ed62850d25c0751ed0df4ec83259374379c9 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 28 May 2025 11:31:01 +0530 Subject: [PATCH 08/54] Fix for 3GPP issue 1457: Stereo Encoder 32 kbps: More rattling artifcats in 16 kHz LTVs Link #1457 --- lib_enc/ivas_cpe_enc_fx.c | 10 +++-- lib_enc/ivas_stereo_dft_enc_itd_fx.c | 26 ++++++++++- lib_enc/ivas_stereo_dft_td_itd_fx.c | 66 +++++++++++++++++++++------- 3 files changed, 79 insertions(+), 23 deletions(-) diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index d0a33ed09..0cd7532d5 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -649,10 +649,11 @@ ivas_error ivas_cpe_enc_fx( hCPE->hStereoDft->Spd_R_smooth_fx_e = sub( hCPE->hStereoDft->Spd_R_smooth_fx_e, temp ); move16(); - + q_com = MAX_16; + move16(); FOR( n = 0; n < CPE_CHANNELS; n++ ) { - q_com = sub( add( L_norm_arr( sts[n]->input32_fx, input_frame ), sts[n]->q_inp32 ), 16 ); + q_com = s_min( q_com, sub( add( L_norm_arr( sts[n]->input32_fx, input_frame ), sts[n]->q_inp32 ), 16 ) ); q_com = s_min( q_com, sub( add( L_norm_arr( sts[n]->old_input_signal32_fx, input_frame ), sts[n]->q_old_inp32 ), 16 ) ); q_com = s_min( q_com, add( norm_arr( hCPE->input_mem_fx[n], hCPE->hStereoDft->dft_ovl ), hCPE->q_input_mem[n] ) ); @@ -661,7 +662,9 @@ ivas_error ivas_cpe_enc_fx( q_com = 0; move16(); } - + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { Copy_Scale_sig_32_16( sts[n]->input32_fx, sts[n]->input_fx, input_frame, sub( q_com, sts[n]->q_inp32 ) ); sts[n]->q_inp = q_com; move16(); @@ -674,7 +677,6 @@ ivas_error ivas_cpe_enc_fx( hCPE->q_input_mem[n] = q_com; move16(); } - stereo_dft_hybrid_ITD_flag_fx( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max ); /* Time Domain ITD compensation using extrapolation */ diff --git a/lib_enc/ivas_stereo_dft_enc_itd_fx.c b/lib_enc/ivas_stereo_dft_enc_itd_fx.c index 1beacd19a..28bac9e8b 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd_fx.c +++ b/lib_enc/ivas_stereo_dft_enc_itd_fx.c @@ -169,7 +169,8 @@ static void stereo_dft_quantize_itd_fx( Word16 *ind ) { Word16 itd; - + Word16 input_fs_by_stereo_dft_itd_fs = 0; + move16(); // itd = (int16_t) ( sign( in ) * 0.5f + in ); itd = in; move16(); @@ -188,9 +189,30 @@ static void stereo_dft_quantize_itd_fx( move16(); } + SWITCH( input_Fs ) + { + case 8000: + input_fs_by_stereo_dft_itd_fs = 1; // Q2 + move16(); + BREAK; + case 16000: + input_fs_by_stereo_dft_itd_fs = 2; // Q2 + move16(); + BREAK; + case 32000: + input_fs_by_stereo_dft_itd_fs = 4; // Q2 + move16(); + BREAK; + case 48000: + input_fs_by_stereo_dft_itd_fs = 6; // Q2 + move16(); + BREAK; + default: + assert( 0 ); + } /*Convert back @ fs*/ //*out = (float) ( itd * input_Fs ) / ( (float) ( STEREO_DFT_ITD_FS ) ); - *out = Mpy_32_32( L_shl( itd * input_Fs, 2 ), 1099511628 /*Q45*/ ); // Q45+Q2-Q31 = Q16 + *out = L_shl( L_mult( itd, input_fs_by_stereo_dft_itd_fs ), Q13 ); // Q16 move32(); return; diff --git a/lib_enc/ivas_stereo_dft_td_itd_fx.c b/lib_enc/ivas_stereo_dft_td_itd_fx.c index 309ec3377..33763d4cc 100644 --- a/lib_enc/ivas_stereo_dft_td_itd_fx.c +++ b/lib_enc/ivas_stereo_dft_td_itd_fx.c @@ -50,9 +50,9 @@ #define STEREO_DFT_CHANNEL_EXTR_LPC_ORDER 10 #define STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT 320 -#define FLR_FX 16384 // Q15 -#define ONE_HALF 24576 // Q14 -const Word16 wac_swb_h_fx[LPC_SHB_ORDER + 1] = { // Q15 +#define FLR_FX 1073741824 // Q31 +#define ONE_HALF 24576 // Q14 +const Word16 wac_swb_h_fx[LPC_SHB_ORDER + 1] = { // Q15 32767, 32758, 32731, @@ -95,7 +95,12 @@ static void stereo_td_get_td_itd_fx( { /* *td_itd is the closest integer to itd that transforms into an integer value * * under the transform x -> (32000/fs) x. */ - Word16 d, d_e; + Word32 inverse_input_fs_by_16k = 0; + move32(); + Word64 tmp64; + Word16 d = 0, shift = 0; + move16(); + move16(); IF( EQ_32( input_Fs, 32000 ) ) { @@ -106,24 +111,51 @@ static void stereo_td_get_td_itd_fx( ELSE { assert( ( input_Fs % 16000 ) == 0 && "sampling frequency should be divisible by 16000" ); - Word16 temp_div, temp_e, temp_add; - d = BASOP_Util_Divide3232_Scale( input_Fs, 16000, &d_e ); - temp_div = BASOP_Util_Divide3232_Scale( itd, L_deposit_h( d ), &temp_e ); - temp_e = add( temp_e, sub( sub( 31, q_itd ), d_e ) ); // e+(e1-e2)// - temp_add = add_sat( temp_div, shr_sat( FLR_FX, temp_e ) ); - - IF( itd != 0 ) + IF( itd == 0 ) { - *td_itd_32 = extract_l( L_shl( L_shr( L_add( temp_add, EPSILON_FX ), sub( 15, temp_e ) ), 1 ) ); + *td_itd_32 = *td_itd = 0; + move16(); + move16(); } ELSE { - *td_itd_32 = shl( shr( temp_add, sub( 15, temp_e ) ), 1 ); - } - move16(); + SWITCH( input_Fs ) + { + case 16000: + inverse_input_fs_by_16k = 1073741824; // Q30 /* This is in Q30, because 2147483648 cannot be represnt in Word32*/ + move32(); + d = 1; // Q0 + move16(); + shift = 1; + move16(); + BREAK; + case 32000: + inverse_input_fs_by_16k = 1073741824; // Q31 + move32(); + d = 2; // Q0 + move16(); + BREAK; + case 48000: + inverse_input_fs_by_16k = 715827883; // Q31 + move32(); + d = 3; // Q0 + move16(); + if (itd < 0 ) + { + inverse_input_fs_by_16k = 715827882; /* Reducing the precision by 1 to handle multiplication of negative case*/ + move32(); + } + BREAK; + default: + assert( 0 ); + } + tmp64 = W_add( W_mult0_32_32( itd, inverse_input_fs_by_16k ), W_shl( FLR_FX, sub( q_itd, shift ) ) ); // Q: q_itd - shift + 31 + *td_itd_32 = shl( extract_l( W_extract_l( W_shr( tmp64, add( sub( q_itd, shift ), Q31 ) ) ) ), 1 ); // Q0 + move16(); - *td_itd = i_mult( shr( *td_itd_32, 1 ), shr( d, sub( 15, d_e ) ) ); - move16(); + *td_itd = i_mult( shr( *td_itd_32, 1 ), d ); // Q0 + move16(); + } } return; -- GitLab From 306f26e2237a46381b687aaf4c6ae86243ea5077 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 28 May 2025 11:34:05 +0530 Subject: [PATCH 09/54] Clang formatting changes --- lib_enc/ivas_stereo_dft_td_itd_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_stereo_dft_td_itd_fx.c b/lib_enc/ivas_stereo_dft_td_itd_fx.c index 33763d4cc..a0d49176f 100644 --- a/lib_enc/ivas_stereo_dft_td_itd_fx.c +++ b/lib_enc/ivas_stereo_dft_td_itd_fx.c @@ -140,7 +140,7 @@ static void stereo_td_get_td_itd_fx( move32(); d = 3; // Q0 move16(); - if (itd < 0 ) + if ( itd < 0 ) { inverse_input_fs_by_16k = 715827882; /* Reducing the precision by 1 to handle multiplication of negative case*/ move32(); -- GitLab From 67f74ae7d4354cfb68eac5ca5b4746d60694c5ed Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 28 May 2025 11:36:09 +0530 Subject: [PATCH 10/54] Fix for 3GPP issue 1504: BASOP decoder to MONO output for MASA 2TC LTV input exhibits higher MLD Link #1504 --- lib_rend/ivas_dirac_rend_fx.c | 122 ++++++++++++---------------------- lib_rend/ivas_stat_rend.h | 4 +- 2 files changed, 44 insertions(+), 82 deletions(-) diff --git a/lib_rend/ivas_dirac_rend_fx.c b/lib_rend/ivas_dirac_rend_fx.c index 063c70f66..99a84bf52 100644 --- a/lib_rend/ivas_dirac_rend_fx.c +++ b/lib_rend/ivas_dirac_rend_fx.c @@ -1759,17 +1759,19 @@ void protoSignalComputation2_fx( Word32 lr_total_bb_ratio_fx, lr_total_hi_ratio_fx; Word32 min_sum_total_ratio_fx, min_sum_total_ratio_db_fx; Word32 sum_total_ratio_fx[MASA_SUM_FREQ_RANGE_BINS]; - Word16 q_sum_total_ratio; + Word16 exp_sum_total_ratio_fx[MASA_SUM_FREQ_RANGE_BINS]; + Word16 q_sum_total_ratio = 0; + move16(); Word32 a_fx, b_fx, a2_fx, b2_fx; Word16 interpolatorSpaced_fx, interpolatorDmx_fx; Word32 tempSpaced_fx, tempDmx_fx; #ifdef FIX_867_CLDFB_NRG_SCALE - Word16 q_shift, min_q_shift[2], exp, q_temp[2], temp_q_shift, q_temp2; + Word16 q_shift, min_q_shift[2], exp, q_temp[2]; #else Word16 q_shift, min_q_shift, exp, q_temp, temp_q_shift, q_temp2; #endif Word32 temp; - Word64 W_tmp1, W_tmp2; + Word64 W_tmp1, W_tmp2, W_tmp3; Word64 reference_power_64fx[CLDFB_NO_CHANNELS_MAX]; Word16 q_reference_power_64fx; Word16 head_room, q_Left_Right_power; @@ -1786,9 +1788,7 @@ void protoSignalComputation2_fx( min_q_shift = Q31; move16(); #endif - temp_q_shift = Q31; - move16(); - q_sum_total_ratio = Q31; + q_sum_total_ratio = 0; move16(); exp = 0; move16(); @@ -1813,7 +1813,6 @@ void protoSignalComputation2_fx( min_q_shift = s_min( min_q_shift, q_shift ); #endif q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ), L_norm_arr( ImagBuffer_fx[l][0], s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) ); - temp_q_shift = s_min( temp_q_shift, q_shift ); } #ifdef FIX_867_CLDFB_NRG_SCALE @@ -1822,7 +1821,6 @@ void protoSignalComputation2_fx( #else min_q_shift = sub( min_q_shift, 2 ); // guard bits #endif - temp_q_shift = sub( temp_q_shift, 2 ); // guard bits /* Upscaling of the buffer proto_power_smooth_fx */ #ifdef FIX_867_CLDFB_NRG_SCALE @@ -2072,7 +2070,7 @@ void protoSignalComputation2_fx( } #ifdef FIX_867_CLDFB_NRG_SCALE - Word16 total_shift[2], q_temp_total; + Word16 total_shift[2]; /* total_shift shift required to get common Q of sum power values */ total_shift[0] = shl( s_max( 0, sub( min_q_shift[0], min_q_shift[1] ) ), 1 ); total_shift[1] = shl( s_max( 0, sub( min_q_shift[1], min_q_shift[0] ) ), 1 ); @@ -2080,13 +2078,11 @@ void protoSignalComputation2_fx( min_q_shift[1] = sub( min_q_shift[1], idiv1616( find_guarded_bits_fx( num_freq_bands ), 2 ) ); q_temp[0] = sub( add( add( q_cldfb, min_q_shift[0] ), add( q_cldfb, min_q_shift[0] ) ), 31 ); q_temp[1] = sub( add( add( q_cldfb, min_q_shift[1] ), add( q_cldfb, min_q_shift[1] ) ), 31 ); - q_temp_total = s_min( q_temp[0], q_temp[1] ); #else min_q_shift = sub( min_q_shift, idiv1616( find_guarded_bits_fx( num_freq_bands ), 2 ) ); q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); #endif - q_temp2 = sub( add( add( q_cldfb, temp_q_shift ), add( q_cldfb, temp_q_shift ) ), 31 ); head_room = 63; move16(); @@ -2195,77 +2191,50 @@ void protoSignalComputation2_fx( IF( LT_16( l, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) ) { -#ifdef FIX_867_CLDFB_NRG_SCALE - re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift - im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift -#else - re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift - im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift -#endif + re_aux = L_add( L_shr( RealBuffer_fx[0][0][l], 1 ), L_shr( RealBuffer_fx[1][0][l], 1 ) ); + im_aux = L_add( L_shr( ImagBuffer_fx[0][0][l], 1 ), L_shr( ImagBuffer_fx[1][0][l], 1 ) ); - sum_power_fx = Madd_32_32( Mpy_32_32( re_aux, re_aux ), im_aux, im_aux ); // 2*(q_cldfb+temp_q_shift)-31 - temp = Mpy_32_32( a_fx, sum_power_fx ); // 2*(q_cldfb+temp_q_shift)-31 + W_tmp3 = W_add( W_mult0_32_32( re_aux, re_aux ), W_mult0_32_32( im_aux, im_aux ) ); + q_shift = W_norm( W_tmp3 ); + sum_power_fx = W_extract_h( W_shl( W_tmp3, q_shift ) ); + exp_temppp = sub( 31, sub( add( shl( sub( q_cldfb, 1 ), 1 ), q_shift ), 32 ) ); - IF( LT_16( q_temp2, stereo_type_detect->q_sum_power ) ) - { - stereo_type_detect->sum_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ), sub( stereo_type_detect->q_sum_power, q_temp2 ) ) ); // q_temp2 - move32(); - } - ELSE - { - stereo_type_detect->sum_power_fx[l] = L_add( L_shr( temp, sub( q_temp2, stereo_type_detect->q_sum_power ) ), Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ) ); // stereo_type_detect->q_sum_power - move32(); - } + stereo_type_detect->sum_power_fx[l] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a_fx, sum_power_fx ), exp_temppp, Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ), stereo_type_detect->exp_sum_power[l], &stereo_type_detect->exp_sum_power[l] ); + move32(); + W_tmp1 = W_add( W_mult0_32_32( RealBuffer_fx[0][0][l], RealBuffer_fx[0][0][l] ), W_mult0_32_32( ImagBuffer_fx[0][0][l], ImagBuffer_fx[0][0][l] ) ); + W_tmp2 = W_add( W_mult0_32_32( RealBuffer_fx[1][0][l], RealBuffer_fx[1][0][l] ), W_mult0_32_32( ImagBuffer_fx[1][0][l], ImagBuffer_fx[1][0][l] ) ); -#ifdef FIX_867_CLDFB_NRG_SCALE - temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], add( 31, total_shift[qidx] ) ) ) ); // 2*(q_cldfb+min_q_shift) -31 - IF( LT_16( q_temp_total, stereo_type_detect->q_total_power ) ) - { - stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp_total ) ) ); // q_temp - move32(); - } - ELSE - { - stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp_total, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); // stereo_type_detect->q_total_power - move32(); - } -#else - temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 - IF( LT_16( q_temp, stereo_type_detect->q_total_power ) ) - { - stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); // q_temp - move32(); - } - ELSE - { - stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); // stereo_type_detect->q_total_power - move32(); - } -#endif + W_tmp2 = W_add( W_tmp1, W_tmp2 ); + q_shift = W_norm( W_tmp2 ); + Total_power_fx = W_extract_h( W_shl( W_tmp2, q_shift ) ); + exp_temppp = sub( 31, sub( add( shl( q_cldfb, 1 ), q_shift ), 32 ) ); + + stereo_type_detect->total_power_fx[l] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a_fx, Total_power_fx ), exp_temppp, Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), stereo_type_detect->exp_total_power[l], &stereo_type_detect->exp_total_power[l] ); + move32(); test(); IF( ( stereo_type_detect->sum_power_fx[l] == 0 ) && ( stereo_type_detect->total_power_fx[l] == 0 ) ) { sum_total_ratio_fx[l] = MAX_32; // q15 move32(); + exp_sum_total_ratio_fx[l] = 16; + move16(); } ELSE IF( stereo_type_detect->total_power_fx[l] == 0 ) { sum_total_ratio_fx[l] = MAX_32; // q15 move32(); + exp_sum_total_ratio_fx[l] = 16; + move16(); } ELSE { - sum_total_ratio_fx[l] = BASOP_Util_Divide3232_Scale( stereo_type_detect->sum_power_fx[l], stereo_type_detect->total_power_fx[l], &exp ); // 15-(exp+s_min( stereo_type_detect->q_total_power, q_temp )-s_min( stereo_type_detect->q_sum_power, q_temp2 )) - move32(); -#ifdef FIX_867_CLDFB_NRG_SCALE - q_sum_total_ratio = add( sub( 15, exp ), sub( s_min( stereo_type_detect->q_sum_power, q_temp2 ), s_min( stereo_type_detect->q_total_power, q_temp_total ) ) ); -#else - q_sum_total_ratio = add( sub( 15, exp ), sub( s_min( stereo_type_detect->q_sum_power, q_temp2 ), s_min( stereo_type_detect->q_total_power, q_temp ) ) ); -#endif - sum_total_ratio_fx[l] = L_shl( sum_total_ratio_fx[l], sub( Q15, q_sum_total_ratio ) ); // q15 + sum_total_ratio_fx[l] = BASOP_Util_Divide3232_Scale_newton( stereo_type_detect->sum_power_fx[l], stereo_type_detect->total_power_fx[l], &exp ); // 15-(exp+s_min( stereo_type_detect->q_total_power, q_temp )-s_min( stereo_type_detect->q_sum_power, q_temp2 )) move32(); + exp_sum_total_ratio_fx[l] = add( exp, sub( stereo_type_detect->exp_sum_power[l], stereo_type_detect->exp_total_power[l] ) ); + move16(); } + q_sum_total_ratio = s_max( q_sum_total_ratio, exp_sum_total_ratio_fx[l] ); } IF( l == 0 ) @@ -2626,18 +2595,6 @@ void protoSignalComputation2_fx( move32(); } - stereo_type_detect->q_sum_power = s_min( stereo_type_detect->q_sum_power, q_temp2 ); - move16(); -#ifdef FIX_867_CLDFB_NRG_SCALE - stereo_type_detect->q_total_power = s_min( stereo_type_detect->q_total_power, q_temp_total ); - move16(); -#else - stereo_type_detect->q_total_power = s_min( stereo_type_detect->q_total_power, q_temp ); - move16(); -#endif - q_sum_total_ratio = Q15; - move16(); - IF( stereo_type_detect->interpolator > 0 ) { stereo_type_detect->interpolator++; @@ -2767,8 +2724,15 @@ void protoSignalComputation2_fx( // 20480 = 10 in Q11 lr_total_hi_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21 + FOR( Word16 i = 0; i < s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ); i++ ) + { + sum_total_ratio_fx[i] = L_shl( sum_total_ratio_fx[i], sub( exp_sum_total_ratio_fx[i], q_sum_total_ratio ) ); + move32(); + } + minimum_l( sum_total_ratio_fx, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio_fx ); // q_sum_total_ratio - exp = sub( 31, q_sum_total_ratio ); + exp = q_sum_total_ratio; + move16(); temp = BASOP_Util_Log2( min_sum_total_ratio_fx ); // q25 IF( NE_32( temp, MIN_32 ) ) { @@ -3537,10 +3501,8 @@ void ivas_masa_init_stereotype_detection_fx( set32_fx( stereo_type_detect->sum_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS ); set32_fx( stereo_type_detect->total_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS ); - stereo_type_detect->q_sum_power = Q31; - move16(); - stereo_type_detect->q_total_power = Q31; - move16(); + set16_fx( stereo_type_detect->exp_sum_power, 0, MASA_SUM_FREQ_RANGE_BINS ); + set16_fx( stereo_type_detect->exp_total_power, 0, MASA_SUM_FREQ_RANGE_BINS ); stereo_type_detect->subtract_power_y_fx = 0; move32(); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 90e4f5d69..a13ee27e7 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -395,9 +395,9 @@ typedef struct Word16 q_total_hi_power; Word32 sum_power_fx[MASA_SUM_FREQ_RANGE_BINS]; /* Q(q_sum_power) */ - Word16 q_sum_power; + Word16 exp_sum_power[MASA_SUM_FREQ_RANGE_BINS]; Word32 total_power_fx[MASA_SUM_FREQ_RANGE_BINS]; /* Q(q_total_power) */ - Word16 q_total_power; + Word16 exp_total_power[MASA_SUM_FREQ_RANGE_BINS]; Word32 subtract_power_y_fx; /* Q(q_subtract_power_y) */ Word16 q_subtract_power_y; -- GitLab From 5132711f954eb053dbb6134abf728ea517be653a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 28 May 2025 12:37:41 +0530 Subject: [PATCH 11/54] Fix for 3GPP issue 1715: Possible typo in array initialization in function ivas_dirac_render_sf_fx() Link #1715 --- lib_dec/ivas_dirac_dec_fx.c | 42 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index f29133d92..03bc7ee12 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -2217,27 +2217,6 @@ void ivas_dirac_dec_render_sf_fx( move16(); move16(); - - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - set32_fx( Cldfb_RealBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( Cldfb_ImagBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); - } - } - -#ifndef OPT_BIN_RENDERER_V2 - FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - set32_fx( Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); - } - } -#endif /* OPT_BIN_RENDERER_V2 */ - /* local copies of azi, ele, diffuseness */ Word16 azimuth[CLDFB_NO_CHANNELS_MAX]; Word16 elevation[CLDFB_NO_CHANNELS_MAX]; @@ -2288,6 +2267,27 @@ void ivas_dirac_dec_render_sf_fx( push_wmops( "ivas_dirac_dec_render" ); /* Initialize aux buffers */ + + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { + FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + set32_fx( Cldfb_RealBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( Cldfb_ImagBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + } + +#ifndef OPT_BIN_RENDERER_V2 + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + set32_fx( Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( Cldfb_ImagBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + } +#endif /* OPT_BIN_RENDERER_V2 */ + hDirAC = st_ivas->hDirAC; hDirACRend = st_ivas->hDirACRend; hSpatParamRendCom = st_ivas->hSpatParamRendCom; -- GitLab From cf1db1c57390b424eb7c5e0e2f0dcde6892ca068 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 28 May 2025 13:53:18 +0530 Subject: [PATCH 12/54] Fix for 3GPP issue 1267: High MLD for ParamMC 5.1 at 80 kbps with +10dB Input gain Link #1267 --- lib_enc/ivas_core_enc_fx.c | 15 ++++++++++----- lib_enc/ivas_core_pre_proc_front_fx.c | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 6fcb8abd0..ad998beb3 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -113,7 +113,7 @@ ivas_error ivas_core_enc_fx( Word16 diff_nBits; ivas_error error; Word16 max_num_indices_BWE; - Word16 i; + Word16 i, shift, Q_min; set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); @@ -531,11 +531,16 @@ ivas_error ivas_core_enc_fx( st->hTcxEnc->exp_buf_speech_ltp = st->exp_buf_speech_enc; move16(); } - Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); - Scale_sig( st->input_fx - input_frame, input_frame, sub( -1, st->q_old_inp ) ); - st->q_inp = -1; + shift = norm_arr( st->input_fx, input_frame ); + Q_min = s_max( -2, add( st->q_inp, shift ) ); + scale_sig( st->input_fx, input_frame, sub( Q_min, st->q_inp ) ); + st->q_inp = Q_min; move16(); - st->q_old_inp = -1; + + shift = norm_arr( st->input_fx - input_frame, input_frame ); + Q_min = s_max( -2, add( st->q_old_inp, shift ) ); + scale_sig( st->input_fx - input_frame, input_frame, sub( Q_min, st->q_old_inp ) ); + st->q_old_inp = Q_min; move16(); } diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 106d7c387..3e7bf2464 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -232,7 +232,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_min = add( sub( 15, st->exp_old_inp_12k8 ), norm_arr( st->old_inp_12k8_fx, L_INP_MEM ) ); Word16 input_frame_full = shl( input_frame, 1 ); //(old frame input length + new frame input length) Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 ) ); - Q_min = s_max( -1, Q_min ); + Q_min = s_max( -2, Q_min ); Copy_Scale_sig_32_16( st->input32_fx - input_frame, st->input_fx - input_frame, input_frame_full, sub( Q_min, st->q_inp32 ) ); // Q_min st->q_inp = Q_min; move16(); @@ -682,7 +682,7 @@ ivas_error pre_proc_front_ivas_fx( } st->mem_preemph_fx = shl_sat( st->mem_preemph_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1) saturation added as float value goes above 65536 for +10 dB test (ltv48_MC512.wav and ltv48_MC51.wav) */ move16(); - st->mem_preemph_DFT_fx = shl( st->mem_preemph_DFT_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1)*/ + st->mem_preemph_DFT_fx = shl_sat( st->mem_preemph_DFT_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1)*/ move16(); st->mem_preemph_q = st->q_inp; move16(); -- GitLab From 75dbe8183bd4e28198f366cf6635be3cba4572cb Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 28 May 2025 14:49:05 +0530 Subject: [PATCH 13/54] Warning fix --- lib_enc/ivas_core_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index ad998beb3..5737aad2f 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -712,7 +712,7 @@ ivas_error ivas_core_enc_fx( Word16 Q_shb_spch_16 = Q_shb_spch; move16(); - Word16 shift = add( getScaleFactor16( shb_speech_fx, L_FRAME16k ), Q16 ); + shift = add( getScaleFactor16( shb_speech_fx, L_FRAME16k ), Q16 ); Copy_Scale_sig_16_32_no_sat( shb_speech_fx, shb_speech_fx32, L_FRAME16k, shift ); // Q_shb_spch Q_shb_spch = add( Q_shb_spch, shift ); -- GitLab From 06b479d714a02229678e6722742af738c9a63f67 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 29 May 2025 15:46:18 +0530 Subject: [PATCH 14/54] IGF caclulate envelop precision enhancement, bug fix: sharpflag in encod_unvoiced, minimum statistics improvements --- lib_com/fd_cng_com_fx.c | 104 ++++++++++++++++++++++++++++++---------- lib_com/prot_fx.h | 10 +++- lib_dec/fd_cng_dec_fx.c | 10 ++-- lib_dec/stat_dec.h | 6 ++- lib_enc/enc_uv_fx.c | 2 +- lib_enc/fd_cng_enc_fx.c | 10 ++-- lib_enc/igf_enc.c | 2 +- lib_enc/stat_enc.h | 6 ++- 8 files changed, 109 insertions(+), 41 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 207925724..7cc536822 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -483,6 +483,54 @@ void expand_range( move16(); } +void expand_range_fx( + Word32 *in, // Q25 + Word32 *out, // exp:out_exp + Word16 *out_exp, + const Word16 len ) +{ + Word16 i, tmp_e; + Word32 maxVal, tmp32; + Word16 maxOutExp; + + const Word32 low_lim = 726940; /* 0.0003385080526823181f in Q31 */ + move32(); + + /* Find max possible output exponent. */ + maxVal = 0; + move32(); + FOR( i = 0; i < len; i++ ) + { + maxVal = L_max( maxVal, in[i] ); + } + tmp32 = BASOP_util_Pow2( maxVal, Q31 - Q25, &tmp_e ); + maxOutExp = tmp_e; + move16(); + + /* out = (2^(in) - 1) */ + FOR( i = 0; i < len; i++ ) + { + tmp32 = BASOP_util_Pow2( in[i], Q31 - Q25, &tmp_e ); // 2^x + tmp32 = L_sub( tmp32, L_shl( 1, sub( 31, tmp_e ) ) ); // 2^x - 1 + tmp32 = L_shr( tmp32, sub( maxOutExp, tmp_e ) ); // make exp same as maxExpOut + + out[i] = tmp32; + move32(); + + Word32 tmp_low_lim = L_shr( low_lim, maxOutExp ); + if ( LT_32( out[i], tmp_low_lim ) ) + { + out[i] = tmp_low_lim; + move32(); + } + } + + *out_exp = maxOutExp; + move16(); + + return; +} + /*------------------------------------------------------------------- * expand_range_var_e() * @@ -1145,10 +1193,10 @@ void minimum_statistics( void minimum_statistics_fx( Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ Word16 lenFFT, /* i : Number of FFT partitions */ - Word16 *psize, /* i : Partition sizes, fractional */ + Word16 *psize, /* i : Partition sizes, fractional Q9*/ Word16 *msPeriodog, /* i : Periodogram (energies) */ - Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ - Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ + Word32 *msNoiseFloor, /* i/o: Noise floors (energies) Q25*/ + Word32 *msNoiseEst, /* i/o: Noise estimates (energies) Q25*/ Word32 *msAlpha, /* i/o: Forgetting factors */ Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ @@ -1222,10 +1270,10 @@ void minimum_statistics_fx( /* No minimum statistics at initialization */ IF( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { - Copy( msPeriodog, msPsd, len ); /* 6Q9 */ - Copy( msPeriodog, msNoiseFloor, len ); /* 6Q9 */ - Copy( msPeriodog, msNoiseEst, len ); /* 6Q9 */ - Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseFloor, len, Q16 ); /* Q25 */ + Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseEst, len, Q16 ); /* Q25 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ set32_fx( msPsdSecondMoment, 0l /*0.0 Q31*/, len ); msPeriodogSum[0] = dotp_s_fx( msPeriodog, psize, lenFFT, CNG_HS ); @@ -1335,7 +1383,16 @@ void minimum_statistics_fx( /* Compute SNR */ /* msPeriodogSum[cnt] with format 16Q15 */ - snr = dotp_s_fx( msNoiseFloor + start, psize + start, current_len, CNG_HS ); + Word16 msNoiseFloor16tmp[NPART_SHAPING]; + IF( enc_dec == ENC ) + { + Copy_Scale_sig32_16( msNoiseFloor, msNoiseFloor16tmp, NPART, 0 ); + } + ELSE + { + Copy_Scale_sig32_16( msNoiseFloor, msNoiseFloor16tmp, NPART_SHAPING, 0 ); + } + snr = dotp_s_fx( &msNoiseFloor16tmp[start], psize + start, current_len, CNG_HS ); IF( GT_32( L_shr( Mpy_32_16_1( msPsdSum[cnt], 18431 /*0.56246299817 Q15*/ ), 13 ), snr ) ) { @@ -1366,16 +1423,16 @@ void minimum_statistics_fx( /* calculate scalar2 with normalized msNoiseFloor[j], exponent -2*s1 */ s1 = WORD16_BITS - 1; move16(); - if ( msNoiseFloor[j] != 0 ) + if ( msNoiseFloor16tmp[j] != 0 ) { - s1 = norm_s( msNoiseFloor[j] ); + s1 = norm_s( msNoiseFloor16tmp[j] ); } - msNoiseFloor16 = shl( msNoiseFloor[j], s1 ); + msNoiseFloor16 = shl( msNoiseFloor16tmp[j], s1 ); scalar2 = L_mult( msNoiseFloor16, msNoiseFloor16 ); /* calculate difference, both elements in 6Q9 format, use absolute value to avoid -1.0 x -1.0 multiplications later */ - scalar316 = abs_s( sub( msPsd[j], msNoiseFloor[j] ) ); + scalar316 = abs_s( sub( msPsd[j], msNoiseFloor16tmp[j] ) ); s2 = WORD16_BITS - 1; move16(); @@ -1475,7 +1532,7 @@ void minimum_statistics_fx( IF( msNoiseFloor[j] != 0 /*0.0 Q15*/ ) { - tmp = L_mult( msNoiseFloor[j], msNoiseFloor[j] ); + tmp = Mpy_32_32( msNoiseFloor[j], msNoiseFloor[j] ); tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( msPsdSecondMoment[j], tmp, &s ); /* consider factor of 2 */ s = s_min( s_max( sub( s, 1 ), -( WORD16_BITS - 1 ) ), ( WORD16_BITS - 1 ) ); @@ -1586,7 +1643,7 @@ void minimum_statistics_fx( } } /* Get the current noise floor */ - Copy_Scale_sig_32_16( msCurrentMinOut, msNoiseFloor, len, -16 ); + Copy32( msCurrentMinOut, msNoiseFloor, len ); } ELSE /* sub window complete */ { @@ -1644,7 +1701,7 @@ void minimum_statistics_fx( set32_fx( msCurrentMin, 2147483647l /*1.0 Q31*/, len ); /* Get the current noise floor */ - Copy_Scale_sig_32_16( msCurrentMinOut, msNoiseFloor, len, -16 ); + Copy32( msCurrentMinOut, msNoiseFloor, len ); } } @@ -1701,18 +1758,19 @@ void minimum_statistics_fx( hFdCngCom->msFrCnt = add( hFdCngCom->msFrCnt, 1 ); move16(); } - + Word64 tmp64; /* Smooth noise estimate during CNG phases */ FOR( j = 0; j < len; j++ ) { - msNoiseEst[j] = round_fx( L_mac( L_mult( 31130 /*0.95 Q15*/, msNoiseEst[j] ), 1638 /*0.05 Q15*/, msNoiseFloor[j] ) ); - move16(); + tmp64 = W_add( W_mult_32_16( msNoiseEst[j], 31130 /*0.95 Q15*/ ), W_mult_32_16( msNoiseFloor[j], 1638 /*0.05 Q15*/ ) ); + msNoiseEst[j] = W_extract_h( W_shl( tmp64, 16 ) ); // Q25 + move32(); } } IF( EQ_16( enc_dec, DEC ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { // v_multc(msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING); - v_multc_att( msNoiseEst, 23142, msNoiseEst, NPART_SHAPING ); + v_multc_att32( msNoiseEst, 23142, msNoiseEst, NPART_SHAPING ); } /* Collect buffers */ Copy( msPeriodog, msPeriodogBuf + len * ( *msPeriodogBufPtr ), len ); @@ -1734,17 +1792,15 @@ void minimum_statistics_fx( { scalar = L_mac( scalar, msPeriodogBuf[i], 6554 /*1.0/MSBUFLEN Q15*/ ); } - scalar16 = round_fx( scalar ); - if ( GT_16( msNoiseEst[j], scalar16 ) /*0.0 Q15*/ ) + if ( GT_32( msNoiseEst[j], scalar ) /*0.0 Q15*/ ) { - msNoiseEst[j] = scalar16; - move16(); + msNoiseEst[j] = scalar; + move32(); } assert( msNoiseEst[j] >= 0 /*0.0 Q15*/ ); } } - /*------------------------------------------------------------------- * apply_scale() * diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 26999f048..b2df3a736 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5163,6 +5163,12 @@ void expand_range( Word16 *out_exp, const Word16 len ); +void expand_range_fx( + Word32 *in, // Q25 + Word32 *out, // exp:out_exp + Word16 *out_exp, + const Word16 len ); + void expand_range_var_exp( Word16 *in, Word16 in_exp, @@ -5198,8 +5204,8 @@ void minimum_statistics_fx( Word16 lenFFT, /* i : Number of FFT partitions */ Word16 *psize, /* i : Partition sizes, fractional */ Word16 *msPeriodog, /* i : Periodogram (energies) */ - Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ - Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ + Word32 *msNoiseFloor, /* i/o: Noise floors (energies) Q25*/ + Word32 *msNoiseEst, /* i/o: Noise estimates (energies) Q25*/ Word32 *msAlpha, /* i/o: Forgetting factors */ Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 99d202870..1d8185601 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -117,7 +117,7 @@ void initFdCngDec_ivas_fx( set16_fx( hFdCngDec->msPsd, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msPsd_fx, 0, NPART_SHAPING ); - set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); + set32_fx( hFdCngDec->msNoiseFloor_32fx, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); set16_fx( &hFdCngDec->msNoiseEst_exp, 0, 1 ); @@ -142,7 +142,7 @@ void initFdCngDec_ivas_fx( move16(); set16_fx( hFdCngDec->msLogPeriodog, 0, NPART_SHAPING ); - set16_fx( hFdCngDec->msLogNoiseEst, 0, NPART_SHAPING ); + set32_fx( hFdCngDec->msLogNoiseEst_32fx, 0, NPART_SHAPING ); set16_fx( hFdCngDec->psize_shaping, 0, NPART_SHAPING ); hFdCngDec->nFFTpart_shaping = 0; @@ -2231,8 +2231,8 @@ void perform_noise_estimation_dec_ivas_fx( nFFTpart, psize_norm, hFdCngDec->msLogPeriodog, - hFdCngDec->msNoiseFloor, - hFdCngDec->msLogNoiseEst, + hFdCngDec->msNoiseFloor_32fx, + hFdCngDec->msLogNoiseEst_32fx, hFdCngDec->msAlpha, hFdCngDec->msPsd, hFdCngDec->msPsdFirstMoment, @@ -2259,7 +2259,7 @@ void perform_noise_estimation_dec_ivas_fx( move16(); /* Expand MS outputs */ - expand_range( hFdCngDec->msLogNoiseEst, hFdCngDec->msNoiseEst, &hFdCngDec->msNoiseEst_exp, npart ); + expand_range_fx( hFdCngDec->msLogNoiseEst_32fx, hFdCngDec->msNoiseEst, &hFdCngDec->msNoiseEst_exp, npart ); } } diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index fcd5142a4..4e4e33c36 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -94,11 +94,13 @@ typedef struct Word16 msPsdFirstMoment[NPART_SHAPING]; Word32 msPsdSecondMoment[NPART_SHAPING]; - Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ - Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ + Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ + Word32 msNoiseFloor_32fx[NPART_SHAPING]; /* IVAS: Estimated noise floor Q25*/ + Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ Word16 msNoiseEst_exp; Word16 msLogPeriodog[NPART_SHAPING]; Word16 msLogNoiseEst[NPART_SHAPING]; + Word32 msLogNoiseEst_32fx[NPART_SHAPING]; /*IVAS: Q25*/ Word16 npart_shaping; /* Number of partitions */ Word16 nFFTpart_shaping; /* Number of hybrid spectral partitions */ diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index a8612725b..887b4afb8 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -358,7 +358,7 @@ void encod_unvoiced_ivas_fx( // E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate, st_fx->element_mode ); inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, - UNVOICED, st_fx->bwidth, st_fx->sharpFlag, i_subfr, -1, p_Aq_fx, + UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx, gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn ); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index a7339e653..fe5839565 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -130,8 +130,10 @@ void initFdCngEnc_fx( move16(); set16_fx( hsEnc->msLogPeriodog_fx, 0, NPART ); set16_fx( hsEnc->msLogNoiseEst_fx, 0, NPART ); + set32_fx( hsEnc->msLogNoiseEst_32fx, 0, NPART ); set16_fx( hsEnc->msPsd_fx, 0, NPART ); set16_fx( hsEnc->msNoiseFloor_fx, 0, NPART ); + set32_fx( hsEnc->msNoiseFloor_32fx, 0, NPART ); set32_fx( hsEnc->msMinBuf_fx, 2147483647l /*1.0 Q31*/, MSNUMSUBFR * NPART ); set32_fx( hsEnc->msCurrentMin_fx, 2147483647l /*1.0 Q31*/, NPART ); set32_fx( hsEnc->msCurrentMinOut_fx, 2147483647l /*1.0 Q31*/, NPART ); @@ -2240,12 +2242,12 @@ void perform_noise_estimation_enc_ivas_fx( Word16 nCLDFBpart = hFdCngEnc->hFdCngCom->nCLDFBpart; /* Q0 */ move16(); - Word16 *psize = hFdCngEnc->hFdCngCom->psize; // 6Q9 + Word16 *psize_norm = hFdCngEnc->hFdCngCom->psize_norm; // 6Q9 Word32 *msPeriodog_fx = hFdCngEnc->msPeriodog_fx; Word32 *msNoiseEst_fx = hFdCngEnc->msNoiseEst_fx; /* exp(msNoiseEst_fx_exp) */ Word16 *msLogPeriodog_fx = hFdCngEnc->msLogPeriodog_fx; - Word16 *msLogNoiseEst_fx = hFdCngEnc->msLogNoiseEst_fx; + Word32 *msLogNoiseEst_fx = hFdCngEnc->msLogNoiseEst_32fx; Word32 scaleEB_fx = 0; move32(); @@ -2387,12 +2389,12 @@ void perform_noise_estimation_enc_ivas_fx( /* Call the minimum statistics routine for noise estimation */ - minimum_statistics_fx( npart, nFFTpart, psize, msLogPeriodog_fx, hFdCngEnc->msNoiseFloor_fx, msLogNoiseEst_fx, hFdCngEnc->msAlpha_fx, hFdCngEnc->msPsd_fx, hFdCngEnc->msPsdFirstMoment_fx, + minimum_statistics_fx( npart, nFFTpart, psize_norm, msLogPeriodog_fx, hFdCngEnc->msNoiseFloor_32fx, msLogNoiseEst_fx, hFdCngEnc->msAlpha_fx, hFdCngEnc->msPsd_fx, hFdCngEnc->msPsdFirstMoment_fx, hFdCngEnc->msPsdSecondMoment_fx, hFdCngEnc->msMinBuf_fx, hFdCngEnc->msBminWin_fx, hFdCngEnc->msBminSubWin_fx, hFdCngEnc->msCurrentMin_fx, hFdCngEnc->msCurrentMinOut_fx, hFdCngEnc->msCurrentMinSubWindow_fx, hFdCngEnc->msLocalMinFlag, hFdCngEnc->msNewMinFlag, hFdCngEnc->msPeriodogBuf_fx, &( hFdCngEnc->msPeriodogBufPtr ), hFdCngEnc->hFdCngCom, ENC, ( hCPE == NULL ) ? 0 : hCPE->element_mode ); /* Expand MS outputs */ - expand_range( msLogNoiseEst_fx, msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart ); + expand_range_fx( msLogNoiseEst_fx, msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart ); return; } diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 18995bd1d..91e1b8520 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -521,7 +521,7 @@ static void IGF_CalculateEnvelope_ivas_fx( { IF( LT_32( 1, pPowerSpectrum_fx[sb] ) ) { - hPrivateData->logSpec[sb] = s_max( 0, (Word16) L_shr( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( e_ps[sb], Q25 ) ), Q25 ) ); + hPrivateData->logSpec[sb] = s_max( 0, extract_l( W_extract_l( W_shr( W_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), W_shl( e_ps[sb], Q25 ) ), Q25 ) ) ) ); move16(); } ELSE diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index b9c515eea..2fbec12bd 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -381,8 +381,9 @@ typedef struct fd_cng_enc_structure Word16 msNewMinFlag[NPART]; Word16 msPsdFirstMoment_fx[NPART]; Word32 msPsdSecondMoment_fx[NPART]; - Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ - Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ + Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ + Word32 msNoiseFloor_32fx[NPART]; /* Estimated noise floor IVAS: Q25*/ + Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ Word16 msNoiseEst_fx_exp; Word32 energy_ho_fx[NPART]; Word16 energy_ho_fx_exp; @@ -399,6 +400,7 @@ typedef struct fd_cng_enc_structure Word16 partDec[NPART]; Word16 msLogPeriodog_fx[NPART]; Word16 msLogNoiseEst_fx[NPART]; + Word32 msLogNoiseEst_32fx[NPART]; /*IVAS: Q25*/ Word32 mem_coherence_fx[4]; Word16 mem_coherence_exp[4]; -- GitLab From 41ab0d527dbb7945e032f20c3cca6170435bb11c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 29 May 2025 15:53:53 +0530 Subject: [PATCH 15/54] Fix for 3GPP issue 1720: Memory allocation in ivas_dirac_dec_output_synthesis_process_slot_fx() Link #1720 --- lib_rend/ivas_dirac_output_synthesis_dec_fx.c | 51 +++++++++++-------- lib_rend/ivas_stat_rend.h | 2 + 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c index 622ebf89a..872d89c34 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c @@ -200,6 +200,12 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } dirac_output_synthesis_state->cy_cross_dir_smooth_prev_len = size; move16(); + + IF( ( dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx = NULL; @@ -609,6 +615,11 @@ void ivas_dirac_dec_output_synthesis_close_fx( free( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev_fx ); ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev_fx = NULL; } + IF( ( dirac_output_synthesis_state )->Q_temp_cy_cross_dir_smooth_fx != NULL ) + { + free( ( dirac_output_synthesis_state )->Q_temp_cy_cross_dir_smooth_fx ); + ( dirac_output_synthesis_state )->Q_temp_cy_cross_dir_smooth_fx = NULL; + } IF( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev_fx != NULL ) { free( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev_fx ); @@ -818,13 +829,10 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( num_freq_bands ); /*h_dirac_output_synthesis_state->diffuse_power_factor_q+Q31-Q31->h_dirac_output_synthesis_state->diffuse_power_factor_q*/ /*Direct gain*/ - - Word16 *Q_temp_cy_cross_dir_smooth_fx = (Word16 *) malloc( num_freq_bands * num_channels_dir * sizeof( Word16 ) ); - tmp16 = imult1616( num_freq_bands, num_channels_dir ); FOR( Word16 kk = 0; kk < tmp16; kk++ ) { - Q_temp_cy_cross_dir_smooth_fx[kk] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[kk] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } @@ -901,13 +909,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth-> (31-sqr_exp) */ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*( 31- sqr_exp )-> h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx*/ @@ -917,7 +925,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*31-sqr_exp*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -969,13 +977,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q(31- sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ @@ -985,7 +993,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -1051,13 +1059,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q(31- sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ @@ -1067,7 +1075,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -1092,13 +1100,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q(31-sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ @@ -1108,7 +1116,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -1125,13 +1133,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*Q( 31- sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ @@ -1141,7 +1149,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); + h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -1152,16 +1160,15 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( tmp16 = imult1616( num_freq_bands, num_channels_dir ); FOR( Word16 kk = 0; kk < tmp16; kk++ ) { - temp = s_min( Q_temp_cy_cross_dir_smooth_fx[kk], temp ); + temp = s_min( h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[kk], temp ); } h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp; move16(); FOR( Word16 kk = 0; kk < tmp16; kk++ ) { - h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, Q_temp_cy_cross_dir_smooth_fx[kk] ) ); /*Q_temp_cy_cross_dir_smooth_fx[kk]->temp*/ + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, h_dirac_output_synthesis_state->Q_temp_cy_cross_dir_smooth_fx[kk] ) ); /*Q_temp_cy_cross_dir_smooth_fx[kk]->temp*/ move32(); } - free( Q_temp_cy_cross_dir_smooth_fx ); /*Directional gain (panning)*/ Word16 temp_q = sub( add( h_dirac_output_synthesis_state->direct_power_factor_q, h_dirac_output_synthesis_state->direct_responses_q ), 31 ); IF( LT_16( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index a13ee27e7..00fbc2549 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -352,6 +352,8 @@ typedef struct dirac_output_synthesis_state_structure Word16 q_cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ Word16 q_cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + Word16 *Q_temp_cy_cross_dir_smooth_fx; + Word16 cy_auto_dir_smooth_len; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ Word16 cy_cross_dir_smooth_len; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ Word16 cy_auto_diff_smooth_len; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ -- GitLab From f602e97871c026176fa68e63304c08a248a1de68 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 30 May 2025 15:42:13 +0530 Subject: [PATCH 16/54] Precision improvements for lp_noise, totalNoise; saturation resolution for non_staX --- lib_com/cnst.h | 1 + lib_com/ivas_prot_fx.h | 4 +-- lib_enc/bw_detect_fx.c | 13 +++++++- lib_enc/dtx_fx.c | 8 ++--- lib_enc/fd_cng_enc_fx.c | 12 +++++-- lib_enc/find_uv_fx.c | 6 ++-- lib_enc/init_enc_fx.c | 6 ++-- lib_enc/ivas_core_pre_proc_front_fx.c | 28 ++++++++-------- lib_enc/ivas_core_pre_proc_fx.c | 2 +- lib_enc/ivas_front_vad_fx.c | 11 +++---- lib_enc/ivas_ism_dtx_enc_fx.c | 2 +- lib_enc/ivas_ism_metadata_enc_fx.c | 2 +- lib_enc/ivas_masa_enc_fx.c | 4 +-- lib_enc/ivas_omasa_enc_fx.c | 2 +- lib_enc/ivas_stereo_classifier_fx.c | 2 +- lib_enc/ivas_stereo_td_analysis_fx.c | 2 +- lib_enc/ivas_tcx_core_enc_fx.c | 4 +-- lib_enc/long_enr_fx.c | 44 ++++++++++++------------- lib_enc/nois_est_fx.c | 47 ++++++++++++++++++--------- lib_enc/prot_fx_enc.h | 13 ++++++-- lib_enc/speech_music_classif_fx.c | 6 ++-- lib_enc/stat_enc.h | 13 +++++--- lib_enc/vad_fx.c | 4 +-- 23 files changed, 140 insertions(+), 96 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 7b204a8e2..a2d051d87 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -759,6 +759,7 @@ enum #define PIT_FIR_SIZE6_2 ( PIT_UP_SAMP6 * PIT_L_INTERPOL6_2 + 1 ) #define E_MIN 0.0035f /* minimum allowable energy */ #define E_MIN_Q11_FX 7 /* minimum allowable energy in Q11*/ +#define E_MIN_Q27_FX 469762 /* minimum allowable energy in Q27*/ #define STEP_DELTA 0.0625f /* quantization step for tilt compensation of gaussian cb. excitation */ #define GAMMA_EV 0.92f /* weighting factor for core synthesis error weighting */ #define FORMANT_SHARPENING_NOISE_THRESHOLD 21.0f /* lp_noise level above which formant sharpening is deactivated */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 928736427..d9ca855be 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2960,7 +2960,7 @@ Word16 ivas_acelp_tcx20_switching_fx( Word16 *inp_fx, /* i : new input signal */ Word16 q_inp, /* i : i/p Q */ Word16 *wsp, /* i : input weighted signal */ - Word16 non_staX, /* i : unbound non-stationarity for sp/mu clas */ + Word32 non_staX, /* i : unbound non-stationarity for sp/mu clas */ Word16 *pitch_fr, /* i : fraction pitch values */ Word16 *voicing_fr, /* i : fractional voicing values */ Word32 currFlatness, /* i : flatness */ @@ -3984,7 +3984,7 @@ Word16 ivas_smc_gmm_fx( const Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) Q8 */ const Word32 epsP_fx[M + 1], /* i : LP prediciton error */ const Word32 PS_fx[], /* i : energy spectrum */ - const Word16 non_sta_fx, /* i : unbound non-stationarity Q8 */ + const Word32 non_sta_fx, /* i : unbound non-stationarity Q20 */ const Word16 relE_fx, /* i : relative frame energy Q8 */ Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ const Word16 flag_spitch, /* i : flag to indicate very short stable pitch */ diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 050adbf01..94ed49129 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -71,6 +71,7 @@ void bw_detect_fx( Flag Overflow = 0; move32(); #endif + Word16 lp_noise_fx; bwd_count_wider_bw = BWD_COUNT_WIDER_BW; move16(); @@ -532,7 +533,17 @@ void bw_detect_fx( /*if( localVAD || st->lp_noise > 30 )*/ test(); - IF( st->localVAD || GT_16( st->lp_noise_fx, 7680 /*30 in Q8*/ ) ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + lp_noise_fx = st->lp_noise_fx; + move16(); + } + ELSE + { + lp_noise_fx = extract_h( st->lp_noise_32fx ); + } + + IF( st->localVAD || GT_32( ( lp_noise_fx ), 7680 /*30 in Q8*/ ) ) { /*st->lt_mean_NB_fx = ALPHA_BWD * st->lt_mean_NB_fx + (1-ALPHA_BWD) * mean_NB;*/ L_tmp = L_mult( ALPHA_BWD_FX, st->lt_mean_NB_fx ); /* Q15 * Q11 -> Q27 */ diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 6d8a29795..7966fc7d8 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -95,7 +95,7 @@ void dtx_ivas_fx( test(); test(); test(); - last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) ); + last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) ); test(); test(); @@ -103,7 +103,7 @@ void dtx_ivas_fx( last_br_flag = ( st_fx->element_mode == EVS_MONO && LE_32( st_fx->last_total_brate, MAX_BRATE_DTX_EVS ) ) || ( st_fx->element_mode != EVS_MONO && LE_32( last_ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || - LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ); + LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ); } /* Initialization */ @@ -211,7 +211,7 @@ void dtx_ivas_fx( test(); br_dtx_flag = ( ( st_fx->element_mode == EVS_MONO ) && LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) ) || ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || - LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ); + LT_16( extract_h( st_fx->lp_noise_32fx ), DTX_THR * 256 ); } test(); test(); @@ -403,7 +403,7 @@ void dtx_ivas_fx( st_fx->cng_type = FD_CNG; move16(); } - ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( LT_32( st_fx->bckr_tilt_lt, fd_thresh ) ) && ( GT_16( st_fx->lp_noise_fx, 512 /* 2 in Q8 */ ) ) ) + ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( LT_32( st_fx->bckr_tilt_lt, fd_thresh ) ) && ( GT_32( st_fx->lp_noise_32fx, 67108864 /* 2 in Q24 */ ) ) ) { st_fx->cng_type = LP_CNG; move16(); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index fe5839565..9298c8634 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -447,8 +447,16 @@ void resetFdCngEnc_fx( /* st->totalNoise_fx; Q8 Noise estimator - total noise energy */ /* Detect fast increase of totalNoise */ - totalNoiseIncrease = sub( hNoiseEst->totalNoise_fx, st->last_totalNoise_fx ); // Q8 - st->last_totalNoise_fx = hNoiseEst->totalNoise_fx; // Q8 + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + totalNoiseIncrease = sub( hNoiseEst->totalNoise_fx, st->last_totalNoise_fx ); // Q8 + st->last_totalNoise_fx = hNoiseEst->totalNoise_fx; // Q8 + } + ELSE + { + totalNoiseIncrease = sub( extract_h( hNoiseEst->totalNoise_32fx ), st->last_totalNoise_fx ); // Q8 + st->last_totalNoise_fx = extract_h( hNoiseEst->totalNoise_32fx ); // Q8 + } move16(); IF( totalNoiseIncrease > 0 ) { diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index c4fe2e895..61de9ca7d 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -853,11 +853,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ IF( st_fx->input_bwidth != NB ) { /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */ - L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, st_fx->lp_noise_fx ); // Q24 + L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 IF( Last_Resort == 0 ) { /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, st_fx->lp_noise_fx ); // Q24 + L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 } relE_thres = round_fx( L_tmp ); } @@ -865,7 +865,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ { /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, st_fx->lp_noise_fx ); // Q24 + L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 relE_thres = round_fx( L_tmp ); } relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */ diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 543a6fab9..ba1d47f79 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1572,9 +1572,9 @@ ivas_error init_encoder_ivas_fx( * DTX *-----------------------------------------------------------------*/ - st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ - move16(); - st->lp_noise_fx = 0; + st->lp_speech_32fx = 754974720; /*Q24 (45.0) */ /* Initialize the long-term active speech level in dB */ + move32(); + st->lp_noise_32fx = 0; move16(); st->flag_noisy_speech_snr = 0; move16(); diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 3e7bf2464..fbd207e26 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -158,7 +158,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 high_lpn_flag; Word16 lsf_new_fx[M]; // Q2.56 Word16 localVAD_HE_SAD; - Word16 non_staX_fx; + Word32 non_staX_fx; Word16 alw_pitch_lag_12k8[2]; Word16 alw_voicing_fx[2]; Word16 last_core_orig; @@ -191,7 +191,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 ncharX_fx; Word16 ncharX_LR_fx; /* noise character for sp/mus classifier */ Word16 loc_harmLR_fx[CPE_CHANNELS]; /* harmonicity flag */ - Word16 non_staX_LR_fx; /* non-stationarity for sp/mus classifier */ + Word32 non_staX_LR_fx; /* non-stationarity for sp/mus classifier */ Word16 sp_div_fx; Word16 q_sp_div; Word16 sp_div_LR_fx; @@ -742,7 +742,7 @@ ivas_error pre_proc_front_ivas_fx( IF( hStereoClassif != NULL ) { - IF( GT_32( sub( st->lp_speech_fx, extract_h( Etot_fx ) ), 25 << Q8 ) ) /*Q8*/ + IF( GT_32( L_sub( st->lp_speech_32fx, Etot_fx ), 25 << Q24 ) ) /*Q8*/ { hStereoClassif->silence_flag = 2; move16(); @@ -806,7 +806,7 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( ( hCPE != NULL && !( lr_vad_enabled && st->idchan == 0 ) ) || hSCE != NULL ) { - *vad_flag_dtx = ivas_dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, vad_hover_flag, NULL, NULL, NULL ); /* Q0 */ + *vad_flag_dtx = ivas_dtx_hangover_addition_fx( st, st->vad_flag, extract_h( L_sub( st->lp_speech_32fx, st->lp_noise_32fx ) ), 0, vad_hover_flag, NULL, NULL, NULL ); /* Q0 */ move16(); } ELSE @@ -904,21 +904,21 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ noise_est_down_ivas_fx( fr_bands_fx, fr_bands_fx_q, st->hNoiseEst->bckr_fx, &st->hNoiseEst->q_bckr, tmpN_fx, &q_tmpN, tmpE_fx, &q_tmpE, st->min_band, st->max_band, - &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_32fx, &st->hNoiseEst->Etot_v_h2_32fx ); + &st->hNoiseEst->totalNoise_32fx, Etot_fx, &st->hNoiseEst->Etot_last_32fx, &st->hNoiseEst->Etot_v_h2_32fx ); test(); IF( lr_vad_enabled && st->idchan == 0 ) { - noise_est_down_ivas_fx( fr_bands_LR_fx[0], fr_bands_LR_fx_q[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[0]->hNoiseEst->q_bckr, tmpN_LR_fx[0], &q_tmpN_LR[0], tmpE_LR_fx[0], &q_tmpE_LR[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_LR_fx[0] ), &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_32fx ); - noise_est_down_ivas_fx( fr_bands_LR_fx[1], fr_bands_LR_fx_q[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[1]->hNoiseEst->q_bckr, tmpN_LR_fx[1], &q_tmpN_LR[1], tmpE_LR_fx[1], &q_tmpE_LR[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_LR_fx[1] ), &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_32fx ); + noise_est_down_ivas_fx( fr_bands_LR_fx[0], fr_bands_LR_fx_q[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[0]->hNoiseEst->q_bckr, tmpN_LR_fx[0], &q_tmpN_LR[0], tmpE_LR_fx[0], &q_tmpE_LR[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_32fx, L_deposit_h( Etot_LR_fx[0] ), &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_32fx ); + noise_est_down_ivas_fx( fr_bands_LR_fx[1], fr_bands_LR_fx_q[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, &hCPE->hFrontVad[1]->hNoiseEst->q_bckr, tmpN_LR_fx[1], &q_tmpN_LR[1], tmpE_LR_fx[1], &q_tmpE_LR[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_32fx, L_deposit_h( Etot_LR_fx[1] ), &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_32fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_32fx ); - corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx ); // Q15 - corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx ); // Q15 + corr_shiftL_fx = correlation_shift_fx( extract_h( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_32fx ) ); // Q15 + corr_shiftR_fx = correlation_shift_fx( extract_h( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_32fx ) ); // Q15 } - *relE_fx = sub( extract_h( Etot_fx ), st->lp_speech_fx ); // Q8 + *relE_fx = sub( extract_h( Etot_fx ), extract_h( st->lp_speech_32fx ) ); // Q8 move16(); - corr_shift_fx = correlation_shift_fx( st->hNoiseEst->totalNoise_fx ); /* Q15 */ + corr_shift_fx = correlation_shift_fx( extract_h( st->hNoiseEst->totalNoise_32fx ) ); /* Q15 */ /*----------------------------------------------------------------* * FD-CNG Noise Estimator @@ -1397,7 +1397,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); stereo_classifier_features_ivas_fx( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new_fx, epsP_fx, st->pitch, st->voicing_fx, *cor_map_sum_fx, non_staX_fx, sp_div_fx, - st->clas, sub( 31, *epsP_fx_q ), ( 31 - Q8 ) /* exp of cor_map_sum */, ( 31 - Q8 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); + st->clas, sub( 31, *epsP_fx_q ), ( 31 - Q8 ) /* exp of cor_map_sum */, ( 31 - Q20 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); } /*----------------------------------------------------------------* @@ -1443,7 +1443,7 @@ ivas_error pre_proc_front_ivas_fx( * Update of old per-band energy spectrum *----------------------------------------------------------------*/ - ivas_long_enr_fx( st, extract_h( Etot_fx ), localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); + ivas_long_enr_fx( st, Etot_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); Copy32( fr_bands_fx + NB_BANDS, st->hNoiseEst->enrO_fx, NB_BANDS ); /* fr_bands_fx_q */ st->hNoiseEst->q_enrO = fr_bands_fx_q; @@ -1452,7 +1452,7 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( lr_vad_enabled && st->idchan == 0 ) { - ivas_long_enr_fx( st, -256 /*-1 q8*/, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR_fx ); + ivas_long_enr_fx( st, -16777216 /*-1 << 24*/, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR_fx ); Copy32( fr_bands_LR_fx[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO_fx, NB_BANDS ); // fr_bands_LR_fx_q hCPE->hFrontVad[0]->hNoiseEst->q_enrO = fr_bands_LR_fx_q[0]; diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 938ab9964..623b38e68 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -462,7 +462,7 @@ ivas_error pre_proc_ivas_fx( IF( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, TRANSITION ) ) { test(); - IF( GE_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) && GT_16( st->lp_noise_fx, FORMANT_SHARPENING_NOISE_THRESHOLD_FX ) ) + IF( GE_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) && GT_32( st->lp_noise_32fx, FORMANT_SHARPENING_NOISE_THRESHOLD_FX << 16 ) ) { st->sharpFlag = 0; move16(); diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index a6054a841..963e363b2 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -492,7 +492,7 @@ ivas_error front_vad_spar_fx( Word16 sp_div_fx; Word16 Q_sp_div; - Word16 non_staX_fx; + Word32 non_staX_fx; Word16 sp_floor; Word16 cor_map_sum_fx; @@ -603,9 +603,9 @@ ivas_error front_vad_spar_fx( Word16 q_tmpN, q_tmpE; noise_est_down_ivas_fx( fr_bands_fx[0], q_fr_bands[0], hFrontVad->hNoiseEst->bckr_fx, &hFrontVad->hNoiseEst->q_bckr, tmpN_fx, &q_tmpN, tmpE_fx, &q_tmpE, st->min_band, st->max_band, - &hFrontVad->hNoiseEst->totalNoise_fx, L_deposit_h( Etot_fx[0] ) /*q8->q24*/, &hFrontVad->hNoiseEst->Etot_last_32fx, &hFrontVad->hNoiseEst->Etot_v_h2_32fx ); + &hFrontVad->hNoiseEst->totalNoise_32fx, L_deposit_h( Etot_fx[0] ) /*q8->q24*/, &hFrontVad->hNoiseEst->Etot_last_32fx, &hFrontVad->hNoiseEst->Etot_v_h2_32fx ); - corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); /* Q15 */ + corr_shift_fx = correlation_shift_fx( extract_h( hFrontVad->hNoiseEst->totalNoise_32fx ) ); /* Q15 */ dtx_ivas_fx( st, hEncoderConfig->last_ivas_total_brate, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); @@ -637,7 +637,7 @@ ivas_error front_vad_spar_fx( move32(); } - relE_fx = sub( Etot_fx[0], st->lp_speech_fx ); + relE_fx = sub( Etot_fx[0], extract_h( st->lp_speech_32fx ) ); Scale_sig( A_fx, ( L_FRAME / L_SUBFR ) * ( M + 1 ), -2 ); // Q12 st->mem_wsp_fx = (Word16) shl_sat( st->mem_wsp_fx, Q_inp_12k8 - st->mem_wsp_q ); /* Q_inp_12k8 */ @@ -749,13 +749,12 @@ ivas_error front_vad_spar_fx( /* 1st stage speech/music classification (GMM model) */ /* run only to get 'high_lpn_flag' parameter */ SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; - Word16 non_sta_fx = shr( non_staX_fx, Q2 ); // Q8->Q6 Word16 Etot_fx_0 = Etot_fx[0]; move16(); scale = getScaleFactor32( PS_fx, 128 ); Qfact_PS = add( Qfact_PS, scale ); Scale_sig32( PS_fx, 128, scale ); - ivas_smc_gmm_fx( st, NULL, localVAD_HE_SAD[0], Etot_fx_0, lsp_new_fx, cor_map_sum_fx, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, hSpMusClas->past_PS_Q ); + ivas_smc_gmm_fx( st, NULL, localVAD_HE_SAD[0], Etot_fx_0, lsp_new_fx, cor_map_sum_fx, epsP_fx, PS_fx, non_staX_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, hSpMusClas->past_PS_Q ); /* long-term energy update */ ivas_long_enr_fx( st, -256 /*-1 q8*/, localVAD_HE_SAD[0], high_lpn_flag, &hFrontVad, 1, localVAD_HE_SAD, Etot_fx ); diff --git a/lib_enc/ivas_ism_dtx_enc_fx.c b/lib_enc/ivas_ism_dtx_enc_fx.c index b06acfbac..bc2c83de1 100644 --- a/lib_enc/ivas_ism_dtx_enc_fx.c +++ b/lib_enc/ivas_ism_dtx_enc_fx.c @@ -143,7 +143,7 @@ Word16 ivas_ism_dtx_enc_fx( /* one of the channels is active -> no DTX */ FOR( ch = 0; ch < nchan_transport; ch++ ) { - lp_noise_fx[ch] = hSCE[ch]->hCoreCoder[0]->lp_noise_fx; /*Q8*/ + lp_noise_fx[ch] = extract_h( hSCE[ch]->hCoreCoder[0]->lp_noise_32fx ); /*Q8*/ move16(); } diff --git a/lib_enc/ivas_ism_metadata_enc_fx.c b/lib_enc/ivas_ism_metadata_enc_fx.c index 1efbb2123..594871b29 100644 --- a/lib_enc/ivas_ism_metadata_enc_fx.c +++ b/lib_enc/ivas_ism_metadata_enc_fx.c @@ -277,7 +277,7 @@ ivas_error ivas_ism_metadata_enc_fx( /* In case of low level noise for low bitrate inactive frames, do not sent metadata */ test(); test(); - hIsmMeta[ch]->ism_metadata_flag = vad_flag[ch] || GT_16( hSCE[ch]->hCoreCoder[0]->lp_noise_fx, 2560 /*10 Q8*/ ) || hSCE[ch]->hCoreCoder[0]->tcxonly; + hIsmMeta[ch]->ism_metadata_flag = vad_flag[ch] || GT_32( hSCE[ch]->hCoreCoder[0]->lp_noise_32fx, 167772160 /*10 Q24*/ ) || hSCE[ch]->hCoreCoder[0]->tcxonly; move16(); } diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 9d0579d12..303d11698 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -1195,12 +1195,12 @@ ivas_error ivas_masa_enc_config_fx( test(); IF( EQ_16( st_ivas->hCPE[0]->element_mode, IVAS_CPE_DFT ) || LT_16( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ) ) { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx; /*Q8*/ + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = extract_h( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_32fx ); /*Q8*/ } ELSE { /* ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; */ - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = extract_h( L_mac( L_mult( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx, ONE_IN_Q14 ), st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise_fx, ONE_IN_Q14 ) ); /*Q8*/ + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = extract_h( L_mac( L_mult( extract_h( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_32fx ), ONE_IN_Q14 ), extract_h( st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise_32fx ), ONE_IN_Q14 ) ); /*Q8*/ } move16(); } diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index b5b592582..b88bb69a1 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -795,7 +795,7 @@ void ivas_set_ism_importance_interformat_fx( IF( active_flag == 0 ) { test(); - if ( GT_16( st->lp_noise_fx, 3840 /* 15 in Q8 */ ) || LT_16( sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /* 30 in Q8 */ ) ) + if ( GT_32( st->lp_noise_32fx, 251658240 /* 15 in Q24 */ ) || LT_16( sub( lp_noise_CPE_fx, extract_h( st->lp_noise_32fx ) ), 7680 /* 30 in Q8 */ ) ) { active_flag = 1; move16(); diff --git a/lib_enc/ivas_stereo_classifier_fx.c b/lib_enc/ivas_stereo_classifier_fx.c index 3a040517a..2c1bc0317 100644 --- a/lib_enc/ivas_stereo_classifier_fx.c +++ b/lib_enc/ivas_stereo_classifier_fx.c @@ -1507,7 +1507,7 @@ void xtalk_classifier_dft_fx( hStereoClassif->xtalk_decision = 1; move16(); } - ELSE IF( GE_32( hCPE->element_brate, IVAS_16k4 ) && hStereoClassif->xtalk_decision == 0 && GT_16( abs_s( itd ), STEREO_DFT_ITD_MAX ) && GT_16( sub( hCPE->hCoreCoder[0]->lp_speech_fx, hCPE->hCoreCoder[0]->lp_noise_fx ), 25 << 8 ) ) + ELSE IF( GE_32( hCPE->element_brate, IVAS_16k4 ) && hStereoClassif->xtalk_decision == 0 && GT_16( abs_s( itd ), STEREO_DFT_ITD_MAX ) && GT_32( L_sub( hCPE->hCoreCoder[0]->lp_speech_32fx, hCPE->hCoreCoder[0]->lp_noise_32fx ), 25 << 24 ) ) { hStereoClassif->xtalk_decision = 1; move16(); diff --git a/lib_enc/ivas_stereo_td_analysis_fx.c b/lib_enc/ivas_stereo_td_analysis_fx.c index 909d0c206..de47ea8e2 100644 --- a/lib_enc/ivas_stereo_td_analysis_fx.c +++ b/lib_enc/ivas_stereo_td_analysis_fx.c @@ -564,7 +564,7 @@ Word16 stereo_tdm_ener_analysis_fx( } } - IF( LT_16( sub( sts[1]->lp_speech_fx, sts[1]->lp_noise_fx ), 12800 /*50.0f in Q8*/ ) ) /* likely presence of noisy content */ + IF( LT_32( L_sub( sts[1]->lp_speech_32fx, sts[1]->lp_noise_32fx ), 838860800 /*50.0f in Q24*/ ) ) /* likely presence of noisy content */ { /* pointing in the right direction, inverse it else do nothing */ test(); diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index 5f2e9a8e0..da141f473 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -715,7 +715,7 @@ Word16 ivas_acelp_tcx20_switching_fx( Word16 *inp_fx, Word16 q_inp, Word16 *wsp, /*q_inp i : input weighted signal */ - Word16 non_staX, /*Q8 i : unbound non-stationarity for sp/mu clas*/ + Word32 non_staX, /*Q20 i : unbound non-stationarity for sp/mu clas*/ Word16 *pitch_fr, /*Q6 i : fraction pitch values */ Word16 *voicing_fr, /*Q15 i : fractional voicing values */ Word32 currFlatness, /*Q21 i : flatness */ @@ -1276,7 +1276,7 @@ Word16 ivas_acelp_tcx20_switching_fx( test(); test(); test(); - if ( ( !flag_16k_smc ) && ( LT_32( offset_tcx, 0x18950F ) ) && GT_16( non_staX, 1280 /*5.0f Q8*/ ) && ( GE_32( snr_acelp, L_sub( tcx_snr, 262144 /*4.0f in Q16*/ ) ) ) && GE_16( st->Nb_ACELP_frames, 1 ) && ( ( GT_16( st->hSpMusClas->lps_fx, st->hSpMusClas->lpm_fx ) && GE_32( mean_voicing_fr, /* 0.3 in Q30 */ 322122547 ) ) || ( GE_16( st->Nb_ACELP_frames, 6 ) && GT_16( st->hSpMusClas->lps_fx, sub( st->hSpMusClas->lpm_fx, 192 /*1.5in Q7*/ ) ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag ) + if ( ( !flag_16k_smc ) && ( LT_32( offset_tcx, 0x18950F ) ) && GT_32( non_staX, 5242880 /*5.0f Q20*/ ) && ( GE_32( snr_acelp, L_sub( tcx_snr, 262144 /*4.0f in Q16*/ ) ) ) && GE_16( st->Nb_ACELP_frames, 1 ) && ( ( GT_16( st->hSpMusClas->lps_fx, st->hSpMusClas->lpm_fx ) && GE_32( mean_voicing_fr, /* 0.3 in Q30 */ 322122547 ) ) || ( GE_16( st->Nb_ACELP_frames, 6 ) && GT_16( st->hSpMusClas->lps_fx, sub( st->hSpMusClas->lpm_fx, 192 /*1.5in Q7*/ ) ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag ) { /* Fine tuned across various databases based on various metrics to detect TCX frames in speech.*/ dsnr = 262144; /*4.0f Q16*/ diff --git a/lib_enc/long_enr_fx.c b/lib_enc/long_enr_fx.c index 60c40b3fe..93918b81e 100644 --- a/lib_enc/long_enr_fx.c +++ b/lib_enc/long_enr_fx.c @@ -17,7 +17,7 @@ *-------------------------------------------------------------------*/ void ivas_long_enr_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q8 */ + const Word32 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q24 */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover Q0*/ Word16 high_lpn_flag, /* i : sp/mus LPN flag Q0*/ FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ @@ -28,7 +28,7 @@ void ivas_long_enr_fx( ) { Word16 tmp; - Word16 alpha; + Word32 alpha; NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; /*-----------------------------------------------------------------* @@ -42,7 +42,7 @@ void ivas_long_enr_fx( { FOR( n = 0; n < n_chan; n++ ) { - hFrontVad[n]->lp_noise_fx = hFrontVad[n]->hNoiseEst->totalNoise_fx; /* Q8 */ + hFrontVad[n]->lp_noise_fx = extract_h( hFrontVad[n]->hNoiseEst->totalNoise_32fx ); /* Q8 */ move16(); tmp = add( hFrontVad[n]->lp_noise_fx, 2560 ); /* Q8 */ @@ -74,7 +74,7 @@ void ivas_long_enr_fx( FOR( n = 0; n < n_chan; n++ ) { - hFrontVad[n]->lp_noise_fx = add( mult_r( smooth_prev, hFrontVad[n]->lp_noise_fx ), mult_r( smooth_curr, hFrontVad[n]->hNoiseEst->totalNoise_fx ) ); /* Q8 */ + hFrontVad[n]->lp_noise_fx = add( mult_r( smooth_prev, hFrontVad[n]->lp_noise_fx ), mult_r( smooth_curr, extract_h( hFrontVad[n]->hNoiseEst->totalNoise_32fx ) ) ); /* Q8 */ move16(); test(); IF( localVAD_HE_SAD_LR[n] && !high_lpn_flag ) @@ -102,11 +102,11 @@ void ivas_long_enr_fx( { IF( LT_16( st_fx->ini_frame, 4 ) ) { - st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; /* Q8 */ - move16(); - tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ - st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); - move16(); + st_fx->lp_noise_32fx = hNoiseEst->totalNoise_32fx; /* Q24 */ + move32(); + Word32 tmp1 = L_add( st_fx->lp_noise_32fx, 167772160 ); /*10.0 in Q24*/ + st_fx->lp_speech_32fx = L_max( st_fx->lp_speech_32fx, tmp1 ); + move32(); } ELSE { @@ -115,34 +115,34 @@ void ivas_long_enr_fx( } else { st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; } */ - alpha = 655; /* 0.02 Q15 */ - move16(); + alpha = 42949673; /* 0.02 Q31 */ + move32(); if ( LT_16( st_fx->ini_frame, 150 ) ) /* should match HE_LT_CNT_INIT_FX */ { - alpha = 1638; - move16(); /* 0.05 Q15 */ + alpha = 107374182; + move32(); /* 0.05 Q31 */ } - st_fx->lp_noise_fx = noise_est_AR1_Qx( hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx, alpha ); /* Q8 state, alpha in Q15 */ - move16(); + st_fx->lp_noise_32fx = noise_est_AR1_Qx_32( hNoiseEst->totalNoise_32fx, st_fx->lp_noise_32fx, alpha ); /* Q24 state, alpha in Q31 */ + move32(); test(); IF( ( localVAD_HE_SAD != 0 ) && ( high_lpn_flag == 0 ) ) { - IF( LT_16( sub( st_fx->lp_speech_fx, Etot ), 2560 ) ) /* 10.0 in Q8 */ + IF( LT_32( L_sub( st_fx->lp_speech_32fx, Etot ), 167772160 ) ) /* 10.0 in Q24 */ { /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ - st_fx->lp_speech_fx = noise_est_AR1_Qx( Etot, st_fx->lp_speech_fx, 655 ); /* Q8 state, 0.02 in Q15 */ - move16(); + st_fx->lp_speech_32fx = noise_est_AR1_Qx_32( Etot, st_fx->lp_speech_32fx, 42949673 ); /* Q24 state, 0.02 in Q31 */ + move32(); } ELSE { - st_fx->lp_speech_fx = sub( st_fx->lp_speech_fx, 13 ); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ - move16(); + st_fx->lp_speech_32fx = L_sub( st_fx->lp_speech_32fx, 838861 ); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ + move32(); } } } /* Update */ - st_fx->hNoiseEst->Etot_last_32fx = L_deposit_h( Etot ); /* Q24 */ - move16(); + st_fx->hNoiseEst->Etot_last_32fx = Etot; /* Q24 */ + move32(); } /*-----------------------------------------------------------------* diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 7534a5159..676696fd6 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -75,6 +75,20 @@ Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ return mac_r( L_mult( y, alpham1 ), x, alpha ); } +Word32 noise_est_AR1_Qx_32( /* o : Qx y(n) */ + Word32 x, /* i : Qx x(n) */ + Word32 y, /* i : Qx y(n-1) */ + Word32 alpha /*i : Q15 scaling of driving x(n) */ +) +{ + Word32 alpham1; + /*alpham1 = negate(add((Word16)-32768, alpha)); */ + alpham1 = L_sub( MAX_32, alpha ); /* one cycle less */ + alpham1++; + + return Madd_32_32( Mpy_32_32( y, alpham1 ), x, alpha ); +} + /*-----------------------------------------------------------------* * noise_est_ln_q8_fx() * @@ -280,7 +294,7 @@ void noise_est_init_ivas_fx( move32(); /*Q7//E_MIN; */ hNoiseEst->enrO_fx[i] = E_MIN_Q11_FX; move32(); - hNoiseEst->bckr_fx[i] = E_MIN_Q11_FX; + hNoiseEst->bckr_fx[i] = E_MIN_Q27_FX; move32(); hNoiseEst->ave_enr_fx[i] = E_MIN_Q11_FX; move32(); @@ -289,14 +303,14 @@ void noise_est_init_ivas_fx( move16(); /*1e-5f; */ hNoiseEst->q_enrO = Q11; move16(); - hNoiseEst->q_bckr = Q11; + hNoiseEst->q_bckr = Q27; move16(); hNoiseEst->ave_enr_q = Q11; move16(); move16(); - hNoiseEst->totalNoise_fx = 0; - move16(); + hNoiseEst->totalNoise_32fx = 0; + move32(); hNoiseEst->first_noise_updt = 0; move16(); hNoiseEst->first_noise_updt_cnt = 0; @@ -747,7 +761,7 @@ void noise_est_down_ivas_fx( Word16 *q_enr, const Word16 min_band, /* i : minimum critical band */ const Word16 max_band, /* i : maximum critical band */ - Word16 *totalNoise, /* o : noise estimate over all critical bands */ + Word32 *totalNoise, /* o : noise estimate over all critical bands */ Word32 Etot, /* i : Energy of current frame Q24*/ Word32 *Etot_last, /* i/o: Energy of last frame Q24 */ Word32 *Etot_v_h2 /* i/o: Energy variations of noise frames Q24 */ @@ -803,8 +817,8 @@ void noise_est_down_ivas_fx( Ltmp = L_mac( L_deposit_h( e_Noise ), f_Noise, 1 ); // Q16 Ltmp = Mpy_32_16_1( Ltmp, LG10 ); // Q14 (16+13-15) Ltmp = L_shl( Ltmp, 10 ); // Q26 - *totalNoise = round_fx( Ltmp ); /*Q8*/ - move16(); + *totalNoise = ( Ltmp ); /*Q24*/ + move32(); /*-----------------------------------------------------------------* * Average energy per frame for each frequency band @@ -2207,7 +2221,7 @@ void noise_est_ivas_fx( Word16 *ncharX, /* o : Q11 */ Word16 *sp_div, /* o : Q_sp_div */ Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier Q8 */ + Word32 *non_staX, /* o : non-stationarity for sp/mus classifier Q20 */ Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ const Word32 *lf_E, /* i : per bin energy for low frequencies q_lf_E */ const Word16 q_lf_E, /* i : Q of lf_E Q0 */ @@ -2728,7 +2742,7 @@ void noise_est_ivas_fx( Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15 log_enr16 = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */ wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) ); - *non_staX = add_o( *non_staX, wtmp, &Overflow ); + *non_staX = L_add( *non_staX, wtmp ); move16(); /* Q8 */ hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16; move16(); @@ -2773,8 +2787,9 @@ void noise_est_ivas_fx( } } - } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */ - + } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */ + *non_staX = L_shl( *non_staX, 12 ); // Q20 + move32(); IF( LT_16( Etot, -1280 /* -5.0f in Q8 */ ) ) { non_sta = L_deposit_l( 1024 ); /* 1.0 in Q10 */ @@ -2974,7 +2989,7 @@ void noise_est_ivas_fx( * long term extensions of frame features *-----------------------------------------------------------------*/ - tmp = sub( Etot, hNoiseEst->totalNoise_fx ); /* Q8 */ + tmp = sub( Etot, extract_h( hNoiseEst->totalNoise_32fx ) ); /* Q8 */ /* st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; */ tmp2 = 0; move16(); @@ -3471,7 +3486,7 @@ void noise_est_ivas_fx( test(); test(); IF( ( LT_16( hNoiseEst->act_pred_fx, 27853 /* 0.85 in Q15 */ ) && ( aE_bgd != 0 ) && ( LT_16( hNoiseEst->lt_Ellp_dist_fx, 10 * 256 /* 10 in Q8*/ ) || ( sd1_bgd != 0 ) ) && ( LT_16( hNoiseEst->lt_tn_dist_fx, 40 * 256 ) ) /* 40.0 in Q8*/ - && LT_16( sub( Etot, hNoiseEst->totalNoise_fx ), 10 * 256 /* 10 in Q8 */ ) /* 10.0 in Q8*/ ) || + && LT_16( sub( Etot, extract_h( hNoiseEst->totalNoise_32fx ) ), 10 * 256 /* 10 in Q8 */ ) /* 10.0 in Q8*/ ) || ( ( hNoiseEst->first_noise_updt == 0 ) && GT_16( hNoiseEst->harm_cor_cnt, 80 ) && ( aE_bgd != 0 ) && GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 /* 0.5 in Q15 */ ) ) || ( ( tn_ini != 0 ) && ( ( aE_bgd != 0 ) || LT_16( non_staB, 10 * 256 /* 10 in Q8*/ ) || GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) ) ) { @@ -3494,7 +3509,7 @@ void noise_est_ivas_fx( ) */ ELSE IF( ( LT_16( hNoiseEst->act_pred_fx, 26214 /* 0.8 in Q15*/ ) && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 3277 /* 0.1 in q15*/ ) ) ) || ( ( LT_16( hNoiseEst->act_pred_fx, 22938 /* 0.70 in Q15 */ ) ) && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 17 * 256 /* 17.0 in Q8 */ ) ) ) && ( PAU != 0 ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 4915 /* 0.15 in Q15 */ ) ) ) || - ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) && GT_16( hNoiseEst->totalNoise_fx, 5 * 256 /* 5.0 in Q8 */ ) && LT_16( Etot, s_max( 1 * 256, add( Etot_l_lp, extract_h( L_add( hNoiseEst->Etot_v_h2_32fx, L_shr( hNoiseEst->Etot_v_h2_32fx, 1 ) ) ) /* 1.5= 1.0+.5 */ ) ) ) ) || + ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) && GT_16( extract_h( hNoiseEst->totalNoise_32fx ), 5 * 256 /* 5.0 in Q8 */ ) && LT_16( Etot, s_max( 1 * 256, add( Etot_l_lp, extract_h( L_add( hNoiseEst->Etot_v_h2_32fx, L_shr( hNoiseEst->Etot_v_h2_32fx, 1 ) ) ) /* 1.5= 1.0+.5 */ ) ) ) ) || ( GT_16( hNoiseEst->harm_cor_cnt, 50 ) && GT_16( hNoiseEst->first_noise_updt, 30 ) && ( aE_bgd != 0 ) && GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 /*.5 in Q15*/ ) ) || ( tn_ini != 0 ) ) { updt_step = 3277; @@ -3513,7 +3528,7 @@ void noise_est_ivas_fx( test(); if ( ( aE_bgd == 0 ) && LT_16( hNoiseEst->harm_cor_cnt, 50 ) && ( GT_16( hNoiseEst->act_pred_fx, 19661 /* 0.6 in Q15*/ ) || - ( ( tn_ini == 0 ) && LT_16( sub( Etot_l_lp, hNoiseEst->totalNoise_fx ), 10 * 256 /* 10.0 in Q8 */ ) && GT_16( non_staB, 8 * 256 /* 8.0 in in Q8*/ ) ) ) ) + ( ( tn_ini == 0 ) && LT_16( sub( Etot_l_lp, extract_h( hNoiseEst->totalNoise_32fx ) ), 10 * 256 /* 10.0 in Q8 */ ) && GT_16( non_staB, 8 * 256 /* 8.0 in in Q8*/ ) ) ) ) { updt_step = 328; move16(); /* 0.01 Q15 */ @@ -3543,7 +3558,7 @@ void noise_est_ivas_fx( /* If in music lower bckr to drop further */ test(); test(); - IF( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) && GT_16( hNoiseEst->lt_haco_ev_fx, 29491 /* 0.9 in Q15 */ ) && ( hNoiseEst->totalNoise_fx > 0 ) ) + IF( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) && GT_16( hNoiseEst->lt_haco_ev_fx, 29491 /* 0.9 in Q15 */ ) && ( hNoiseEst->totalNoise_32fx > 0 ) ) { updt_step = -655; move16(); /* for debug purposes */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 59d2fdf9a..c433dcb2c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -304,7 +304,7 @@ void long_enr_fx( Word16 high_lpn_flag ); void ivas_long_enr_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q=8*/ + const Word32 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q=24*/ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ Word16 high_lpn_flag, /* i : sp/mus LPN flag */ FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ @@ -347,7 +347,7 @@ void noise_est_down_ivas_fx( Word16 *q_enr, const Word16 min_band, /* i : minimum critical band */ const Word16 max_band, /* i : maximum critical band */ - Word16 *totalNoise, /* o : noise estimate over all critical bands */ + Word32 *totalNoise, /* o : noise estimate over all critical bands */ Word32 Etot, /* i : Energy of current frame Q24*/ Word32 *Etot_last, /* i/o: Energy of last frame Q24 */ Word32 *Etot_v_h2 /* i/o: Energy variations of noise frames Q24 */ @@ -398,7 +398,7 @@ void noise_est_ivas_fx( Word16 *ncharX, /* o : Q11 */ Word16 *sp_div, /* o : Q_sp_div */ Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word32 *non_staX, /* o : non-stationarity for sp/mus classifier */ Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ const Word32 *lf_E, /* i : per bin energy for low frequencies q_lf_E */ const Word16 q_lf_E, /* i : Q of lf_E Q0 */ @@ -4465,6 +4465,13 @@ Word16 noise_est_AR1_Qx( /* o: Qx y(n) */ Word16 y, /* i : Qx y(n-1) */ Word16 alpha /*i : Q15 scaling of driving x(n) */ ); + +Word32 noise_est_AR1_Qx_32( /* o: Qx y(n) */ + Word32 x, /* i : Qx x(n) */ + Word32 y, /* i : Qx y(n-1) */ + Word32 alpha /*i : Q15 scaling of driving x(n) */ +); + void FEC_lsf_estim_enc_fx( Encoder_State *st_fx, /* i : Encoder static memory */ Word16 *lsf /* o : estimated LSF vector Qlog2(2.56)*/ diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 817e5fb70..fd983741b 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -1588,7 +1588,7 @@ Word16 ivas_smc_gmm_fx( const Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) Q8 */ const Word32 epsP_fx[M + 1], /* i : LP prediciton error */ const Word32 PS_fx[], /* i : energy spectrum */ - const Word16 non_sta_fx, /* i : unbound non-stationarity Q8 */ + const Word32 non_sta_fx, /* i : unbound non-stationarity Q20 */ const Word16 relE_fx, /* i : relative frame energy Q8 */ Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ const Word16 flag_spitch, /* i : flag to indicate very short stable pitch */ @@ -1879,7 +1879,7 @@ Word16 ivas_smc_gmm_fx( move32(); /* [8] non_sta */ - *pFV_fx++ = L_shl( non_sta_fx, Q12 ); /*scaling from Q8 to Q20*/ + *pFV_fx++ = non_sta_fx; /*Q20*/ move32(); /* [9] epsP */ @@ -3161,7 +3161,7 @@ void ivas_smc_mode_selection_fx( test(); test(); test(); - if ( EQ_16( st->vad_flag, 1 ) && LE_32( element_brate, IVAS_16k4 ) && GT_16( st->lp_noise_fx, 7680 /* 30.0f in Q8 */ ) && st->sp_aud_decision1 == 0 && GE_16( st->bwidth, SWB ) && EQ_16( st->coder_type_raw, UNVOICED ) ) + if ( EQ_16( st->vad_flag, 1 ) && LE_32( element_brate, IVAS_16k4 ) && GT_32( st->lp_noise_32fx, 503316480 /* 30.0f in Q24 */ ) && st->sp_aud_decision1 == 0 && GE_16( st->bwidth, SWB ) && EQ_16( st->coder_type_raw, UNVOICED ) ) { st->GSC_noisy_speech = 1; move16(); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 2fbec12bd..0647b6ebc 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -542,8 +542,9 @@ typedef struct noise_estimation_structure Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band ave_enr_q */ Word16 ave_enr_q; - Word16 aEn; /* Noise estimator - noise estimator adaptation flag */ - Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ + Word16 aEn; /* Noise estimator - noise estimator adaptation flag */ + Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ + Word32 totalNoise_32fx; /* Q24 Noise estimator - total noise energy */ Word16 first_noise_updt; /* Noise estimator - flag used to determine if the first noise update frame */ Word16 first_noise_updt_cnt; /* Noise estimator - counter of frame after first noise update */ @@ -1522,9 +1523,11 @@ typedef struct enc_core_structure Word16 sharpFlag; Word16 localVAD; /* i : local VAD flag */ - Word32 bckr_tilt_lt; /* Q16 */ - Word16 lp_speech_fx; /* Q8 */ - Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation Q8 */ + Word32 bckr_tilt_lt; /* Q16 */ + Word16 lp_speech_fx; /* Q8 */ + Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation Q24 */ + Word32 lp_speech_32fx; /* Q24 */ + Word32 lp_noise_32fx; /* CNG and DTX - LP filtered total noise estimation Q24 */ Word16 Opt_HE_SAD_ON_fx; Word16 nb_active_frames_HE_SAD_fx; Word16 voicing_old_fx; diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 721a6e348..1cf7a5de8 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -1997,13 +1997,13 @@ Word16 wb_vad_ivas_fx( } if ( LT_16( lp_speech_fx, -100 * 256 ) ) { - lp_speech_fx = st_fx->lp_speech_fx; /*Q8*/ + lp_speech_fx = extract_h( st_fx->lp_speech_32fx ); /*Q8*/ move16(); } if ( LT_16( lp_noise_fx, -100 * 256 ) ) { - lp_noise_fx = st_fx->lp_noise_fx; /*Q8*/ + lp_noise_fx = extract_h( st_fx->lp_noise_32fx ); /*Q8*/ move16(); } -- GitLab From 2ba1cea8d687da5ee683e1a375132ded4738fa74 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 30 May 2025 18:13:46 +0530 Subject: [PATCH 17/54] Fix for 3GPP issue 1201: BASOP encoder ParamISM: high MLD and audible artifacts Link #1201 --- lib_com/swb_tbe_com_fx.c | 3 +++ lib_enc/swb_tbe_enc_fx.c | 48 ++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 96d07e7ef..e4d84ef23 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3309,6 +3309,9 @@ void GenShapedSHBExcitation_ivas_enc_fx( move16(); move16(); + scale_sig( White_exc16k, L_FRAME16k, -1 /* guard bit to prevent saturation in deemph*/ ); + Q_White_exc16k = sub( Q_White_exc16k, 1 ); + Word16 tbe_demph_fx = shl_sat( *tbe_demph, sub( Q_White_exc16k, *Q_bwe_exc ) ); // Q_White_exc16k deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, &tbe_demph_fx ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 9d0f16ee9..b001f8693 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -77,7 +77,8 @@ static void EstimateSHBGainShape_fx( const Word16 length, const Word16 Q_synSHB, Word16 *subgain, const Word16 *subwin, - Word16 *n_subfr_saturation ); + Word16 *n_subfr_saturation, + const Flag limit_min_gain ); static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ); @@ -1072,7 +1073,7 @@ void wb_tbe_enc_fx( Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, - shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL ); + shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL, 1 ); /* Gain frame adjustment factor */ test(); @@ -1707,7 +1708,7 @@ void wb_tbe_enc_ivas_fx( Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, - shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL ); + shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL, 1 ); /* Gain frame adjustment factor */ test(); @@ -2552,7 +2553,7 @@ void swb_tbe_enc_fx( n_subfr_saturation = 0; move16(); EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation ); + Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 1 ); /* Gain shape BWS/high band low energy fix */ IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ @@ -3857,7 +3858,7 @@ void swb_tbe_enc_ivas_fx( n_subfr_saturation = 0; move16(); EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation ); + Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) @@ -4931,14 +4932,15 @@ static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ) /*--------------------------------------------------------------------------*/ static void EstimateSHBGainShape_fx( - const Word16 length, /* i : SHB overlap length */ - const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ - const Word16 Q_oriSHB, /* i : Q of target original SHB frame */ - const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ - const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ - Word16 *subgain, /* o : estimate of gain shape Q15 */ - const Word16 *subwin, /* i : SHB subframe window Q15 */ - Word16 *n_subfr_saturation /* o : Number of subframes which saturated while calculating oriNrg */ + const Word16 length, /* i : SHB overlap length */ + const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ + const Word16 Q_oriSHB, /* i : Q of target original SHB frame */ + const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ + const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ + Word16 *subgain, /* o : estimate of gain shape Q15 */ + const Word16 *subwin, /* i : SHB subframe window Q15 */ + Word16 *n_subfr_saturation, /* o : Number of subframes which saturated while calculating oriNrg */ + const Flag limit_min_gain /* i : gain shape limiting flag */ ) { const Word16 *skip; @@ -5152,11 +5154,23 @@ static void EstimateSHBGainShape_fx( n = sub( 31, add( n, ( sub( 28, shl( n_max, 1 ) ) ) ) ); normFact = Isqrt_lc( L_sum_gain, &n ); - FOR( i = 0; i < num_gains; i++ ) + IF( limit_min_gain ) { - L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ - subgain[i] = s_max( round_fx_o( L_shl_o( L_tmp, add( n, n_max + 1 ), &Overflow ), &Overflow ), 3277 /*0.1f Q15*/ ); /* Q15 */ - move16(); + FOR( i = 0; i < num_gains; i++ ) + { + L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ + subgain[i] = s_max( round_fx_o( L_shl_o( L_tmp, add( n, n_max + 1 ), &Overflow ), &Overflow ), 3277 /*0.1f Q15*/ ); /* Q15 */ + move16(); + } + } + ELSE + { + FOR( i = 0; i < num_gains; i++ ) + { + L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ + subgain[i] = round_fx_o( L_shl_o( L_tmp, add( n, n_max + 1 ), &Overflow ), &Overflow ); /* Q15 */ + move16(); + } } return; -- GitLab From 36c5c06501f379b942be8c0d6af87f77b14aac55 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 14:53:32 +0200 Subject: [PATCH 18/54] Add new fx-fx job --- .gitlab-ci.yml | 49 ++++++++++++++++++++++++++++++++++++++++ .gitlab-ci/variables.yml | 1 + 2 files changed, 50 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9f37f50f2..b743f7a03 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,6 +36,9 @@ workflow: variables: IVAS_PIPELINE_NAME: 'Run encoder dmx comparison against float ref: $CI_COMMIT_BRANCH' - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-long' + variables: + IVAS_PIPELINE_NAME: 'Run comparison tools against float ref FX-FX (long test vectors): $CI_COMMIT_BRANCH' + - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-long-fx-fx' variables: IVAS_PIPELINE_NAME: 'Run comparison tools against float ref (long test vectors): $CI_COMMIT_BRANCH' - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-to-input' @@ -133,6 +136,15 @@ workflow: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' when: never +.rules-pytest-long-fx-fx: + rules: + - if: $PYTEST_MLD_LONG # Set by scheduled pipeline + - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == "pytest-compare-long-fx-fx" + - if: $CI_PIPELINE_SOURCE == 'push' + when: never + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + when: never + .rules-coverage: rules: - if: $COVERAGE_TEST # Set by scheduled pipeline @@ -1336,6 +1348,43 @@ ivas-pytest-compare_ref-long-dec-lev+10: - SPLIT_COMPARISON="true" <<: *ivas-pytest-anchor +ivas-pytest-compare_ref-long-fx-fx: + extends: + - .rules-pytest-long-fx-fx + - .test-job-linux + before_script: + - USE_LTV=1 + - REF_ENCODER_PATH=./$DUT_ENCODER_PATH + - TEST_SUITE="$LONG_TEST_SUITE_NO_RENDERER" + - LEVEL_SCALING=1.0 + - SPLIT_COMPARISON="true" + <<: *ivas-pytest-anchor + +ivas-pytest-compare_ref-long-fx-fx-lev-10: + extends: + - .rules-pytest-long-fx-fx + - .test-job-linux + before_script: + - USE_LTV=1 + - REF_ENCODER_PATH=./$DUT_ENCODER_PATH + - TEST_SUITE="$LONG_TEST_SUITE_NO_RENDERER" + - LEVEL_SCALING=0.3162 + - SPLIT_COMPARISON="true" + <<: *ivas-pytest-anchor + +ivas-pytest-compare_ref-long-fx-fx-lev+10: + extends: + - .rules-pytest-long-fx-fx + - .test-job-linux + before_script: + - USE_LTV=1 + - REF_ENCODER_PATH=./$DUT_ENCODER_PATH + - TEST_SUITE="$LONG_TEST_SUITE_NO_RENDERER" + - LEVEL_SCALING=3.162 + - SPLIT_COMPARISON="true" + <<: *ivas-pytest-anchor + + ivas-smoke-test-saturation: extends: - .rules-pytest-saturation-smoke-test diff --git a/.gitlab-ci/variables.yml b/.gitlab-ci/variables.yml index 94bb71fb3..0c212d312 100644 --- a/.gitlab-ci/variables.yml +++ b/.gitlab-ci/variables.yml @@ -54,6 +54,7 @@ variables: - 'pytest-compare' - 'pytest-compare-enc-dmx' - 'pytest-compare-long' + - 'pytest-compare-long-fx-fx' - 'pytest-compare-to-input' - 'pytest-saturation-smoke-test' - 'evs-26444' -- GitLab From 4f34d8e44d3a7b41bb78e94818fc4b13c959f056 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 3 Jun 2025 08:32:21 +0200 Subject: [PATCH 19/54] Correct variable for scheduled FX-FX job --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b743f7a03..d10993ad6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -138,7 +138,7 @@ workflow: .rules-pytest-long-fx-fx: rules: - - if: $PYTEST_MLD_LONG # Set by scheduled pipeline + - if: $PYTEST_MLD_LONG_FX_FX # Set by scheduled pipeline - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == "pytest-compare-long-fx-fx" - if: $CI_PIPELINE_SOURCE == 'push' when: never -- GitLab From 7f30144ba1767174ab29777070380b4df55cf488 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 4 Jun 2025 10:49:42 +0530 Subject: [PATCH 20/54] Fix for 3GPP issue 1722: Assert in BASOP renderer when rendering ISM to certain custom LS setup Link #1722 Increased precision in in_tri function fixes the issue --- lib_rend/ivas_efap_fx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_efap_fx.c b/lib_rend/ivas_efap_fx.c index 4fb88643b..3a4ddde1e 100644 --- a/lib_rend/ivas_efap_fx.c +++ b/lib_rend/ivas_efap_fx.c @@ -2490,7 +2490,8 @@ static Word16 in_tri_fx( Word32 tmpDot1[2], tmpDot2[2]; Word32 matInv[2][2]; Word32 invFactor; - Word16 tmp16, tmp_e; + Word16 tmp_e; + Word32 tmp32; Word64 S[2]; /* Threshold adjusted */ Word64 thresh_int = 35184640; // 1e-6f in Q45 @@ -2520,8 +2521,8 @@ static Word16 in_tri_fx( } /* invFactor = 1.f / invFactor; */ - tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); /*15-tmp_e*/ - invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp32 = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q13, invFactor, &tmp_e ); /*31-tmp_e*/ + invFactor = L_shl_sat( tmp32, tmp_e ); /* Q31 */ Word16 invFactor_exp = norm_l( invFactor ); invFactor = L_shl( invFactor, invFactor_exp ); // 31+invFactor_exp -- GitLab From 9281becbefa13ab56fce58ddcd9ecfee17dbc0a2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 4 Jun 2025 10:54:36 +0530 Subject: [PATCH 21/54] Clang formatting changes --- lib_rend/ivas_efap_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_efap_fx.c b/lib_rend/ivas_efap_fx.c index 3a4ddde1e..fbcfdfe77 100644 --- a/lib_rend/ivas_efap_fx.c +++ b/lib_rend/ivas_efap_fx.c @@ -2522,7 +2522,7 @@ static Word16 in_tri_fx( /* invFactor = 1.f / invFactor; */ tmp32 = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q13, invFactor, &tmp_e ); /*31-tmp_e*/ - invFactor = L_shl_sat( tmp32, tmp_e ); /* Q31 */ + invFactor = L_shl_sat( tmp32, tmp_e ); /* Q31 */ Word16 invFactor_exp = norm_l( invFactor ); invFactor = L_shl( invFactor, invFactor_exp ); // 31+invFactor_exp -- GitLab From 7ef8ea8a57c6b04c40eb4502f9722e11fff507bd Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 4 Jun 2025 12:52:12 +0530 Subject: [PATCH 22/54] Cleanup of synth_fx_32 buffer in ivas_mct_dec_fx, enhancer_ivas_fx function --- lib_com/enhancer_fx.c | 221 ++---------------------------- lib_com/prot_fx.h | 22 +-- lib_dec/dec_gen_voic_fx.c | 4 +- lib_dec/ivas_mct_dec_fx.c | 5 +- lib_dec/ivas_td_low_rate_dec_fx.c | 4 +- 5 files changed, 16 insertions(+), 240 deletions(-) diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 7df474a5d..620904d08 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -299,10 +299,11 @@ void enhancer_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*======================================================================================*/ + void enhancer_ivas_fx( - const Word16 codec_mode, /* i : flag indicating Codec Mode */ - const Word32 core_brate, /* i : decoder bitrate */ - const Word16 cbk_index, /* i : */ + const Word16 codec_mode, /* i : flag indicating Codec Mode */ + const Word32 core_brate, /* i : decoder bitrate */ + const Word16 cbk_index, const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 coder_type, /* i : coder type */ const Word16 i_subfr, /* i : subframe number */ @@ -322,9 +323,11 @@ void enhancer_ivas_fx( Word16 tmp, fac, *pt_exc2; Word16 i; Word32 L_tmp; + Word32 L_tmp1, L_tmp2; Word16 gain_code_hi; Word16 pit_sharp, tmp16; Word16 excp[L_SUBFR], sc; + Word64 w_temp; pit_sharp = gain_pit; @@ -400,215 +403,6 @@ void enhancer_ivas_fx( phase_dispersion_fx( norm_gain_code, gain_pit, code, i, dm_fx ); - /*------------------------------------------------------------ - * noise enhancer - * - * - Enhance excitation on noise. (modify gain of code) - * If signal is noisy and LPC filter is stable, move gain - * of code 1.5 dB toward gain of code threshold. - * This decreases by 3 dB noise energy variation. - *-----------------------------------------------------------*/ - - /* tmp = 0.5f * (1.0f - voice_fac) */ - tmp = msu_r_sat( 0x40000000 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q14*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ - /* fac = stab_fac * tmp */ - fac = mult( stab_fac, tmp ); /*Q15*/ - - IF( LT_32( norm_gain_code, *gc_threshold ) ) - { - L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 /*0.19.Q15*/ ); /*Q16 */ - L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ - } - ELSE - { - L_tmp = Mult_32_16( norm_gain_code, 27536 /*0.84.Q15*/ ); /*Q16 */ - L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ - } - *gc_threshold = L_tmp; - move32(); /*Q16 */ - - /* gain_code = (fac * tmp) + (1.0 - fac) * gain_code ==> fac * (tmp - gain_code) + gain_code */ - L_tmp = L_sub( L_tmp, norm_gain_code ); /*Q16 */ - norm_gain_code = Madd_32_16( norm_gain_code, L_tmp, fac ); /*Q16 */ - - /* gain_code *= gain_inov - Inverse the normalization */ - L_tmp = Mult_32_16( norm_gain_code, gain_inov ); /*Q13*/ /* gain_inov in Q12 */ - - sc = 6; - move16(); - - gain_code_hi = round_fx( L_shl( L_tmp, add( Q_exc, 3 ) ) ); /* in Q_exc */ - - /*------------------------------------------------------------* - * pitch enhancer - * - * - Enhance excitation on voiced. (HP filtering of code) - * On voiced signal, filtering of code by a smooth fir HP - * filter to decrease energy of code at low frequency. - *------------------------------------------------------------*/ - test(); - IF( !Opt_AMR_WB && EQ_16( coder_type, UNVOICED ) ) - { - /* Copy(code, exc2, L_SUBFR) */ - FOR( i = 0; i < L_SUBFR; i++ ) - { - pt_exc2[i] = round_fx( L_shl( L_mult( gain_code_hi, code[i] ), sc ) ); /*Q0 */ /* code in Q12 (Q9 for encoder) */ - move16(); - } - } - ELSE - { - test(); - test(); - IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) - { - pit_sharp = shl_sat( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ - /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) - { - tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); - FOR( i = 0; i < L_SUBFR; i++ ) - { - /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ - excp[i] = mult_r( pt_exc2[i], tmp16 ); - move16(); - } - } - } - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - /* tmp = 0.150 * (1.0 + voice_fac) */ - /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x13333333L /*0.150.Q31*/, voice_fac, 4915 /*0.150.Q15*/ ); /*Q15 */ - } - ELSE - { - /* tmp = 0.125 * (1.0 + voice_fac) */ - /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L /*0.125.Q31*/, voice_fac, 4096 ); /*Q15 */ - } - - /*----------------------------------------------------------------- - * Do a simple noncasual "sharpening": effectively an FIR - * filter with coefs [-tmp 1.0 -tmp] where tmp=0...0.25. - * This is applied to code and add_fxed to exc2 - *-----------------------------------------------------------------*/ - /* pt_exc2[0] += code[0] - tmp * code[1] */ - L_tmp = L_deposit_h( code[0] ); /* if Enc :Q9 * Q15 -> 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 ); - pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); - move16(); /* in Q_exc */ - - FOR( i = 1; i < L_SUBFR - 1; i++ ) - { - /* 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 ); - pt_exc2[i] = msu_r_sat( L_tmp, -32768, pt_exc2[i] ); - move16(); /* in Q_exc */ - } - - /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ - 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] ); - move16(); /* in Q_exc */ - test(); - test(); - IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) - { - IF( GT_16( pit_sharp, 16384 /*0.5.Q14*/ ) ) - { - FOR( i = 0; i < L_SUBFR; i++ ) - { - /* excp[i] += pt_exc2[i] */ - excp[i] = add( excp[i], pt_exc2[i] ); - move16(); - } - agc2_fx( pt_exc2, excp, L_SUBFR ); - Copy( excp, pt_exc2, L_SUBFR ); - } - } - } -} - -void enhancer_ivas_fx2( - const Word32 core_brate, /* i : decoder bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ -) -{ - Word16 tmp, fac, *pt_exc2; - Word16 i; - Word32 L_tmp; - Word32 L_tmp1, L_tmp2; - Word16 gain_code_hi; - Word16 pit_sharp, tmp16; - Word16 excp[L_SUBFR], sc; - Word64 w_temp; - - - pit_sharp = gain_pit; - move16(); /* to remove gcc warning */ - pt_exc2 = exc2 + i_subfr; - - /*------------------------------------------------------------* - * Phase dispersion to enhance noise at low bit rate - *------------------------------------------------------------*/ - - i = 2; - move16(); /* no dispersion */ - IF( Opt_AMR_WB ) - { - IF( LE_32( core_brate, ACELP_6k60 ) ) - { - i = 0; - move16(); /* high dispersion */ - } - ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) - { - i = 1; - move16(); /* low dispersion */ - } - } - ELSE IF( NE_16( coder_type, UNVOICED ) ) - - { - test(); - test(); - test(); - test(); - IF( LE_32( core_brate, ACELP_7k20 ) ) - { - i = 0; - move16(); /* high dispersion */ - } - ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) - { - i = 1; - move16(); /* low dispersion */ - } - } - - phase_dispersion_fx( norm_gain_code, gain_pit, code, i, dm_fx ); - /*------------------------------------------------------------ * noise enhancer * @@ -656,7 +450,8 @@ void enhancer_ivas_fx2( * filter to decrease energy of code at low frequency. *------------------------------------------------------------*/ test(); - IF( !Opt_AMR_WB && EQ_16( coder_type, UNVOICED ) ) + test(); + IF( !Opt_AMR_WB && EQ_16( codec_mode, MODE1 ) && EQ_16( coder_type, UNVOICED ) ) { /* Copy(code, exc2, L_SUBFR) */ FOR( i = 0; i < L_SUBFR; i++ ) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index b2df3a736..0a11364dc 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5622,27 +5622,9 @@ void enhancer_fx( ); void enhancer_ivas_fx( - const Word16 codec_mode, /* i : flag indicating Codec Mode */ - const Word32 core_brate, /* i : decoder bitrate */ - const Word16 cbk_index, /* i : */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ -); - -void enhancer_ivas_fx2( + const Word16 codec_mode, /* i : flag indicating Codec Mode */ const Word32 core_brate, /* i : decoder bitrate */ + const Word16 cbk_index, /* i : */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 coder_type, /* i : coder type */ const Word16 i_subfr, /* i : subframe number */ diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 3e42d9535..b9f488942 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -344,8 +344,8 @@ ivas_error decod_gen_voic_fx( } ELSE { - enhancer_ivas_fx2( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); + enhancer_ivas_fx( MODE1, st_fx->core_brate, -1, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, + norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } } diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index b34ce0c56..ec7b8c697 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -85,7 +85,7 @@ ivas_error ivas_mct_dec_fx( set16_fx( x_len[1], 0, NB_DIV ); Decoder_State **sts; Word32 *p_output_orig_fx[2]; - Word32 synth_32_fx[CPE_CHANNELS][L_FRAME_PLUS]; + Word32 synth_fx_32[CPE_CHANNELS][L_FRAME_PLUS]; Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; //(Q_synth) Word32 ivas_total_brate; ivas_error error; @@ -168,7 +168,7 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { p_output_orig_fx[n] = output_fx[n]; - output_fx[n] = synth_32_fx[n]; + output_fx[n] = synth_fx_32[n]; } } @@ -390,7 +390,6 @@ ivas_error ivas_mct_dec_fx( /*----------------------------------------------------------------* * CoreCoder Post-processing and updates *----------------------------------------------------------------*/ - Word32 synth_fx_32[CPE_CHANNELS][L_FRAME48k]; FOR( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 6419f8517..f48d3fabc 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -329,9 +329,9 @@ void decod_gen_2sbfr_fx( * called twice because adapting it to double the subfr length would need lot of modifications *----------------------------------------------------------------*/ - enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc ); + enhancer_ivas_fx( MODE1, st->core_brate, -1, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc ); - enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); + enhancer_ivas_fx( MODE1, st->core_brate, -1, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); p_Aq += 2 * ( M + 1 ); /* Q12 */ -- GitLab From 14e3697e827be3335fd55b4a814ea5ac71ffad7e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Jun 2025 08:43:10 +0530 Subject: [PATCH 23/54] Fix for 3GPP issue 1020: ParamISM: Binaural: HF click Link #1020 --- lib_dec/acelp_core_dec_fx.c | 12 ++++++++-- lib_dec/stat_dec.h | 3 ++- lib_dec/swb_tbe_dec_fx.c | 46 ++++++++++++++++++++++--------------- lib_dec/updt_dec_fx.c | 2 ++ 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index fd0c8ce2d..37d284346 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -2326,6 +2326,11 @@ ivas_error acelp_core_dec_fx( st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + if ( NE_16( st->element_mode, EVS_MONO ) ) + { + st->hBWE_TD->q_old_bwe_exc_extended_fx = 0; + move16(); + } } test(); @@ -2341,9 +2346,12 @@ ivas_error acelp_core_dec_fx( } ELSE { - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), st->hBWE_TD->q_old_bwe_exc_extended_fx ) ) ); /* Q(q_old_bwe_exc_extended_fx) -> Q(2 * Q_exc) */ non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + exp = sub( L_norm_arr( bwe_exc_extended_fx + L_FRAME32k, NL_BUFF_OFFSET ), 16 ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, exp ); /* Q(2 * Q_exc) -> Q(q_old_bwe_exc_extended_fx) */ + st->hBWE_TD->q_old_bwe_exc_extended_fx = add( shl( st->Q_exc, 1 ), exp ); + move16(); } } diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 4e4e33c36..28a97f072 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -822,7 +822,8 @@ typedef struct td_bwe_dec_structure Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ Word16 bwe_seed[2]; Word32 bwe_non_lin_prev_scale_fx; - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; + Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; /* EVS : Q(prev_Q_bwe_exc - 16), IVAS : Q(q_old_bwe_exc_extended_fx) */ + Word16 q_old_bwe_exc_extended_fx; Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index bd8700063..b005a88bf 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -56,10 +56,13 @@ static void find_max_mem_dec( hBWE_TD = st_fx->hBWE_TD; /* old BWE exc max */ - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - tempQ15 = abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ); - max = s_max( max, tempQ15 ); + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + { + tempQ15 = abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ); + max = s_max( max, tempQ15 ); + } } /* decimate all-pass steep memory */ @@ -232,10 +235,13 @@ static void rescale_genSHB_mem_dec( TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); - move16(); + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + { + hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); + move16(); + } } FOR( i = 0; i < 7; i++ ) @@ -283,9 +289,12 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - max = s_max( max, abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ) ); + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + { + max = s_max( max, abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ) ); + } } FOR( i = 0; i < 7; i++ ) { @@ -362,10 +371,13 @@ void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ) TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); - move16(); + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) + { + hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); + move16(); + } } FOR( i = 0; i < 10; i++ ) @@ -418,6 +430,8 @@ static void InitSWBdecBuffer_fx( move16(); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->q_old_bwe_exc_extended_fx = 0; + move16(); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); @@ -5375,12 +5389,6 @@ static void rescale_genSHB_mem_dec_ivas( TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) - { - hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); - move16(); - } - FOR( i = 0; i < 7; i++ ) { hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); @@ -6147,7 +6155,7 @@ void ivas_swb_tbe_dec_fx( /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ Lmax = 0; move32(); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) ); } @@ -6177,7 +6185,7 @@ void ivas_swb_tbe_dec_fx( /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) ); move16(); diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 81046fb19..7af4dec1a 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -240,6 +240,8 @@ void updt_IO_switch_dec_fx( { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->q_old_bwe_exc_extended_fx = 0; + move16(); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); -- GitLab From b7cb47dc09e7ce88dc1f2552bbb09dd88076c748 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Jun 2025 12:47:31 +0530 Subject: [PATCH 24/54] Review comments addressing --- lib_dec/acelp_core_dec_fx.c | 2 +- lib_dec/swb_tbe_dec_fx.c | 2 +- lib_dec/updt_dec_fx.c | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 37d284346..847e16594 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -2328,7 +2328,7 @@ ivas_error acelp_core_dec_fx( set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); if ( NE_16( st->element_mode, EVS_MONO ) ) { - st->hBWE_TD->q_old_bwe_exc_extended_fx = 0; + st->hBWE_TD->q_old_bwe_exc_extended_fx = Q15; move16(); } } diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index b005a88bf..1234e2853 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -430,7 +430,7 @@ static void InitSWBdecBuffer_fx( move16(); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - hBWE_TD->q_old_bwe_exc_extended_fx = 0; + hBWE_TD->q_old_bwe_exc_extended_fx = Q15; move16(); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 7af4dec1a..81046fb19 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -240,8 +240,6 @@ void updt_IO_switch_dec_fx( { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - hBWE_TD->q_old_bwe_exc_extended_fx = 0; - move16(); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); -- GitLab From f874b377fb9be35147ceda399fb2653038557d1f Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 5 Jun 2025 09:31:10 +0200 Subject: [PATCH 25/54] Add FIX_USAN_BASOP_UTIL_DIVIDE3232 to address USAN in BASOP_Util_Divide3232_Scale_newton --- lib_com/basop_util.c | 4 ++++ lib_com/options.h | 1 + 2 files changed, 5 insertions(+) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index e52f404f6..3d6324783 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1409,7 +1409,11 @@ Word32 BASOP_Util_Divide3232_Scale_newton( Word32 x, Word32 y, Word16 *s ) *s = 0; return ( (Word32) 0 ); } +#ifdef FIX_USAN_BASOP_UTIL_DIVIDE3232 + IF( EQ_32( y, (Word32) 0x80000000 ) ) +#else IF( EQ_32( y, 0x80000000 ) ) +#endif { /* Division by -1.0: same as negation of numerator */ /* Return normalized negated numerator */ diff --git a/lib_com/options.h b/lib_com/options.h index a5d5a4846..fe44eae00 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -105,5 +105,6 @@ #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ #define FIX_1713_EXP /* VA: proposed correction to exp in ic-BWE*/ +#define FIX_USAN_BASOP_UTIL_DIVIDE3232 /* Eri: Fix USAN error in BASOP_Util_Divide3232_Scale_newton by adding explicit type cast for -1 in hex */ #endif -- GitLab From 9a6b8df96f3a92e5592c223c8bb6a81325b44bfb Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Jun 2025 14:47:00 +0530 Subject: [PATCH 26/54] Fix for 3GPP issue 1728: Renderer crash with assertion in OMASA to MASA output (renderIsmToMasa) Link #1728, #1729 This change fixes issue #1729 as well --- lib_rend/lib_rend_fx.c | 45 +++++++++++------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index e39b9a61e..4b98684fb 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -5530,53 +5530,32 @@ static void renderIsmToMasa( Word16 *exp ) { Word32 tmpRendBuffer_fx[MAX_NUM_OBJECTS][L_FRAME48k]; - Word16 i, j; - Word16 q_fact; + Word16 i, guard_bits, q_min, q_diff; push_wmops( "renderIsmToMasa" ); - FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) - { - set32_fx( tmpRendBuffer_fx[i], 0, L_FRAME48k ); - } - copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpRendBuffer_fx ); - Word16 input_e[MAX_NUM_OBJECTS], max_e; - - FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) - { - input_e[i] = sub( 31, add( getScaleFactor32( tmpRendBuffer_fx[i], L_FRAME48k ), *outAudio.pq_fact ) ); - move16(); - } - Word16 guard_bits = find_guarded_bits_fx( L_FRAME48k ); - max_e = input_e[0]; + q_min = MAX_16; move16(); - FOR( i = 1; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < ismInput->base.inputBuffer.config.numChannels; i++ ) { - if ( LT_16( max_e, input_e[0] ) ) - { - max_e = input_e[i]; - move16(); - } + q_min = s_min( q_min, L_norm_arr( tmpRendBuffer_fx[i], ismInput->base.inputBuffer.config.numSamplesPerChannel ) ); } - FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) + guard_bits = find_guarded_bits_fx( ismInput->base.inputBuffer.config.numSamplesPerChannel ); + q_min = sub( add( q_min, *outAudio.pq_fact ), guard_bits ); + q_diff = sub( q_min, *outAudio.pq_fact ); + + FOR( i = 0; i < ismInput->base.inputBuffer.config.numChannels; i++ ) { - FOR( j = 0; j < L_FRAME48k; j++ ) - { - tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], add( sub( max_e, sub( 31, *outAudio.pq_fact ) ), guard_bits ) ); /* Q(31 - (max_e + guard_bits)) */ - move32(); - } + scale_sig32( tmpRendBuffer_fx[i], ismInput->base.inputBuffer.config.numSamplesPerChannel, q_diff ); // *outAudio.pq_fact -> q_min } - max_e = add( max_e, guard_bits ); - q_fact = sub( Q31, max_e ); - - ivas_omasa_ana_fx( ismInput->hOMasa, tmpRendBuffer_fx, &q_fact, ismInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, ismInput->base.inputBuffer.config.numChannels ); + ivas_omasa_ana_fx( ismInput->hOMasa, tmpRendBuffer_fx, &q_min, ismInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, ismInput->base.inputBuffer.config.numChannels ); - *exp = q_fact; + *exp = q_min; move16(); accumulate2dArrayToBuffer_fx( tmpRendBuffer_fx, &outAudio ); -- GitLab From 26272dddb88b8a15defd8167d6786e05a2e752b7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Jun 2025 14:50:39 +0530 Subject: [PATCH 27/54] Fix for 3GPP issue 1726: Renderer crash with assert for OMASA to MONO (renderBufferChannelLerp_fx) Link #1726 --- lib_com/cnst.h | 18 ++++++++++-------- lib_rend/lib_rend_fx.c | 6 ++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index a2d051d87..17dbc31c4 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -45,20 +45,22 @@ #define MATRIX_CONSTANT (759250113) #define NUM_SAMPLES_960 (960) #define NUM_SAMPLES_720 (720) +#define NUM_SAMPLES_640 (640) #define NUM_SAMPLES_320 (320) #define NUM_SAMPLES_160 (160) #define L_SUBFRAME_48k (240) #define L_SUBFRAME_32k (180) #define L_SUBFRAME_16k (80) #define L_SUBFRAME_8k (40) -#define Q31_BY_NUM_SAMPLES_960 ( 2239294 ) -#define Q31_BY_NUM_SAMPLES_720 ( 2986764 ) -#define Q31_BY_NUM_SAMPLES_320 ( 6731924 ) -#define Q31_BY_NUM_SAMPLES_160 ( 13506186 ) -#define Q31_BY_SUB_FRAME_240 ( 8985287 ) -#define Q31_BY_SUB_FRAME_180 ( 11997115 ) -#define Q31_BY_SUB_FRAME_80 ( 27183337 ) -#define Q31_BY_SUB_FRAME_40 ( 55063683 ) +#define Q31_BY_NUM_SAMPLES_960 ( 2239294 ) /* 1/959 in Q31 */ +#define Q31_BY_NUM_SAMPLES_720 ( 2986764 ) /* 1/719 in Q31 */ +#define Q31_BY_NUM_SAMPLES_640 ( 3360694 ) /* 1/639 in Q31 */ +#define Q31_BY_NUM_SAMPLES_320 ( 6731924 ) /* 1/319 in Q31 */ +#define Q31_BY_NUM_SAMPLES_160 ( 13506186 ) /* 1/159 in Q31 */ +#define Q31_BY_SUB_FRAME_240 ( 8985287 ) /* 1/239 in Q31 */ +#define Q31_BY_SUB_FRAME_180 ( 11997115 ) /* 1/179 in Q31 */ +#define Q31_BY_SUB_FRAME_80 ( 27183337 ) /* 1/79 in Q31 */ +#define Q31_BY_SUB_FRAME_40 ( 55063683 ) /* 1/39 in Q31 */ /*----------------------------------------------------------------------------------* diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index e39b9a61e..2b70c2e21 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -4579,6 +4579,12 @@ static void renderBufferChannelLerp_fx( move32(); move32(); BREAK; + case NUM_SAMPLES_640: + tmp = Q31_BY_NUM_SAMPLES_640; + tmp1 = 639; /* NUM_SAMPLES_640 - 1 */ + move32(); + move32(); + BREAK; case NUM_SAMPLES_320: tmp = Q31_BY_NUM_SAMPLES_320; tmp1 = 319; /* NUM_SAMPLES_320 - 1 */ -- GitLab From ea1c1cd3b9b8581c9be393f63c503a3e51b1b76b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Jun 2025 14:57:34 +0530 Subject: [PATCH 28/54] Fix for 3GPP issue 1727: Renderer crash with assert for OMASA to MASA output (ivas_create_masa_out_meta_fx) Link #1727 --- lib_com/ivas_dirac_com_fx.c | 115 ------------- lib_com/ivas_prot_fx.h | 12 -- lib_rend/ivas_dirac_ana_fx.c | 270 ++++++++++------------------- lib_rend/ivas_masa_merge_fx.c | 4 +- lib_rend/ivas_omasa_ana_fx.c | 308 +++++++++++----------------------- lib_rend/ivas_stat_rend.h | 10 +- lib_rend/lib_rend_fx.c | 9 +- 7 files changed, 198 insertions(+), 530 deletions(-) diff --git a/lib_com/ivas_dirac_com_fx.c b/lib_com/ivas_dirac_com_fx.c index 4279065b0..2be3f8ace 100644 --- a/lib_com/ivas_dirac_com_fx.c +++ b/lib_com/ivas_dirac_com_fx.c @@ -778,121 +778,6 @@ void computeDirectionVectors_fx( return; } -/*------------------------------------------------------------------------- - * computeDiffuseness() - * - * - *------------------------------------------------------------------------*/ - -void computeDiffuseness_fx( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], // i: Q(q_factor_intensity) - const Word32 *buffer_energy, // i: Q(q_factor_energy) - const Word16 num_freq_bands, - Word32 *diffuseness, // o: exp(out_exp) - Word16 q_factor_intensity, - Word16 q_factor_energy, - Word16 *out_exp /*Ouput Q*/ -) -{ - Word32 intensity_slow[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX]; - Word32 intensity_slow_abs[CLDFB_NO_CHANNELS_MAX]; - Word32 energy_slow[CLDFB_NO_CHANNELS_MAX]; - Word16 i, j, k; - Word32 tmp = 0, tmp_1; - move32(); - Word32 *p_tmp; - const Word32 *p_tmp_c; - - /* Compute Intensity slow and energy slow */ - - set32_fx( intensity_slow, 0, DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX ); - set32_fx( intensity_slow_abs, 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( energy_slow, 0, CLDFB_NO_CHANNELS_MAX ); - - FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) - { - /* Energy slow */ - p_tmp_c = buffer_energy + i * num_freq_bands; - FOR( k = 0; k < num_freq_bands; k++ ) - { - energy_slow[k] = L_add( *( p_tmp_c++ ), energy_slow[k] ); // Q(q_factor_energy) - move32(); - } - - /* Intensity slow */ - FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) - { - p_tmp = buffer_intensity[j][i]; - - FOR( k = 0; k < num_freq_bands; k++ ) - { - intensity_slow[j * num_freq_bands + k] = L_add( *( p_tmp++ ), intensity_slow[j * num_freq_bands + k] ); - move32(); - } - } - } - - /* intensity_slow.^2 + intensity_slow_abs*/ - FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) - { - p_tmp = intensity_slow + j * num_freq_bands; - - FOR( k = 0; k < num_freq_bands; k++ ) - { - *( p_tmp ) = Mpy_32_32( *p_tmp, *( p_tmp ) ); // Q( 2*(q_factor_intensity + scale_fact - 1) -31 ) - intensity_slow_abs[k] = L_add( *( p_tmp++ ), intensity_slow_abs[k] ); - move32(); - move32(); - } - } - Word16 init_exp = sub( 62, shl( q_factor_intensity, 1 ) ); // 31 - ( 2 * q_factor_intensity - 31 ) - Word16 exp; - - Word16 exp1 = 0, exp2; - move16(); - /* Compute Diffuseness */ - p_tmp = intensity_slow_abs; - FOR( i = 0; i < num_freq_bands; ++i ) - { - exp = init_exp; - move16(); - Word32 temp = *( p_tmp++ ); - move32(); - tmp_1 = Sqrt32( temp, &exp ); - tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp_1, L_add( energy_slow[i], 1 ), &exp1 ) ); - exp2 = add( sub( 31, exp1 ), sub( sub( 31, exp ), q_factor_energy ) ); - IF( GT_32( exp2, 30 ) ) - { - tmp = L_shr( tmp, sub( exp2, 30 ) ); - exp2 = sub( exp2, sub( exp2, 30 ) ); - } - tmp = L_sub( L_shl( 1, exp2 ), tmp ); - // diffuseness[i] = ( ( tmp < L_shl( 1, exp2 ) ) ? ( ( tmp < 0 ) ? 0 : tmp ) : L_shl( 1, exp2 ) ); - - IF( LT_32( tmp, L_shl( 1, exp2 ) ) ) - { - IF( tmp < 0 ) - { - diffuseness[i] = 0; - } - ELSE - { - diffuseness[i] = tmp; - } - } - ELSE - { - diffuseness[i] = L_shl( 1, exp2 ); - } - out_exp[i] = exp2; - - move32(); - move16(); - } - return; -} - - /*------------------------------------------------------------------------- * computeDiffuseness() * diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index d9ca855be..4bea59632 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -4951,18 +4951,6 @@ void computeDirectionVectors_fx( Word32 *direction_vector_z, Word16 *q_factor ); - -void computeDiffuseness_fx( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, - const Word16 num_freq_bands, - Word32 *diffuseness, - Word16 q_factor_intensity, - Word16 q_factor_energy, - Word16 *out_exp - -); - void computeDiffuseness_fixed( Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], const Word32 *buffer_energy, diff --git a/lib_rend/ivas_dirac_ana_fx.c b/lib_rend/ivas_dirac_ana_fx.c index c2430d008..0e3686197 100644 --- a/lib_rend/ivas_dirac_ana_fx.c +++ b/lib_rend/ivas_dirac_ana_fx.c @@ -127,7 +127,20 @@ ivas_error ivas_dirac_ana_open_fx( } set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, MASA_FREQUENCY_BANDS ); } + IF( ( hDirAC->direction_vector_e[i] = (Word16 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( ( hDirAC->direction_vector_e[i][j] = (Word16 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + } } + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) @@ -140,7 +153,8 @@ ivas_error ivas_dirac_ana_open_fx( } } set32_fx( hDirAC->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS ); - + set16_fx( hDirAC->buffer_intensity_real_q, 31, DIRAC_NO_COL_AVG_DIFF ); + set16_fx( hDirAC->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); hDirAC->index_buffer_intensity = 0; move16(); @@ -194,6 +208,12 @@ void ivas_dirac_ana_close_fx( free( ( *hDirAC )->direction_vector_m_fx[i] ); ( *hDirAC )->direction_vector_m_fx[i] = NULL; + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + free( ( *hDirAC )->direction_vector_e[i][j] ); + ( *hDirAC )->direction_vector_e[i][j] = NULL; + } + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { free( ( *hDirAC )->buffer_intensity_real_fx[i][j] ); @@ -231,15 +251,10 @@ void ivas_dirac_ana_fx( Word32 energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 energyRatio_q, surroundingCoherence_q = 0, spreadCoherence_q = 0; - move16(); - move16(); /* Estimate MASA parameters from the SBA signals */ ivas_dirac_param_est_ana_fx( hDirAC, data_fx, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame ); - energyRatio_q = 30; - move16(); /* Create MASA metadata buffer from the estimated values */ - ivas_create_masa_out_meta_fx( hDirAC->hMasaOut, hDirAC->sph_grid16, nchan_transport, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, energyRatio_q, spreadCoherence_q, surroundingCoherence_q ); + ivas_create_masa_out_meta_fx( hDirAC->hMasaOut, hDirAC->sph_grid16, nchan_transport, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, Q31, Q31, Q31 ); /* Downmix */ ivas_dirac_dmx_fx( data_fx, input_frame, nchan_transport ); // output Q of data_fx is same as that of input @@ -256,38 +271,37 @@ void ivas_dirac_ana_fx( static void ivas_dirac_param_est_ana_fx( DIRAC_ANA_HANDLE hDirAC, Word32 data_fx[][L_FRAME48k], /* Q7 */ - Word32 elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q22 */ - Word32 azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q22 */ - Word32 energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q30 */ - Word32 spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Qx */ - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Qx */ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q22 */ + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q22 */ + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q30 */ + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Qx */ + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Qx */ const Word16 input_frame ) { Word32 reference_power_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 ts, i, d, j; Word16 num_freq_bands, index; - Word32 dir_v[DIRAC_NUM_DIMS]; - Word16 dir_q; + Word32 dir_v_fx[DIRAC_NUM_DIMS]; + Word16 dir_v_q; Word16 l_ts; Word32 Foa_RealBuffer_fx[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; Word32 Foa_ImagBuffer_fx[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; Word32 intensity_real_fx[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; Word32 direction_vector_fx[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; - Word16 diffuseness_vector_exp[MASA_FREQUENCY_BANDS]; Word32 diffuseness_vector_fx[MASA_FREQUENCY_BANDS]; Word32 diffuseness_m_fx[MASA_FREQUENCY_BANDS]; - + Word16 diffuseness_e[MASA_FREQUENCY_BANDS]; + Word16 diffuseness_q = 0; + move16(); Word16 band_m_idx, block_m_idx; Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; + Word16 renormalization_factor_diff_e[MASA_FREQUENCY_BANDS]; Word32 norm_tmp_fx; Word16 mrange[2]; Word16 brange[2]; Word16 numAnalysisChannels; - Word16 io_q; - Word16 scale_fact, scale_fact2; - Word16 q_factor_intensity, q_factor_intensity_old = 0; - Word16 q_factor_energy = 0, q_factor_energy_old = 0; - Word16 exp = 0, exp_div = 0; + Word16 inp_q; + Word16 intensity_q, reference_power_q; num_freq_bands = hDirAC->nbands; /* l_ts = input_frame / CLDFB_NO_COL_MAX; */ l_ts = shr( input_frame, 4 ); @@ -327,24 +341,25 @@ static void ivas_dirac_param_est_ana_fx( FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { + Word16 cr_q = MAX_16, ci_q = MAX_16, sf, c_e; + inp_q = Q7; // Input Q of data_fx + move16(); + move16(); + move16(); FOR( i = 0; i < numAnalysisChannels; i++ ) { - io_q = Q7; // Input Q of data_fx - move16(); - cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][imult1616( l_ts, ts )] ), Foa_RealBuffer_fx[i], Foa_ImagBuffer_fx[i], l_ts, hDirAC->cldfbAnaEnc[i], &io_q ); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][imult1616( l_ts, ts )] ), Foa_RealBuffer_fx[i], Foa_ImagBuffer_fx[i], l_ts, hDirAC->cldfbAnaEnc[i], &inp_q ); + cr_q = s_min( cr_q, getScaleFactor32( Foa_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); + ci_q = s_min( ci_q, getScaleFactor32( Foa_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); } - scale_fact = getScaleFactor32( (const Word32 *) Foa_RealBuffer_fx, FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX ); - scale_fact = s_min( getScaleFactor32( (const Word32 *) Foa_ImagBuffer_fx, FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX ), scale_fact ); - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + sf = sub( s_min( cr_q, ci_q ), 4 ); + FOR( i = 0; i < numAnalysisChannels; i++ ) { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - Foa_RealBuffer_fx[i][j] = L_shl( Foa_RealBuffer_fx[i][j], sub( scale_fact, Q3 ) ); // Q( scale_fact + Q1 ) - move32(); - Foa_ImagBuffer_fx[i][j] = L_shl( Foa_ImagBuffer_fx[i][j], sub( scale_fact, Q3 ) ); // Q( scale_fact + Q1 ) - move32(); - } + scale_sig32( Foa_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); // Q-> inp_q + sf + scale_sig32( Foa_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); // Q-> inp_q + sf } + inp_q = add( inp_q, sf ); + c_e = sub( 31, inp_q ); /* Compute omni energy for metadata processing */ FOR( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) { @@ -354,191 +369,82 @@ static void ivas_dirac_param_est_ana_fx( move16(); FOR( j = brange[0]; j < brange[1]; j++ ) { - hDirAC->energy_fx[block_m_idx][band_m_idx] = ( L_add( hDirAC->energy_fx[block_m_idx][band_m_idx], L_add( Mpy_32_32( Foa_RealBuffer_fx[0][j], Foa_RealBuffer_fx[0][j] ), Mpy_32_32( Foa_ImagBuffer_fx[0][j], Foa_ImagBuffer_fx[0][j] ) ) ) ); // 2*( scale_fact + Q1 )-31 + Word32 temp = L_add( Mult_32_32( Foa_RealBuffer_fx[0][j], Foa_RealBuffer_fx[0][j] ), Mult_32_32( Foa_ImagBuffer_fx[0][j], Foa_ImagBuffer_fx[0][j] ) ); // Q-> 2*inp_q - 31, e = 31 - (2*inp_q - 31) = 62 - 2*inp_q = 2*(31 - inp_q) = 2*c_e + hDirAC->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->energy_fx[block_m_idx][band_m_idx], hDirAC->energy_e[block_m_idx][band_m_idx], temp, shl( c_e, 1 ), &hDirAC->energy_e[block_m_idx][band_m_idx] ); move32(); } } /* Direction estimation */ - computeIntensityVector_ana_fx( hDirAC->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); // 2 * ( scale_fact + Q1 ) - 31 - exp = sub( shl( sub( scale_fact, Q1 ), 1 ), 31 ); - - computeDirectionVectors_fx( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], &exp ); + computeIntensityVector_ana_fx( hDirAC->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); /* Q intensity_real_fx = 2*inp_q-31, e = 31 - 2*inp_q + 31 = 62 - 2*inp_q = 2*(31-inp_q)=2*c_e */ + intensity_q = sub(31 ,shl ( c_e, 1)); + computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], shl( c_e, 1 ), NULL ); /* Power estimation for diffuseness */ computeReferencePower_ana_fx( hDirAC->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx[ts], num_freq_bands ); //( 2 * ( scale_fact - Q1 ) - 31 - 1 ); // computeReferencePower_ana( hDirAC->band_grouping, Foa_RealBuffer, Foa_ImagBuffer, reference_power[ts], num_freq_bands ); - + reference_power_q = sub( shl( inp_q, 1 ), 30 ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ), 1 ); /* averaging_length = 32 */ move16(); index = hDirAC->index_buffer_intensity; move16(); - Word16 guard_bits = find_guarded_bits_fx( DIRAC_NO_COL_AVG_DIFF ); - scale_fact2 = getScaleFactor32( (const Word32 *) intensity_real_fx, DIRAC_NUM_DIMS * MASA_FREQUENCY_BANDS ); - IF( GT_16( guard_bits, scale_fact2 ) ) - { - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - intensity_real_fx[i][j] = L_shr( intensity_real_fx[i][j], sub( guard_bits, scale_fact2 ) ); - move32(); - } - } - q_factor_intensity = sub( sub( shl( sub( scale_fact, 1 ), 1 ), 31 ), sub( guard_bits, scale_fact2 ) ); - } - ELSE - { - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - intensity_real_fx[i][j] = L_shl( intensity_real_fx[i][j], sub( scale_fact2, guard_bits ) ); - move32(); - } - } - q_factor_intensity = add( sub( shl( sub( scale_fact, 1 ), 1 ), 31 ), sub( scale_fact2, guard_bits ) ); - } - scale_fact2 = getScaleFactor32( reference_power_fx[ts], MASA_FREQUENCY_BANDS ); - IF( GT_16( guard_bits, scale_fact2 ) ) - { - - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - reference_power_fx[ts][j] = L_shr( reference_power_fx[ts][j], sub( guard_bits, scale_fact2 ) ); - move32(); - } - - q_factor_energy = sub( sub( shl( scale_fact, 1 ), 31 ), sub( guard_bits, scale_fact2 ) ); - } - ELSE - { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - reference_power_fx[ts][j] = L_shl( reference_power_fx[ts][j], sub( scale_fact2, guard_bits ) ); - move32(); - } - - q_factor_energy = add( sub( shl( scale_fact, 1 ), 31 ), sub( scale_fact2, guard_bits ) ); - } - - IF( q_factor_intensity_old != 0 ) - { - - IF( LT_16( q_factor_intensity_old, q_factor_intensity ) ) - { - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - intensity_real_fx[i][j] = L_shr( intensity_real_fx[i][j], sub( q_factor_intensity, q_factor_intensity_old ) ); - move32(); - } - } - q_factor_intensity = q_factor_intensity_old; - move16(); - } - ELSE - { - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - FOR( j = 0; j < index - 1; j++ ) - { - /* only real part needed */ - FOR( Word16 k = 0; k < num_freq_bands; k++ ) - { - hDirAC->buffer_intensity_real_fx[i][j][k] = L_shr( hDirAC->buffer_intensity_real_fx[i][j][k], sub( q_factor_intensity_old, q_factor_intensity ) ); - move32(); - } - } - } - } - } - IF( q_factor_energy_old != 0 ) - { - - IF( LT_16( q_factor_energy_old, q_factor_energy ) ) - { - - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - reference_power_fx[ts][j] = L_shr( reference_power_fx[ts][j], sub( q_factor_energy, q_factor_energy_old ) ); - move32(); - } - - q_factor_energy = q_factor_energy_old; - move16(); - } - ELSE - { - FOR( i = 0; i < index - 1; i++ ) - { - FOR( j = 0; j < num_freq_bands; j++ ) - { - FOR( Word16 k = 0; k < num_freq_bands; k++ ) - { - hDirAC->buffer_energy_fx[add( imult1616( i, j ), k )] = L_shr( hDirAC->buffer_energy_fx[add( imult1616( i, j ), k )], sub( q_factor_energy_old, q_factor_energy_old ) ); - move32(); - } - } - } - } - } - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); // intensity_q } - Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[imult1616( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); - - computeDiffuseness_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, q_factor_intensity, q_factor_energy, diffuseness_vector_exp ); - q_factor_intensity_old = q_factor_intensity; + hDirAC->buffer_intensity_real_q[index - 1] = intensity_q; move16(); - q_factor_energy_old = q_factor_energy; + Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + hDirAC->buffer_energy_q[index - 1] = reference_power_q; move16(); - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - if ( LT_16( diffuseness_vector_exp[j], 10 ) ) - { - diffuseness_vector_fx[j] = 0; - move16(); - } - } + computeDiffuseness_fixed( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hDirAC->buffer_intensity_real_q, hDirAC->buffer_energy_q, &diffuseness_q ); FOR( band_m_idx = 0; band_m_idx < hDirAC->nbands; band_m_idx++ ) { - norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], ( L_sub( ONE_IN_Q30, L_shr( diffuseness_vector_fx[band_m_idx], sub( 30, diffuseness_vector_exp[band_m_idx] ) ) ) ) ); // q_factor_energy-1 + norm_tmp_fx = L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ), 1 ); /*2*inp_q-30*/ - hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ); // Q (q_factor_energy + exp -32) + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), shl( c_e, 1 ), &hDirAC->direction_vector_e[0][block_m_idx][band_m_idx] ); move32(); - hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ); // Q (q_factor_energy + exp -32) + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), shl( c_e, 1 ), &hDirAC->direction_vector_e[1][block_m_idx][band_m_idx] ); move32(); - hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ); // Q (q_factor_energy + exp -32) + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_e[2][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), shl( c_e, 1 ), &hDirAC->direction_vector_e[2][block_m_idx][band_m_idx] ); move32(); - - diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[ts][band_m_idx], L_shr( diffuseness_vector_fx[band_m_idx], sub( 30, diffuseness_vector_exp[band_m_idx] ) ) ) ); // Qq_factor_energy-1 + diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), 1 ), sub( shl( c_e, 1 ), 1 ), &diffuseness_e[band_m_idx] ); move32(); - renormalization_factor_diff_fx[band_m_idx] = L_add( renormalization_factor_diff_fx[band_m_idx], reference_power_fx[ts][band_m_idx] ); // Qq_factor_energy + + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], sub( shl( c_e, 1 ), 1 ), &renormalization_factor_diff_e[band_m_idx] ); move32(); + } + } - FOR( band_m_idx = 0; band_m_idx < hDirAC->nbands; band_m_idx++ ) { + Word16 max_e = MIN_16; + move16(); FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v[d] = hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx]; + max_e = s_max( max_e, hDirAC->direction_vector_e[d][block_m_idx][band_m_idx] ); + } + max_e = add( max_e, 1 ); /*1 as guard bit to prevent overflow*/ + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) + { + dir_v_fx[d] = L_shr( hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx], sub( max_e, hDirAC->direction_vector_e[d][block_m_idx][band_m_idx] ) ); move32(); } - dir_q = add( q_factor_energy, sub( exp, 32 ) ); - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v, dir_q, &azimuth_m_values[block_m_idx][band_m_idx], &elevation_m_values[block_m_idx][band_m_idx] ); + dir_v_q = sub( 31, max_e ); + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, dir_v_q, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); } /* Determine energy ratios */ FOR( band_m_idx = 0; band_m_idx < hDirAC->nbands; band_m_idx++ ) { + Word16 diffuseness_m_e; IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &exp_div ); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e ); + move32(); + diffuseness_m_e = add( diffuseness_m_e, sub( diffuseness_e[band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); + diffuseness_m_fx[band_m_idx] = L_shl_sat( diffuseness_m_fx[band_m_idx], add( 16, diffuseness_m_e ) ); // Q31 move32(); } ELSE @@ -546,16 +452,14 @@ static void ivas_dirac_param_est_ana_fx( diffuseness_m_fx[band_m_idx] = 0; move32(); } - exp_div = sub( 30, exp_div ); - energyRatio[block_m_idx][band_m_idx] = L_sub( L_shl( 1, 30 ), L_shl( diffuseness_m_fx[band_m_idx], sub( 30, exp_div ) ) ); // Q30 + energyRatio_fx[block_m_idx][band_m_idx] = L_sub( ONE_IN_Q31, diffuseness_m_fx[band_m_idx] ); move32(); } - FOR( band_m_idx = 0; band_m_idx < hDirAC->nbands; band_m_idx++ ) { - spreadCoherence[block_m_idx][band_m_idx] = 0; + spreadCoherence_fx[block_m_idx][band_m_idx] = 0; move32(); - surroundingCoherence[block_m_idx][band_m_idx] = 0; + surroundingCoherence_fx[block_m_idx][band_m_idx] = 0; move32(); } } diff --git a/lib_rend/ivas_masa_merge_fx.c b/lib_rend/ivas_masa_merge_fx.c index fd20a9fab..65829e1c8 100644 --- a/lib_rend/ivas_masa_merge_fx.c +++ b/lib_rend/ivas_masa_merge_fx.c @@ -209,7 +209,7 @@ void diffuse_meta_merge_1x1_fx( tmp = BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, L_add( EPSILON_FX, total_nrg_fx ), &scale ); scale = add( scale, sub( total_diff_nrg_e, total_nrg_e ) ); - dir_nrg_ratio_fx = L_sub( L_shl( 1, scale ), L_deposit_h( tmp ) ); + dir_nrg_ratio_fx = L_sub( L_shl_sat( 1, sub( 31, scale ) ), L_deposit_h( tmp ) ); dir_nrg_ratio_e = scale; move16(); @@ -239,7 +239,7 @@ void diffuse_meta_merge_1x1_fx( { new_diff_ratio_fx = L_sub( L_shl( 1, sub( 31, new_dir_ratio_e ) ), new_dir_ratio_fx ); /* Q(31 - new_dir_ratiio_e) */ } - outMeta->diffuseToTotalRatio[sf][band] = (UWord8) imult1616( extract_l( L_shr( new_diff_ratio_fx, new_dir_ratio_e ) ), UINT8_MAX ); + outMeta->diffuseToTotalRatio[sf][band] = (UWord8) imult1616( extract_l( L_shr( new_diff_ratio_fx, sub( 31, new_dir_ratio_e ) ) ), UINT8_MAX ); move16(); } ELSE diff --git a/lib_rend/ivas_omasa_ana_fx.c b/lib_rend/ivas_omasa_ana_fx.c index 7b7f64c84..1a579aece 100644 --- a/lib_rend/ivas_omasa_ana_fx.c +++ b/lib_rend/ivas_omasa_ana_fx.c @@ -159,6 +159,18 @@ ivas_error ivas_omasa_ana_open( } set_zero_fx( hOMasa->direction_vector_m_fx[i][j], MASA_FREQUENCY_BANDS ); } + IF( ( hOMasa->direction_vector_e[i] = (Word16 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( ( hOMasa->direction_vector_e[i][j] = (Word16 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + } } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -172,7 +184,8 @@ ivas_error ivas_omasa_ana_open( set_zero_fx( hOMasa->buffer_intensity_real_fx[i][j], MASA_FREQUENCY_BANDS ); } } - + set16_fx( hOMasa->buffer_intensity_real_q, 31, DIRAC_NO_COL_AVG_DIFF ); + set16_fx( hOMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); set_zero_fx( hOMasa->buffer_energy_fx, DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS ); FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -249,6 +262,12 @@ void ivas_omasa_ana_close( ( *hOMasa )->direction_vector_m_fx[i][j] = NULL; } + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + free( ( *hOMasa )->direction_vector_e[i][j] ); + ( *hOMasa )->direction_vector_e[i][j] = NULL; + } + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { free( ( *hOMasa )->buffer_intensity_real_fx[i][j] ); @@ -298,7 +317,7 @@ void ivas_omasa_ana_fx( /* Create MASA metadata buffer from the estimated values */ - ivas_create_masa_out_meta_fx( hOMasa->hMasaOut, hOMasa->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, energyRatio_q, spreadCoherence_q, sorroundingCoherence_q ); + ivas_create_masa_out_meta_fx( hOMasa->hMasaOut, hOMasa->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); /* Downmix */ ivas_omasa_dmx_fx( data_in_f_fx, data_in_q, input_frame, nchan_transport, nchan_ism, hOMasa->ism_azimuth_fx, hOMasa->ism_elevation_fx, hOMasa->prev_object_dm_gains_fx, hOMasa->interpolator_fx ); @@ -332,7 +351,7 @@ static void ivas_omasa_param_est_ana_fx( Word16 num_freq_bins, num_freq_bands, index; Word16 l_ts; - Word32 reference_power_fx[MASA_FREQUENCY_BANDS]; + Word32 reference_power_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 Chnl_RealBuffer_fx[MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; Word16 Chnl_RealBuffer_q[MAX_NUM_OBJECTS]; Word16 Chnl_ImagBuffer_q[MAX_NUM_OBJECTS]; @@ -344,20 +363,16 @@ static void ivas_omasa_param_est_ana_fx( Word32 diffuseness_vector_fx[MASA_FREQUENCY_BANDS]; Word16 diffuseness_q = 0; move16(); + Word16 diffuseness_e[MASA_FREQUENCY_BANDS]; Word32 diffuseness_m_fx[MASA_FREQUENCY_BANDS]; - Word16 diffuseness_m_q = 0; - move16(); + Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; - Word16 renormalization_factor_diff_q = 0; - move16(); + Word16 renormalization_factor_diff_e[MASA_FREQUENCY_BANDS]; Word32 norm_tmp_fx; - Word16 scale; Word16 tmp_ener_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 dir_v_fx[DIRAC_NUM_DIMS], L_tmp1, L_tmp2; - Word16 dir_v_q, norm_tmp_q; - Word16 foa_q; - + Word32 dir_v_fx[DIRAC_NUM_DIMS]/*, L_tmp1, L_tmp2*/; + Word16 dir_v_q/*, norm_tmp_q*/; Word16 band_m_idx, block_m_idx; Word16 mrange[2]; @@ -367,13 +382,10 @@ static void ivas_omasa_param_est_ana_fx( move16(); num_freq_bands = hOMasa->nbands; move16(); - - // l_ts = input_frame / CLDFB_NO_COL_MAX; l_ts = shr( input_frame, 4 ); - move16(); Word16 intensity_q; - Word16 direction_q, reference_power_q; + Word16 reference_power_q; set16_zero_fx( Chnl_RealBuffer_q, MAX_NUM_OBJECTS ); set16_zero_fx( Chnl_ImagBuffer_q, MAX_NUM_OBJECTS ); @@ -381,37 +393,15 @@ static void ivas_omasa_param_est_ana_fx( /* Compute ISM to FOA matrices */ FOR( i = 0; i < nchan_ism; i++ ) { - Word16 tmp, tmp1; - // 180 in Q22 754974720 - hOMasa->chnlToFoaMtx_fx[0][i] = 32767; // 1 in Q15 - move16(); - - tmp = BASOP_Util_Divide3232_Scale( hOMasa->ism_azimuth_fx[i], 754974720, &scale ); - tmp = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 - tmp = getSinWord16( tmp ); // Q15 sine value - - tmp1 = BASOP_Util_Divide3232_Scale( hOMasa->ism_elevation_fx[i], 754974720, &scale ); - tmp1 = mult( tmp1, EVS_PI_FX ); - tmp1 = getCosWord16( tmp1 ); - hOMasa->chnlToFoaMtx_fx[1][i] = shl( mult( tmp, tmp1 ), 1 ); // Q14 + Q15 - Q15 + Q1 -> Q15 - move16(); - - tmp = BASOP_Util_Divide3232_Scale( hOMasa->ism_elevation_fx[i], 754974720, &scale ); - tmp = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 - hOMasa->chnlToFoaMtx_fx[2][i] = getSinWord16( tmp ); // Q15 - move16(); - - tmp = BASOP_Util_Divide3232_Scale( hOMasa->ism_azimuth_fx[i], 754974720, &scale ); - tmp = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 - tmp = getCosWord16( tmp ); // Q14 - - - tmp1 = BASOP_Util_Divide3232_Scale( hOMasa->ism_elevation_fx[i], 754974720, &scale ); - tmp1 = mult( tmp, EVS_PI_FX ); // Q13 + Q15 - Q15 --> Q13 - tmp1 = getCosWord16( tmp ); // Q14 + hOMasa->chnlToFoaMtx_fx[0][i] = ONE_IN_Q31; + move32(); + hOMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( Mpy_32_32( hOMasa->ism_azimuth_fx[i], 46603 /*32767/360*/ ) /*Q22+Q24-31=>Q15*/ ) ), getCosWord16R2( extract_l( Mpy_32_32( hOMasa->ism_elevation_fx[i], 46603 /*2^24/360*/ ) ) ) ); // Q31 + move32(); + hOMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( Mpy_32_32( hOMasa->ism_elevation_fx[i], 46603 /*2^24/360*/ ) ) ), 16 ); // Q31 + move32(); + hOMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( Mpy_32_32( hOMasa->ism_azimuth_fx[i], 46603 /*2^24/360*/ ) ) ), getCosWord16R2( extract_l( Mpy_32_32( hOMasa->ism_elevation_fx[i], 46603 /*2^24/360*/ ) ) ) ); // Q31 + move32(); - hOMasa->chnlToFoaMtx_fx[3][i] = shl( mult( tmp, tmp1 ), 2 ); // Q14 + Q14 - Q15 + Q2-> Q13 + Q2 -> Q15 - move16(); } /* do processing over all CLDFB time slots */ @@ -442,63 +432,29 @@ static void ivas_omasa_param_est_ana_fx( FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { + Word16 cr_q = MAX_16, ci_q = MAX_16, sf, c_e; + move16(); + move16(); + Word16 inp_q = data_f_q; + move16(); FOR( i = 0; i < nchan_ism; i++ ) { - Word16 in_q = Q11; + + inp_q = data_f_q; move16(); + cldfbAnalysis_ts_fx_fixed_q( &( data_f_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &inp_q ); - /* Keep input to cldfbAnalysis_ts_fx in Q11 */ - IF( NE_16( in_q, data_f_q ) ) - { - scale_sig32( &( data_f_fx[i][i_mult( l_ts, ts )] ), l_ts, sub( in_q, data_f_q ) ); /* Q11 */ - } - - cldfbAnalysis_ts_fx( &( data_f_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &in_q ); - - /* Restore data_f_fx to it's original Q */ - IF( NE_16( data_f_q, Q11 ) ) - { - scale_sig32( &( data_f_fx[i][i_mult( l_ts, ts )] ), l_ts, sub( data_f_q, Q11 ) ); /* Q(data_f_q) */ - } - - FOR( Word16 ind = 0; ind < CLDFB_NO_CHANNELS_MAX; ind++ ) - { - Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], 4 ); // Q: in_q - 4 - move32(); - Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], 4 ); // Q: in_q - 4 - move32(); - } - - Chnl_RealBuffer_q[i] = sub( in_q, 4 ); - move16(); - Chnl_ImagBuffer_q[i] = sub( in_q, 4 ); - move16(); + cr_q = s_min( cr_q, getScaleFactor32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); + ci_q = s_min( ci_q, getScaleFactor32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); } - - IF( GT_16( nchan_ism, 1 ) ) + sf = sub( s_min( cr_q, ci_q ), 4 ); + FOR( i = 0; i < nchan_ism; i++ ) { - Word16 anaBuf_com_q; - minimum_fx( Chnl_RealBuffer_q, nchan_ism, &anaBuf_com_q ); - - FOR( i = 0; i < nchan_ism; i++ ) - { - IF( NE_16( anaBuf_com_q, Chnl_RealBuffer_q[i] ) ) - { - FOR( Word16 ind = 0; ind < CLDFB_NO_CHANNELS_MAX; ind++ ) - { - Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], sub( Chnl_RealBuffer_q[i], anaBuf_com_q ) ); // Q: anaBuf_com_q - move32(); - Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], sub( Chnl_ImagBuffer_q[i], anaBuf_com_q ) ); // Q: anaBuf_com_q - move32(); - } - Chnl_ImagBuffer_q[i] = anaBuf_com_q; - move16(); - Chnl_RealBuffer_q[i] = anaBuf_com_q; - move16(); - } - } + scale_sig32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); // Q-> inp_q + sf + scale_sig32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); // Q-> inp_q + sf } - + inp_q = add( inp_q, sf ); + c_e = sub( 31, inp_q ); /* Compute channel-based energy for metadata processing */ FOR( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) @@ -510,21 +466,9 @@ static void ivas_omasa_param_est_ana_fx( FOR( j = brange[0]; j < brange[1]; j++ ) { FOR( i = 0; i < nchan_ism; i++ ) - { - Word16 tmp_e, tmp_r_q, tmp_i_q; - Word32 tmp_r, tmp_i, L_tmp_sum; - tmp_r_q = norm_l( Chnl_RealBuffer_fx[i][j] ); - tmp_r = L_shl( Chnl_RealBuffer_fx[i][j], tmp_r_q ); /* Q(Chnl_RealBuffer_q[i] + tmp_r_q) */ - tmp_r_q = add( tmp_r_q, Chnl_RealBuffer_q[i] ); - L_tmp1 = Mpy_32_32( tmp_r, tmp_r ); /* Q(2*tmp_r_q - 31)*/ - tmp_r_q = sub( add( tmp_r_q, tmp_r_q ), 31 ); - tmp_i_q = norm_l( Chnl_ImagBuffer_fx[i][j] ); - tmp_i = L_shl( Chnl_ImagBuffer_fx[i][j], tmp_i_q ); /* Q(Chnl_ImagBuffer_q[i] + tmp_i_q)*/ - tmp_i_q = add( tmp_i_q, Chnl_ImagBuffer_q[i] ); - tmp_i_q = sub( add( tmp_i_q, tmp_i_q ), 31 ); - L_tmp2 = Mpy_32_32( tmp_i, tmp_i ); /* Q(2*tmp_i_q - 31) */ - L_tmp_sum = BASOP_Util_Add_Mant32Exp( L_tmp1, sub( 31, tmp_r_q ), L_tmp2, sub( 31, tmp_i_q ), &tmp_e ); /* Q(31 - tmp_e) */ - hOMasa->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->energy_fx[block_m_idx][band_m_idx], tmp_ener_e[block_m_idx][band_m_idx], L_tmp_sum, tmp_e, &tmp_ener_e[block_m_idx][band_m_idx] ); /* Q(31 - tmp_ener_e[block_m_idx][band_m_idx]) */ + { + Word32 temp = L_add( Mult_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ), Mult_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ) ); // Q-> 2*inp_q - 31, e = 31 - (2*inp_q - 31) = 62 - 2*inp_q = 2*(31 - inp_q) = 2*c_e + hOMasa->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->energy_fx[block_m_idx][band_m_idx], hOMasa->energy_e[block_m_idx][band_m_idx], temp, shl( c_e, 1 ), &hOMasa->energy_e[block_m_idx][band_m_idx] ); move32(); } } @@ -533,8 +477,8 @@ static void ivas_omasa_param_est_ana_fx( /* Compute FOA */ /* W */ - Copy32( Chnl_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins ); - Copy32( Chnl_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins ); + Copy32( Chnl_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins );//inp_q + Copy32( Chnl_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins );//inp_q FOR( i = 1; i < nchan_ism; i++ ) { @@ -549,59 +493,42 @@ static void ivas_omasa_param_est_ana_fx( /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q + v_multc_fixed( Chnl_RealBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[1][0], Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[1][0], Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q } /* Z */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q + v_multc_fixed( Chnl_RealBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[2][0] , Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[2][0] , Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q } - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q + v_multc_fixed( Chnl_RealBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[3][0] , Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[3][0] , Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q - } - - /* Direction estimation */ - FOR( i = 0; i < FOA_CHANNELS; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) - move32(); - Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) - move32(); - } + v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q } - foa_q = sub( Chnl_ImagBuffer_q[0], 5 ); - computeIntensityVector_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); - - intensity_q = sub( shl( add( foa_q, Q1 ), 1 ), 31 ); - direction_q = intensity_q; - move16(); - - computeDirectionVectors_fx( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], &direction_q ); + computeIntensityVector_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx );/* Q intensity_real_fx = 2*inp_q-31, e = 31 - 2*inp_q + 31 = 62 - 2*inp_q = 2*(31-inp_q)=2*c_e */ + intensity_q = sub( 31, shl( c_e, 1 ) ); + computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], shl( c_e, 1 ), NULL ); /* Q direction_vector_fx = Q30*/ /* Power estimation for diffuseness */ - computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx, num_freq_bands ); // 2 * inputq - 30 - reference_power_q = sub( shl( Chnl_ImagBuffer_q[0], 1 ), 30 ); + computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx[ts], num_freq_bands ); // 2 * inputq - 30 + reference_power_q = sub( shl( inp_q, 1 ), 30 ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hOMasa->index_buffer_intensity = add( ( hOMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ), 1 ); /* averaging_length = 32 */ @@ -616,68 +543,61 @@ static void ivas_omasa_param_est_ana_fx( } hOMasa->buffer_intensity_real_q[index - 1] = intensity_q; move16(); - Copy32( reference_power_fx, &( hOMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + Copy32( reference_power_fx[ts], &( hOMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); hOMasa->buffer_energy_q[index - 1] = reference_power_q; move16(); - computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q ); + computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q );//diffuseness_q=Q30 FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 - norm_tmp_q = sub( add( reference_power_q, 30 ), 31 ); + norm_tmp_fx = L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ), 1 ); /*2*inp_q-30*/ - hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) + hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], hOMasa->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), shl( c_e, 1 ), &hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ); move32(); - - hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) + hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], hOMasa->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), shl( c_e, 1 ), &hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ); move32(); - hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) + hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], hOMasa->direction_vector_e[2][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), shl( c_e, 1 ), &hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ); move32(); - hOMasa->direction_vector_m_q = sub( add( norm_tmp_q, direction_q ), 31 ); - - - diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[band_m_idx], diffuseness_vector_fx[band_m_idx] ) ); // diffuseness_m_q: ( ( reference_power_q + diffuseness_q ) - 31 ); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), 1 ), sub( shl( c_e, 1 ), 1 ), &diffuseness_e[band_m_idx] ); move32(); - diffuseness_m_q = sub( add( reference_power_q, diffuseness_q ), 31 ); - renormalization_factor_diff_fx[band_m_idx] = L_add( renormalization_factor_diff_fx[band_m_idx], reference_power_fx[band_m_idx] ); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], sub( shl( c_e, 1 ), 1 ), &renormalization_factor_diff_e[band_m_idx] ); move32(); - renormalization_factor_diff_q = reference_power_q; - move16(); + } } FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { + Word16 max_e = MIN_16; + move16(); FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v_fx[d] = hOMasa->direction_vector_m_fx[d][block_m_idx][band_m_idx]; - move32(); + max_e = s_max( max_e, hOMasa->direction_vector_e[d][block_m_idx][band_m_idx] ); } - dir_v_q = hOMasa->direction_vector_m_q; - move16(); - - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + max_e = add( max_e, 1 ); /*1 as guard bit to prevent overflow*/ + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v_fx[i] = L_shr( dir_v_fx[i], 1 ); + dir_v_fx[d] = L_shr( hOMasa->direction_vector_m_fx[d][block_m_idx][band_m_idx], sub( max_e, hOMasa->direction_vector_e[d][block_m_idx][band_m_idx] ) ); move32(); } + dir_v_q = sub( 31, max_e ); - dir_v_q = sub( dir_v_q, 1 ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, dir_v_q, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); + } /* Determine energy ratios */ FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - IF( BASOP_Util_Cmp_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], sub( 31, renormalization_factor_diff_q ), L_deposit_h( EPSILON_FX ), 2 ) > 0 ) + Word16 diffuseness_m_e; + IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &scale ); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e ); move32(); - scale = add( scale, sub( sub( 31, diffuseness_m_q ), sub( 31, renormalization_factor_diff_q ) ) ); - - diffuseness_m_fx[band_m_idx] = L_shr( diffuseness_m_fx[band_m_idx], sub( 31, add( scale, diffuseness_m_q ) ) ); + diffuseness_m_e = add( diffuseness_m_e, sub( diffuseness_e[band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); + diffuseness_m_fx[band_m_idx] = L_shl_sat( diffuseness_m_fx[band_m_idx], add( 16, diffuseness_m_e ) ); // Q31 move32(); } ELSE @@ -685,7 +605,7 @@ static void ivas_omasa_param_est_ana_fx( diffuseness_m_fx[band_m_idx] = 0; move32(); } - energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); // Q: diffuseness_m_q + energyRatio_fx[block_m_idx][band_m_idx] = L_sub( ONE_IN_Q31, diffuseness_m_fx[band_m_idx] ); move32(); } @@ -698,40 +618,12 @@ static void ivas_omasa_param_est_ana_fx( move32(); } } - - Word16 q_ener_min = MAX_16; + *energyRatio_q = Q31; + *spreadCoherence_q = Q31; + *surroundingCoherence_q = Q31; move16(); - FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) - { - Word16 e_max; - maximum_fx( tmp_ener_e[block_m_idx], num_freq_bands, &e_max ); - e_max = sub( 31, e_max ); - if ( GT_16( q_ener_min, e_max ) ) - { - q_ener_min = e_max; - move16(); - } - } - - FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) - { - FOR( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) - { - hOMasa->energy_fx[block_m_idx][band_m_idx] = L_shr( hOMasa->energy_fx[block_m_idx][band_m_idx], sub( sub( 31, tmp_ener_e[block_m_idx][band_m_idx] ), q_ener_min ) ); /* Q(q_ener_min) */ - move32(); - } - } - - hOMasa->energy_q = q_ener_min; - move16(); - - *spreadCoherence_q = 0; - move16(); - *surroundingCoherence_q = 0; move16(); - *energyRatio_q = 0; move16(); - return; } diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 00fbc2549..588e416ca 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1597,13 +1597,14 @@ typedef struct ivas_omasa_ana_data_structure SPHERICAL_GRID_DATA *sph_grid16; Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ - Word16 direction_vector_m_q; /* Average direction vector */ + Word16 **direction_vector_e[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Average direction vector */ Word32 ism_azimuth_fx[MAX_NUM_OBJECTS]; Word32 ism_elevation_fx[MAX_NUM_OBJECTS]; Word32 energy_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_q; - Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES]; + Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 energy_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 interpolator_fx[L_FRAME48k]; Word32 prev_object_dm_gains_fx[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; @@ -1611,7 +1612,7 @@ typedef struct ivas_omasa_ana_data_structure Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; - Word16 chnlToFoaMtx_fx[FOA_CHANNELS][MCMASA_MAX_ANA_CHANS]; // Q15 + Word32 chnlToFoaMtx_fx[FOA_CHANNELS][MCMASA_MAX_ANA_CHANS]; // Q15 } OMASA_ANA_DATA, *OMASA_ANA_HANDLE; @@ -1629,13 +1630,16 @@ typedef struct ivas_dirac_ana_data_structure /* DirAC parameter estimation */ Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word16 **direction_vector_e[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Average direction vector */ Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; Word16 block_grouping[5]; /* diffuseness */ Word16 index_buffer_intensity; Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; + Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; MASA_DECODER_EXT_OUT_META_HANDLE hMasaOut; SPHERICAL_GRID_DATA *sph_grid16; diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index e39b9a61e..9a0f2a522 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -5644,11 +5644,6 @@ static ivas_error renderInputIsm( BREAK; case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: renderIsmToMasa( ismInput, outAudio, &exp ); - FOR( Word16 block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) - { - ismInput->hOMasa->energy_e[block_m_idx] = sub( 31, ismInput->hOMasa->energy_q ); - move16(); - } BREAK; default: return IVAS_ERR_INVALID_OUTPUT_FORMAT; @@ -7097,7 +7092,7 @@ ivas_error IVAS_REND_MergeMasaMetadata( { *hMasaExtOutMeta = hIvasRend->inputsIsm->hOMasa->hMasaOut; inEne1_fx = &( hIvasRend->inputsIsm->hOMasa->energy_fx ); - inEne1_e = ( hIvasRend->inputsIsm->hOMasa->energy_e ); + inEne1_e = ( hIvasRend->inputsIsm->hOMasa->energy_exp ); } ELSE IF( EQ_32( inputType1, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) { @@ -7127,7 +7122,7 @@ ivas_error IVAS_REND_MergeMasaMetadata( { inMeta2 = hIvasRend->inputsIsm->hOMasa->hMasaOut; inEne2_fx = &( hIvasRend->inputsIsm->hOMasa->energy_fx ); - inEne2_e = ( hIvasRend->inputsIsm->hOMasa->energy_e ); + inEne2_e = ( hIvasRend->inputsIsm->hOMasa->energy_exp ); } ELSE IF( EQ_32( inputType2, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) { -- GitLab From bcb13845eb74b07d83331f1dde7b34e13853494c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Jun 2025 15:28:46 +0530 Subject: [PATCH 29/54] Clang formatting changes --- lib_rend/ivas_dirac_ana_fx.c | 8 +++----- lib_rend/ivas_omasa_ana_fx.c | 29 +++++++++++++---------------- lib_rend/ivas_stat_rend.h | 4 ++-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib_rend/ivas_dirac_ana_fx.c b/lib_rend/ivas_dirac_ana_fx.c index 0e3686197..4fd86c9fe 100644 --- a/lib_rend/ivas_dirac_ana_fx.c +++ b/lib_rend/ivas_dirac_ana_fx.c @@ -270,7 +270,7 @@ void ivas_dirac_ana_fx( /* Estimate MASA parameters from the SBA signals */ static void ivas_dirac_param_est_ana_fx( DIRAC_ANA_HANDLE hDirAC, - Word32 data_fx[][L_FRAME48k], /* Q7 */ + Word32 data_fx[][L_FRAME48k], /* Q7 */ Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q22 */ Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q22 */ Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q30 */ @@ -355,7 +355,7 @@ static void ivas_dirac_param_est_ana_fx( sf = sub( s_min( cr_q, ci_q ), 4 ); FOR( i = 0; i < numAnalysisChannels; i++ ) { - scale_sig32( Foa_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); // Q-> inp_q + sf + scale_sig32( Foa_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); // Q-> inp_q + sf scale_sig32( Foa_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, sf ); // Q-> inp_q + sf } inp_q = add( inp_q, sf ); @@ -376,7 +376,7 @@ static void ivas_dirac_param_est_ana_fx( } /* Direction estimation */ computeIntensityVector_ana_fx( hDirAC->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); /* Q intensity_real_fx = 2*inp_q-31, e = 31 - 2*inp_q + 31 = 62 - 2*inp_q = 2*(31-inp_q)=2*c_e */ - intensity_q = sub(31 ,shl ( c_e, 1)); + intensity_q = sub( 31, shl( c_e, 1 ) ); computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], shl( c_e, 1 ), NULL ); /* Power estimation for diffuseness */ @@ -414,9 +414,7 @@ static void ivas_dirac_param_est_ana_fx( renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], sub( shl( c_e, 1 ), 1 ), &renormalization_factor_diff_e[band_m_idx] ); move32(); - } - } FOR( band_m_idx = 0; band_m_idx < hDirAC->nbands; band_m_idx++ ) { diff --git a/lib_rend/ivas_omasa_ana_fx.c b/lib_rend/ivas_omasa_ana_fx.c index 1a579aece..f82ac12bd 100644 --- a/lib_rend/ivas_omasa_ana_fx.c +++ b/lib_rend/ivas_omasa_ana_fx.c @@ -371,8 +371,8 @@ static void ivas_omasa_param_est_ana_fx( Word32 norm_tmp_fx; Word16 tmp_ener_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 dir_v_fx[DIRAC_NUM_DIMS]/*, L_tmp1, L_tmp2*/; - Word16 dir_v_q/*, norm_tmp_q*/; + Word32 dir_v_fx[DIRAC_NUM_DIMS] /*, L_tmp1, L_tmp2*/; + Word16 dir_v_q /*, norm_tmp_q*/; Word16 band_m_idx, block_m_idx; Word16 mrange[2]; @@ -401,7 +401,6 @@ static void ivas_omasa_param_est_ana_fx( move32(); hOMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( Mpy_32_32( hOMasa->ism_azimuth_fx[i], 46603 /*2^24/360*/ ) ) ), getCosWord16R2( extract_l( Mpy_32_32( hOMasa->ism_elevation_fx[i], 46603 /*2^24/360*/ ) ) ) ); // Q31 move32(); - } /* do processing over all CLDFB time slots */ @@ -439,7 +438,7 @@ static void ivas_omasa_param_est_ana_fx( move16(); FOR( i = 0; i < nchan_ism; i++ ) { - + inp_q = data_f_q; move16(); cldfbAnalysis_ts_fx_fixed_q( &( data_f_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &inp_q ); @@ -466,8 +465,8 @@ static void ivas_omasa_param_est_ana_fx( FOR( j = brange[0]; j < brange[1]; j++ ) { FOR( i = 0; i < nchan_ism; i++ ) - { - Word32 temp = L_add( Mult_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ), Mult_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ) ); // Q-> 2*inp_q - 31, e = 31 - (2*inp_q - 31) = 62 - 2*inp_q = 2*(31 - inp_q) = 2*c_e + { + Word32 temp = L_add( Mult_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ), Mult_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ) ); // Q-> 2*inp_q - 31, e = 31 - (2*inp_q - 31) = 62 - 2*inp_q = 2*(31 - inp_q) = 2*c_e hOMasa->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->energy_fx[block_m_idx][band_m_idx], hOMasa->energy_e[block_m_idx][band_m_idx], temp, shl( c_e, 1 ), &hOMasa->energy_e[block_m_idx][band_m_idx] ); move32(); } @@ -477,8 +476,8 @@ static void ivas_omasa_param_est_ana_fx( /* Compute FOA */ /* W */ - Copy32( Chnl_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins );//inp_q - Copy32( Chnl_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins );//inp_q + Copy32( Chnl_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins ); // inp_q + Copy32( Chnl_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins ); // inp_q FOR( i = 1; i < nchan_ism; i++ ) { @@ -504,8 +503,8 @@ static void ivas_omasa_param_est_ana_fx( /* Z */ - v_multc_fixed( Chnl_RealBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[2][0] , Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_fixed( Chnl_ImagBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[2][0] , Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q + v_multc_fixed( Chnl_RealBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[2][0], Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[2][0], Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { @@ -513,15 +512,15 @@ static void ivas_omasa_param_est_ana_fx( v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q } - v_multc_fixed( Chnl_RealBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[3][0] , Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q - v_multc_fixed( Chnl_ImagBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[3][0] , Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q + v_multc_fixed( Chnl_RealBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[3][0], Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], hOMasa->chnlToFoaMtx_fx[3][0], Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { v_multc_acc_32_32( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q } - computeIntensityVector_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx );/* Q intensity_real_fx = 2*inp_q-31, e = 31 - 2*inp_q + 31 = 62 - 2*inp_q = 2*(31-inp_q)=2*c_e */ + computeIntensityVector_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); /* Q intensity_real_fx = 2*inp_q-31, e = 31 - 2*inp_q + 31 = 62 - 2*inp_q = 2*(31-inp_q)=2*c_e */ intensity_q = sub( 31, shl( c_e, 1 ) ); computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], shl( c_e, 1 ), NULL ); /* Q direction_vector_fx = Q30*/ @@ -547,7 +546,7 @@ static void ivas_omasa_param_est_ana_fx( hOMasa->buffer_energy_q[index - 1] = reference_power_q; move16(); - computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q );//diffuseness_q=Q30 + computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q ); // diffuseness_q=Q30 FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { @@ -564,7 +563,6 @@ static void ivas_omasa_param_est_ana_fx( move32(); renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], sub( shl( c_e, 1 ), 1 ), &renormalization_factor_diff_e[band_m_idx] ); move32(); - } } @@ -585,7 +583,6 @@ static void ivas_omasa_param_est_ana_fx( dir_v_q = sub( 31, max_e ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, dir_v_q, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); - } /* Determine energy ratios */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 588e416ca..2654e5a53 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1596,7 +1596,7 @@ typedef struct ivas_omasa_ana_data_structure MASA_DECODER_EXT_OUT_META_HANDLE hMasaOut; SPHERICAL_GRID_DATA *sph_grid16; - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ Word16 **direction_vector_e[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Average direction vector */ Word32 ism_azimuth_fx[MAX_NUM_OBJECTS]; Word32 ism_elevation_fx[MAX_NUM_OBJECTS]; @@ -1629,7 +1629,7 @@ typedef struct ivas_dirac_ana_data_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[DIRAC_MAX_ANA_CHANS]; /* DirAC parameter estimation */ - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ Word16 **direction_vector_e[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Average direction vector */ Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; Word16 block_grouping[5]; -- GitLab From 4272cc79608cb23134b2d8260f1c2eede5d4e8d4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Jun 2025 15:55:30 +0530 Subject: [PATCH 30/54] Added missed pointer freeing in renderer --- lib_rend/ivas_dirac_ana_fx.c | 5 ++++- lib_rend/ivas_omasa_ana_fx.c | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib_rend/ivas_dirac_ana_fx.c b/lib_rend/ivas_dirac_ana_fx.c index 4fd86c9fe..f282e8390 100644 --- a/lib_rend/ivas_dirac_ana_fx.c +++ b/lib_rend/ivas_dirac_ana_fx.c @@ -214,6 +214,9 @@ void ivas_dirac_ana_close_fx( ( *hDirAC )->direction_vector_e[i][j] = NULL; } + free( ( *hDirAC )->direction_vector_e[i] ); + ( *hDirAC )->direction_vector_e[i] = NULL; + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { free( ( *hDirAC )->buffer_intensity_real_fx[i][j] ); @@ -348,7 +351,7 @@ static void ivas_dirac_param_est_ana_fx( move16(); FOR( i = 0; i < numAnalysisChannels; i++ ) { - cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][imult1616( l_ts, ts )] ), Foa_RealBuffer_fx[i], Foa_ImagBuffer_fx[i], l_ts, hDirAC->cldfbAnaEnc[i], &inp_q ); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][( l_ts * ts )] ), Foa_RealBuffer_fx[i], Foa_ImagBuffer_fx[i], l_ts, hDirAC->cldfbAnaEnc[i], &inp_q ); cr_q = s_min( cr_q, getScaleFactor32( Foa_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); ci_q = s_min( ci_q, getScaleFactor32( Foa_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); } diff --git a/lib_rend/ivas_omasa_ana_fx.c b/lib_rend/ivas_omasa_ana_fx.c index f82ac12bd..bce8870c8 100644 --- a/lib_rend/ivas_omasa_ana_fx.c +++ b/lib_rend/ivas_omasa_ana_fx.c @@ -276,6 +276,9 @@ void ivas_omasa_ana_close( free( ( *hOMasa )->direction_vector_m_fx[i] ); ( *hOMasa )->direction_vector_m_fx[i] = NULL; + + free( ( *hOMasa )->direction_vector_e[i] ); + ( *hOMasa )->direction_vector_e[i] = NULL; } free( ( *hOMasa )->hMasaOut ); -- GitLab From 86af060636474ee4b1b2fa54912cbe2ab355ed4b Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 5 Jun 2025 16:17:55 +0200 Subject: [PATCH 31/54] Fix cldfbAnalysis_ts_fx() in regard to the consistency of real/imag output buffers scale respective to q_cldfb. --- lib_com/cldfb_fx.c | 19 +++++++++++++++++++ lib_com/options.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/lib_com/cldfb_fx.c b/lib_com/cldfb_fx.c index bf832b640..06d72668f 100644 --- a/lib_com/cldfb_fx.c +++ b/lib_com/cldfb_fx.c @@ -519,6 +519,7 @@ void cldfbAnalysis_ts_fx( } fft_cldfb_fx( rBuffer_fx, M2 ); +#ifndef FIX_1733_CLDFB_BUG /* post modulation of DST IV */ FOR( k = 0; k < M2; k++ ) { @@ -533,6 +534,7 @@ void cldfbAnalysis_ts_fx( move32(); move32(); } +#endif *q_cldfb = sub( *q_cldfb, 2 ); move16(); @@ -553,6 +555,23 @@ void cldfbAnalysis_ts_fx( move32(); } +#ifdef FIX_1733_CLDFB_BUG + /* post modulation of DST IV */ + FOR( k = 0; k < M2; k++ ) + { + /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ +#ifdef OPT_AVOID_STATE_BUF_RESCALE + realBuffer_fx[( ( M1 - 1 ) - ( k * 2 ) )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 + realBuffer_fx[2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 +#else /* OPT_AVOID_STATE_BUF_RESCALE */ + realBuffer_fx[( ( M1 - 1 ) - ( k * 2 ) )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + move32(); + move32(); + } + +#endif /* post modulation of DCT IV */ FOR( k = 0; k < M2; k++ ) { diff --git a/lib_com/options.h b/lib_com/options.h index a5d5a4846..12580b20d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -106,4 +106,6 @@ #define FIX_1713_EXP /* VA: proposed correction to exp in ic-BWE*/ +#define FIX_1733_CLDFB_BUG + #endif -- GitLab From 6e410b332207a461eb284ba31d77a6cf928324fa Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 5 Jun 2025 16:21:38 +0200 Subject: [PATCH 32/54] clang format --- lib_com/cldfb_fx.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib_com/cldfb_fx.c b/lib_com/cldfb_fx.c index 06d72668f..ede4be78b 100644 --- a/lib_com/cldfb_fx.c +++ b/lib_com/cldfb_fx.c @@ -417,8 +417,8 @@ void cldfbAnalysis_ts_fx( rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 #else /* OPT_AVOID_STATE_BUF_RESCALE */ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 #endif /* OPT_AVOID_STATE_BUF_RESCALE */ move32(); move32(); @@ -431,8 +431,8 @@ void cldfbAnalysis_ts_fx( iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 #else /* OPT_AVOID_STATE_BUF_RESCALE */ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 #endif /* OPT_AVOID_STATE_BUF_RESCALE */ move32(); move32(); @@ -478,8 +478,8 @@ void cldfbAnalysis_ts_fx( rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 #else /* OPT_AVOID_STATE_BUF_RESCALE */ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 #endif /* OPT_AVOID_STATE_BUF_RESCALE */ move32(); move32(); @@ -492,8 +492,8 @@ void cldfbAnalysis_ts_fx( iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 #else /* OPT_AVOID_STATE_BUF_RESCALE */ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 #endif /* OPT_AVOID_STATE_BUF_RESCALE */ move32(); move32(); @@ -581,8 +581,8 @@ void cldfbAnalysis_ts_fx( imagBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 imagBuffer_fx[( M1 - 1 ) - ( k * 2 )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 #else /* OPT_AVOID_STATE_BUF_RESCALE */ - imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 - imagBuffer_fx[( M1 - 1 ) - ( k * 2 )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 + imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 + imagBuffer_fx[( M1 - 1 ) - ( k * 2 )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 #endif /* OPT_AVOID_STATE_BUF_RESCALE */ move32(); move32(); @@ -608,8 +608,8 @@ void cldfbAnalysis_ts_fx( cplx_aux_fx = Msub_32_32( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ); // q - 5 imagBuffer_fx[k] = Madd_32_32( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ); // q - 5 #else /* OPT_AVOID_STATE_BUF_RESCALE */ - cplx_aux_fx = L_sub( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ) ); // q - 5 - imagBuffer_fx[k] = L_add( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ) ); // q - 5 + cplx_aux_fx = L_sub( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ) ); // q - 5 + imagBuffer_fx[k] = L_add( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ) ); // q - 5 #endif /* OPT_AVOID_STATE_BUF_RESCALE */ realBuffer_fx[k] = cplx_aux_fx; move32(); -- GitLab From b55b837d06be2c2f160ac01f8c9bc2c8356f6c59 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 9 Jun 2025 11:29:32 +0530 Subject: [PATCH 33/54] Fix for 3GPP issue 1731: OMASA BASOP bitstream crashing float decoder (ivas_mdct_core_invQ) Link #1731 --- lib_com/ivas_cnst.h | 2 +- lib_com/ivas_masa_com_fx.c | 6 +++--- lib_com/ivas_prot_fx.h | 2 +- lib_dec/ivas_masa_dec_fx.c | 2 +- lib_enc/ivas_masa_enc_fx.c | 8 +------- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 097ba1789..d3e52ec16 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -383,7 +383,7 @@ typedef enum #define PARAM_ISM_MAX_CHAN 16 #define PARAM_ISM_HYS_BUF_SIZE 10 -#define STEP_PARAM_ISM_POW_RATIO_NBITS_Q15 (4681) /* 1.0f / (float)((1 << PARAM_ISM_POW_RATIO_NBITS) - 1) */ +#define STEP_PARAM_ISM_POW_RATIO_NBITS_Q31 (306783378) /* 1.0f / (float)((1 << PARAM_ISM_POW_RATIO_NBITS) - 1) */ /* ISM DTX */ #define ISM_Q_STEP_FX ( 10485760 ) // Q22 diff --git a/lib_com/ivas_masa_com_fx.c b/lib_com/ivas_masa_com_fx.c index cfed06357..a28e229ff 100644 --- a/lib_com/ivas_masa_com_fx.c +++ b/lib_com/ivas_masa_com_fx.c @@ -1308,7 +1308,7 @@ Word16 valid_ratio_index_fx( void reconstruct_ism_ratios_fx( Word16 *ratio_ism_idx, /* i : index vector Q0 */ const Word16 nchan_ism, /* i : number of components/objects Q0 */ - const Word16 step, /* i : quantization step Q15 */ + const Word32 step, /* i : quantization step Q31 */ Word32 *q_energy_ratio_ism /* o : reconstructed ISM values Q30 */ ) { @@ -1317,10 +1317,10 @@ void reconstruct_ism_ratios_fx( sum = 0; move32(); - + FOR( i = 0; i < nchan_ism - 1; i++ ) { - q_energy_ratio_ism[i] = L_shl( L_mult( ratio_ism_idx[i], step ), 14 ); // q0 + q15 + 1 + 14 = q30; + q_energy_ratio_ism[i] = W_extract_l(W_shr( W_mult_32_16( step, ratio_ism_idx[i] ), 2 )); // q0 + q31 + 1 - 2 = q30; move32(); sum = L_add( sum, q_energy_ratio_ism[i] ); // Q30 diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index d9ca855be..542f9e0e9 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -115,7 +115,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( void reconstruct_ism_ratios_fx( Word16 *ratio_ism_idx, /* i : index vector Q0 */ const Word16 nchan_ism, /* i : number of components/objects Q0 */ - const Word16 step, /* i : quantization step Q15 */ + const Word32 step, /* i : quantization step Q31 */ Word32 *q_energy_ratio_ism /* o : reconstructed ISM values Q30 */ ); diff --git a/lib_dec/ivas_masa_dec_fx.c b/lib_dec/ivas_masa_dec_fx.c index 36900867e..e61e51262 100644 --- a/lib_dec/ivas_masa_dec_fx.c +++ b/lib_dec/ivas_masa_dec_fx.c @@ -3097,7 +3097,7 @@ static void decode_ism_ratios_fx( /* reconstructed values */ FOR( band = 0; band < nbands; band++ ) { - reconstruct_ism_ratios_fx( ratio_ism_idx[band], n_ism, STEP_PARAM_ISM_POW_RATIO_NBITS_Q15, ratio_ism[sf][band] ); + reconstruct_ism_ratios_fx( ratio_ism_idx[band], n_ism, STEP_PARAM_ISM_POW_RATIO_NBITS_Q31, ratio_ism[sf][band] ); } test(); diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 303d11698..fb86dee7a 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -4666,7 +4666,6 @@ static void ivas_encode_masaism_metadata_fx( UWord16 index_theta, index_phi; Word16 ratio_ism_fx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - Word16 step; Word32 energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; Word16 tmp, rotate, energy_ism_e, energy_ism_ind_e[MAX_NUM_OBJECTS]; Word16 n_ism_tmp, i; @@ -4919,11 +4918,6 @@ static void ivas_encode_masaism_metadata_fx( /* quantize ism_ratios */ IF( GT_16( nchan_ism, 1 ) ) { - /* inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); * - * step = 1.0f / inv_step; */ - step = 4681; // 1.f / ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) => 1.f / 7 in Q15 - move16(); - rotate = 0; n_ism_tmp = 0; move16(); @@ -4968,7 +4962,7 @@ static void ivas_encode_masaism_metadata_fx( } /* reconstructed values */ - reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); + reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, STEP_PARAM_ISM_POW_RATIO_NBITS_Q31, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); } test(); IF( GT_16( nchan_ism, 2 ) && EQ_16( idx_separated_object, sub( nchan_ism, 1 ) ) ) -- GitLab From 027d6aa2294158b013f6b2b97126bdbcc040de62 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 9 Jun 2025 11:33:58 +0530 Subject: [PATCH 34/54] Clang formatting changes --- lib_com/ivas_masa_com_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_masa_com_fx.c b/lib_com/ivas_masa_com_fx.c index a28e229ff..a691fb390 100644 --- a/lib_com/ivas_masa_com_fx.c +++ b/lib_com/ivas_masa_com_fx.c @@ -1317,10 +1317,10 @@ void reconstruct_ism_ratios_fx( sum = 0; move32(); - + FOR( i = 0; i < nchan_ism - 1; i++ ) { - q_energy_ratio_ism[i] = W_extract_l(W_shr( W_mult_32_16( step, ratio_ism_idx[i] ), 2 )); // q0 + q31 + 1 - 2 = q30; + q_energy_ratio_ism[i] = W_extract_l( W_shr( W_mult_32_16( step, ratio_ism_idx[i] ), 2 ) ); // q0 + q31 + 1 - 2 = q30; move32(); sum = L_add( sum, q_energy_ratio_ism[i] ); // Q30 -- GitLab From dae6401d9374fdde1bced371758d7d6e6398a9f9 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 9 Jun 2025 19:30:09 +0530 Subject: [PATCH 35/54] Fix for 3GPP issue 1730: Rendering MASA LTV has severe audible distortions Link #1730 --- .../ivas_dirac_dec_binaural_functions_fx.c | 107 +++++++++--------- lib_rend/ivas_rotation_fx.c | 9 +- lib_rend/ivas_stat_rend.h | 4 +- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 2db86d6eb..6dc701468 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -2740,14 +2740,12 @@ static void adaptTransportSignalsHeadtracked_fx( Word16 slot, ch, bin, louderCh; Word32 mono_factor_ILD, mono_factor; Word32 y_val, mono_factor_rotation, ene_proc, ene_target, ILD; + Word16 ene_proc_e, ene_target_e; Word16 max_band; Word32 eqVal; Word16 band_idx, bin_lo, bin_hi, norm, shift = 31; - Word16 q_chEneIIR = 0, q_procChEneIIR = 0; Word32 temp_div; - Word16 e_div, tmp, is_zero, i; - move16(); - move16(); + Word16 e_div, is_zero, i; move16(); #ifdef OPT_BIN_RENDERER_V1 @@ -2793,16 +2791,17 @@ static void adaptTransportSignalsHeadtracked_fx( shift = sub( shift, 5 ); // 5 is gaurded bits needed// Word32 re, img, temp; - Word16 q_temp = sub( imult1616( 2, add( q_inp, shift ) ), 31 ); + Word16 s, q_band_nrg, q_temp[2]; FOR( band_idx = 0; band_idx < max_band; band_idx++ ) { - Word32 ch_nrg[2]; /* storage for input signal channel energies */ + Word32 ch_nrg[2]; /* storage for input signal channel energies */ + Word64 W_ch_nrg[2]; /* storage for input signal channel energies */ bin_lo = MASA_band_grouping_24[band_idx]; bin_hi = s_min( MASA_band_grouping_24[band_idx + 1], (Word16) nBins ); FOR( ch = 0; ch < 2; ch++ ) { - ch_nrg[ch] = 0; + W_ch_nrg[ch] = 0; move32(); FOR( slot = 0; slot < nSlots; slot++ ) { @@ -2811,24 +2810,31 @@ static void adaptTransportSignalsHeadtracked_fx( re = L_shl( inRe_fx[ch][slot][bin], shift ); img = L_shl( inIm_fx[ch][slot][bin], shift ); - ch_nrg[ch] = L_add( ch_nrg[ch], ( L_add( Mpy_32_32( re, re ), Mpy_32_32( img, img ) ) ) ); // 2(q_inp +shift) -31 - move32(); + W_ch_nrg[ch] = W_add( W_ch_nrg[ch], ( W_add( W_mult0_32_32( re, re ), W_mult0_32_32( img, img ) ) ) ); // 2(q_inp +shift) + move64(); } } + s = W_norm( W_ch_nrg[ch] ); + ch_nrg[ch] = W_extract_h( W_shl( W_ch_nrg[ch], s ) ); // Q: 2*(q_inp+shift) + s - 32 + q_temp[ch] = sub( add( shl( add( q_inp, shift ), 1 ), s ), 32 ); + move32(); + move16(); + hHeadTrackData->chEneIIR_fx[ch][band_idx] = Mpy_32_16_1( hHeadTrackData->chEneIIR_fx[ch][band_idx], ADAPT_HTPROTO_IIR_FAC_FX ); // q_chEneIIR move32(); - temp = Mpy_32_16_1( ch_nrg[ch], sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); - IF( LT_16( hHeadTrackData->q_chEneIIR, q_temp ) ) + temp = Mpy_32_16_1( ch_nrg[ch], sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); // q_temp[ch] + IF( LT_16( hHeadTrackData->q_chEneIIR[ch][band_idx], q_temp[ch] ) ) { - hHeadTrackData->chEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp, hHeadTrackData->q_chEneIIR ) ), hHeadTrackData->chEneIIR_fx[ch][band_idx] ); + hHeadTrackData->chEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp[ch], hHeadTrackData->q_chEneIIR[ch][band_idx] ) ), hHeadTrackData->chEneIIR_fx[ch][band_idx] ); // hHeadTrackData->q_chEneIIR[ch][band_idx] } ELSE { - hHeadTrackData->chEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->chEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_chEneIIR, q_temp ) ), temp ); + hHeadTrackData->chEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->chEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_chEneIIR[ch][band_idx], q_temp[ch] ) ), temp ); // q_temp[ch] } move32(); + hHeadTrackData->q_chEneIIR[ch][band_idx] = s_min( hHeadTrackData->q_chEneIIR[ch][band_idx], q_temp[ch] ); + move16(); } - q_chEneIIR = s_min( hHeadTrackData->q_chEneIIR, q_temp ); /* Determine ILD */ IF( EQ_32( L_max( 1, hHeadTrackData->chEneIIR_fx[0][band_idx] ), L_max( 1, hHeadTrackData->chEneIIR_fx[1][band_idx] ) ) ) @@ -2839,7 +2845,7 @@ static void adaptTransportSignalsHeadtracked_fx( ELSE { temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( L_max( 1, hHeadTrackData->chEneIIR_fx[0][band_idx] ), L_max( 1, hHeadTrackData->chEneIIR_fx[1][band_idx] ), &e_div ) ); - + e_div = add( e_div, sub( hHeadTrackData->q_chEneIIR[1][band_idx], hHeadTrackData->q_chEneIIR[0][band_idx] ) ); temp = BASOP_Util_Log2( temp_div ); // Q25 IF( e_div > 0 ) { @@ -2853,7 +2859,7 @@ static void adaptTransportSignalsHeadtracked_fx( temp = Mpy_32_32( temp, 646462464 ); // logx base 10 = 0.30103* logx base 2// ILD = L_abs( Mpy_32_16_1( temp, 20480 ) ); // Q21 } - IF( GT_32( hHeadTrackData->chEneIIR_fx[1][band_idx], hHeadTrackData->chEneIIR_fx[0][band_idx] ) ) + IF( BASOP_Util_Cmp_Mant32Exp( hHeadTrackData->chEneIIR_fx[1][band_idx], sub( 31, hHeadTrackData->q_chEneIIR[1][band_idx] ), hHeadTrackData->chEneIIR_fx[0][band_idx], sub( 31, hHeadTrackData->q_chEneIIR[0][band_idx] ) ) > 0 ) { louderCh = 1; } @@ -2886,8 +2892,9 @@ static void adaptTransportSignalsHeadtracked_fx( { IF( NE_16( ch, louderCh ) ) { - Word32 band_nrg = 0; - move32(); + Word32 band_nrg; + Word64 W_band_nrg = 0; + move64(); FOR( slot = 0; slot < nSlots; slot++ ) { @@ -2898,24 +2905,31 @@ static void adaptTransportSignalsHeadtracked_fx( inIm_fx[ch][slot][bin] = L_add( ( Mpy_32_32( mono_factor, L_add( inIm_fx[0][slot][bin], inIm_fx[1][slot][bin] ) ) ), ( Mpy_32_32( L_sub( ONE_IN_Q31, mono_factor ), inIm_fx[ch][slot][bin] ) ) ); move32(); move32(); - re = L_shl( inRe_fx[ch][slot][bin], shift ); // q_inp +shift - img = L_shl( inIm_fx[ch][slot][bin], shift ); // q_inp +shift - band_nrg = L_add( band_nrg, ( L_add( Mpy_32_32( re, re ), Mpy_32_32( img, img ) ) ) ); // 2(q_inp +shift) -31 + re = L_shl( inRe_fx[ch][slot][bin], shift ); // q_inp +shift + img = L_shl( inIm_fx[ch][slot][bin], shift ); // q_inp +shift + + W_band_nrg = W_add( W_band_nrg, ( W_add( W_mult0_32_32( re, re ), W_mult0_32_32( img, img ) ) ) ); // 2(q_inp + shift) } } - hHeadTrackData->procChEneIIR_fx[ch][band_idx] = Mpy_32_16_1( hHeadTrackData->procChEneIIR_fx[ch][band_idx], ADAPT_HTPROTO_IIR_FAC_FX ); // q_procChEneIIR + s = W_norm( W_band_nrg ); + band_nrg = W_extract_h( W_shl( W_band_nrg, s ) ); // Q: 2*(q_inp+shift) + s - 32 + q_band_nrg = sub( add( shl( add( q_inp, shift ), 1 ), s ), 32 ); + + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = Mpy_32_16_1( hHeadTrackData->procChEneIIR_fx[ch][band_idx], ADAPT_HTPROTO_IIR_FAC_FX ); // hHeadTrackData->q_procChEneIIR[ch][band_idx] move32(); - temp = Mpy_32_16_1( band_nrg, sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); - IF( LT_16( hHeadTrackData->q_procChEneIIR, q_temp ) ) + temp = Mpy_32_16_1( band_nrg, sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); // q_band_nrg + IF( LT_16( hHeadTrackData->q_procChEneIIR[ch][band_idx], q_band_nrg ) ) { - hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp, hHeadTrackData->q_procChEneIIR ) ), hHeadTrackData->procChEneIIR_fx[ch][band_idx] ); + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_band_nrg, hHeadTrackData->q_procChEneIIR[ch][band_idx] ) ), hHeadTrackData->procChEneIIR_fx[ch][band_idx] ); // hHeadTrackData->q_procChEneIIR[ch][band_idx] } ELSE { - hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->procChEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_procChEneIIR, q_temp ) ), temp ); + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->procChEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_procChEneIIR[ch][band_idx], q_band_nrg ) ), temp ); // q_band_nrg } move32(); + hHeadTrackData->q_procChEneIIR[ch][band_idx] = s_min( hHeadTrackData->q_procChEneIIR[ch][band_idx], q_band_nrg ); + move16(); } ELSE { @@ -2924,27 +2938,27 @@ static void adaptTransportSignalsHeadtracked_fx( move32(); temp = Mpy_32_16_1( ch_nrg[ch], sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); - IF( LT_16( hHeadTrackData->q_procChEneIIR, q_temp ) ) + IF( LT_16( hHeadTrackData->q_procChEneIIR[ch][band_idx], q_temp[ch] ) ) { - hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp, hHeadTrackData->q_procChEneIIR ) ), hHeadTrackData->procChEneIIR_fx[ch][band_idx] ); + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp[ch], hHeadTrackData->q_procChEneIIR[ch][band_idx] ) ), hHeadTrackData->procChEneIIR_fx[ch][band_idx] ); // hHeadTrackData->q_procChEneIIR[ch][band_idx] } ELSE { - hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->procChEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_procChEneIIR, q_temp ) ), temp ); + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->procChEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_procChEneIIR[ch][band_idx], q_temp[ch] ) ), temp ); // q_temp[ch] } move32(); + hHeadTrackData->q_procChEneIIR[ch][band_idx] = s_min( hHeadTrackData->q_procChEneIIR[ch][band_idx], q_temp[ch] ); + move16(); } } - q_procChEneIIR = s_min( hHeadTrackData->q_procChEneIIR, q_temp ); - /* Equalize */ - ene_target = L_add( hHeadTrackData->chEneIIR_fx[0][band_idx], hHeadTrackData->chEneIIR_fx[1][band_idx] ); // q_chEneIIR// + ene_target = BASOP_Util_Add_Mant32Exp( hHeadTrackData->chEneIIR_fx[0][band_idx], sub( 31, hHeadTrackData->q_chEneIIR[0][band_idx] ), hHeadTrackData->chEneIIR_fx[1][band_idx], sub( 31, hHeadTrackData->q_chEneIIR[1][band_idx] ), &ene_target_e ); - ene_proc = L_add( hHeadTrackData->procChEneIIR_fx[0][band_idx], hHeadTrackData->procChEneIIR_fx[1][band_idx] ); // q_procChEneIIR// + ene_proc = BASOP_Util_Add_Mant32Exp( hHeadTrackData->procChEneIIR_fx[0][band_idx], sub( 31, hHeadTrackData->q_procChEneIIR[0][band_idx] ), hHeadTrackData->procChEneIIR_fx[1][band_idx], sub( 31, hHeadTrackData->q_procChEneIIR[1][band_idx] ), &ene_proc_e ); temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( ene_target, L_max( 1, ene_proc ), &e_div ) ); - e_div = add( e_div, sub( q_procChEneIIR, q_chEneIIR ) ); + e_div = add( e_div, sub( ene_target_e, ene_proc_e ) ); eqVal = Sqrt32( temp_div, &e_div ); @@ -2994,16 +3008,8 @@ static void adaptTransportSignalsHeadtracked_fx( } IF( is_zero ) { - hHeadTrackData->q_chEneIIR = 31; - move16(); - } - ELSE - { - tmp = sub( s_min( getScaleFactor32( hHeadTrackData->chEneIIR_fx[0], MASA_FREQUENCY_BANDS ), getScaleFactor32( hHeadTrackData->chEneIIR_fx[1], MASA_FREQUENCY_BANDS ) ), 1 ); - scale_sig32( hHeadTrackData->chEneIIR_fx[0], MASA_FREQUENCY_BANDS, tmp ); - scale_sig32( hHeadTrackData->chEneIIR_fx[1], MASA_FREQUENCY_BANDS, tmp ); - hHeadTrackData->q_chEneIIR = add( q_chEneIIR, tmp ); - move16(); + set16_fx( hHeadTrackData->q_chEneIIR[0], 31, MASA_FREQUENCY_BANDS ); + set16_fx( hHeadTrackData->q_chEneIIR[1], 31, MASA_FREQUENCY_BANDS ); } is_zero = 1; @@ -3020,17 +3026,10 @@ static void adaptTransportSignalsHeadtracked_fx( } IF( is_zero ) { - hHeadTrackData->q_procChEneIIR = 31; - move16(); - } - ELSE - { - tmp = sub( s_min( getScaleFactor32( hHeadTrackData->procChEneIIR_fx[0], MASA_FREQUENCY_BANDS ), getScaleFactor32( hHeadTrackData->procChEneIIR_fx[1], MASA_FREQUENCY_BANDS ) ), 1 ); - scale_sig32( hHeadTrackData->procChEneIIR_fx[0], MASA_FREQUENCY_BANDS, tmp ); - scale_sig32( hHeadTrackData->procChEneIIR_fx[1], MASA_FREQUENCY_BANDS, tmp ); - hHeadTrackData->q_procChEneIIR = add( q_procChEneIIR, tmp ); - move16(); + set16_fx( hHeadTrackData->q_procChEneIIR[0], 31, MASA_FREQUENCY_BANDS ); + set16_fx( hHeadTrackData->q_procChEneIIR[1], 31, MASA_FREQUENCY_BANDS ); } + return; } diff --git a/lib_rend/ivas_rotation_fx.c b/lib_rend/ivas_rotation_fx.c index 1633f42d0..b9403e7da 100644 --- a/lib_rend/ivas_rotation_fx.c +++ b/lib_rend/ivas_rotation_fx.c @@ -1439,10 +1439,11 @@ ivas_error ivas_combined_orientation_open( set_zero_fx( ( *hCombinedOrientationData )->chEneIIR_fx[1], MASA_FREQUENCY_BANDS ); set_zero_fx( ( *hCombinedOrientationData )->procChEneIIR_fx[0], MASA_FREQUENCY_BANDS ); set_zero_fx( ( *hCombinedOrientationData )->procChEneIIR_fx[1], MASA_FREQUENCY_BANDS ); - ( *hCombinedOrientationData )->q_chEneIIR = Q31; - move16(); - ( *hCombinedOrientationData )->q_procChEneIIR = Q31; - move16(); + set16_fx( ( *hCombinedOrientationData )->q_chEneIIR[0], Q31, MASA_FREQUENCY_BANDS ); + set16_fx( ( *hCombinedOrientationData )->q_chEneIIR[1], Q31, MASA_FREQUENCY_BANDS ); + set16_fx( ( *hCombinedOrientationData )->q_procChEneIIR[0], Q31, MASA_FREQUENCY_BANDS ); + set16_fx( ( *hCombinedOrientationData )->q_procChEneIIR[1], Q31, MASA_FREQUENCY_BANDS ); + ( *hCombinedOrientationData )->isExtOrientationFrozen = 0; move16(); ( *hCombinedOrientationData )->isHeadRotationFrozen = 0; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 2654e5a53..ddf2b5942 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -837,9 +837,9 @@ typedef struct ivas_combined_orientation_struct Word32 Rmat_fx[MAX_PARAM_SPATIAL_SUBFRAMES][3][3]; /* Q30 */ Word32 Rmat_prev_fx[3][3]; /* Q30 */ Word32 chEneIIR_fx[2][MASA_FREQUENCY_BANDS]; /* independent of the format. MASA bands are suitable for the task and readily available in ROM. */ /* Q(q_chEneIIR) */ - Word16 q_chEneIIR; + Word16 q_chEneIIR[2][MASA_FREQUENCY_BANDS]; Word32 procChEneIIR_fx[2][MASA_FREQUENCY_BANDS]; /* Q(q_procChEneIIR) */ - Word16 q_procChEneIIR; + Word16 q_procChEneIIR[2][MASA_FREQUENCY_BANDS]; Word16 shd_rot_max_order; IVAS_VECTOR3 listenerPos[MAX_PARAM_SPATIAL_SUBFRAMES]; IVAS_QUATERNION Quaternion_frozen_ext; -- GitLab From a7617c8fada6aec8684857bb577d9895033db409 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 10 Jun 2025 09:55:16 +0530 Subject: [PATCH 36/54] Disable WMOPS macro in options.h - Fix for MR 1572 --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 940cd1fe7..cd57657b0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -54,7 +54,7 @@ #define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ -#define WMOPS /* Activate complexity and memory counters */ +/*#define WMOPS*/ /* Activate complexity and memory counters */ #ifdef WMOPS #define WMOPS_PER_FRAME /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ #define WMOPS_DETAIL /* Output detailed complexity printout for every function. Increases runtime overhead */ -- GitLab From 9230c2956c4af8efefae97b3780b37203b808811 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 9 Jun 2025 19:33:07 +0530 Subject: [PATCH 37/54] Fix for 3GPP issue 1732: Accuracy of spatial metadata in ivas_omasa_enc_fx compared to the floating point equivalent Link #1732 --- lib_com/ivas_dirac_com_fx.c | 33 ++++++++---- lib_enc/ivas_omasa_enc_fx.c | 101 ++++++++++++++++++++++++++---------- 2 files changed, 96 insertions(+), 38 deletions(-) diff --git a/lib_com/ivas_dirac_com_fx.c b/lib_com/ivas_dirac_com_fx.c index 2be3f8ace..0922e0289 100644 --- a/lib_com/ivas_dirac_com_fx.c +++ b/lib_com/ivas_dirac_com_fx.c @@ -796,19 +796,23 @@ void computeDiffuseness_fixed( { Word32 intensity_slow[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX]; Word32 intensity_slow_abs[CLDFB_NO_CHANNELS_MAX]; + Word64 tmp_intensity_slow_abs[CLDFB_NO_CHANNELS_MAX]; + Word16 intensity_slow_abs_exp[CLDFB_NO_CHANNELS_MAX]; Word32 energy_slow[CLDFB_NO_CHANNELS_MAX]; - Word16 i, j, k; + Word16 i, j, k, tmp16; Word32 tmp = 0; move32(); Word32 *p_tmp; const Word32 *p_tmp_c; Word16 min_q_shift1, min_q_shift2, exp1, exp2, q_tmp; - Word16 q_ene, q_intensity, q_intensity_slow; + Word16 q_ene, q_intensity; /* Compute Intensity slow and energy slow buffer_intensity and buffer_energy */ - set_zero_fx( intensity_slow, i_mult( DIRAC_NUM_DIMS, CLDFB_NO_CHANNELS_MAX ) ); + set_zero_fx( intensity_slow, DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX ); set_zero_fx( intensity_slow_abs, CLDFB_NO_CHANNELS_MAX ); + set16_fx( intensity_slow_abs_exp, 0, CLDFB_NO_CHANNELS_MAX ); + set64_fx( tmp_intensity_slow_abs, 0, CLDFB_NO_CHANNELS_MAX ); set_zero_fx( energy_slow, CLDFB_NO_CHANNELS_MAX ); /* Calculate max possible shift for the buffer buffer_energy and buffer_intensity */ @@ -892,10 +896,8 @@ void computeDiffuseness_fixed( q_intensity = s_min( q_intensity, q_tmp ); } - min_q_shift1 = getScaleFactor32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ) ); - min_q_shift1 = sub( min_q_shift1, idiv1616( add( find_guarded_bits_fx( DIRAC_NUM_DIMS ), 1 ), 2 ) ); - scale_sig32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ), min_q_shift1 ); - q_intensity = add( q_intensity, min_q_shift1 ); + scale_sig32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ), -2 ); + q_intensity = sub( q_intensity, 2 ); /* intensity_slow.^2 + intensity_slow_abs*/ FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) @@ -904,11 +906,19 @@ void computeDiffuseness_fixed( FOR( k = 0; k < num_freq_bands; k++ ) { - intensity_slow_abs[k] = Madd_32_32( intensity_slow_abs[k], p_tmp[k], p_tmp[k] ); - move32(); + tmp_intensity_slow_abs[k] = W_mac_32_32( tmp_intensity_slow_abs[k], p_tmp[k], p_tmp[k] ); + move64(); } } - q_intensity_slow = sub( add( q_intensity, q_intensity ), 31 ); + + FOR( k = 0; k < num_freq_bands; k++ ) + { + tmp16 = W_norm( tmp_intensity_slow_abs[k] ); + intensity_slow_abs[k] = W_extract_h( W_shl( tmp_intensity_slow_abs[k], tmp16 ) ); + move32(); + intensity_slow_abs_exp[k] = sub( 31, sub( add( add( shl( q_intensity, 1 ), 1 ), tmp16 ), 32 ) ); + move16(); + } /* Compute Diffuseness */ p_tmp = intensity_slow_abs; @@ -916,7 +926,8 @@ void computeDiffuseness_fixed( move16(); FOR( i = 0; i < num_freq_bands; ++i ) { - exp1 = sub( 31, q_intensity_slow ); + exp1 = intensity_slow_abs_exp[i]; + move16(); tmp = Sqrt32( p_tmp[i], &exp1 ); tmp = BASOP_Util_Divide3232_Scale_newton( tmp, L_add( energy_slow[i], EPSILLON_FX ), &exp2 ); diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index b88bb69a1..58ba680d6 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -82,13 +82,14 @@ static void ivas_omasa_dmx_fx( Word16 prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], /*o:q15*/ const Word16 interpolator[L_FRAME48k] /*i:q15*/ ); -static void computeIntensityVector_enc_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], /* o : Intensity vector */ - Word16 guard_bits ); +void computeIntensityVector_enc_fx( + const Word16 *band_grouping, + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /*inp_q*/ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /*inp_q*/ + const Word16 num_frequency_bands, + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], /*exp: exp_intensity_real*/ + Word16 *exp_intensity_real, + Word16 inp_q ); static void computeReferencePower_omasa_ivas_fx( const Word16 *band_grouping, Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], Word32 *reference_power, const Word16 enc_param_start_band, const Word16 num_freq_bands, Word16 q_Cldfb, Word16 *ref_exp ); /*--------------------------------------------------------------------------* * ivas_omasa_enc_open() @@ -1191,8 +1192,13 @@ static void ivas_omasa_param_est_enc_fx( norm_buff = s_min( norm_buff, L_norm_arr( &Foa_ImagBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX ) ); guard_bits = find_guarded_bits_fx( max_band_grouping_diff ); guard_bits = add( guard_bits, sub( 1, norm_buff ) ); - computeIntensityVector_enc_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx, guard_bits ); - intensity_real_e = sub( add( 62, guard_bits ), shl( q, 1 ) ); + + scale_sig32( &Foa_RealBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX, negate( guard_bits ) ); + scale_sig32( &Foa_ImagBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX, negate( guard_bits ) ); + + q = sub( q, guard_bits ); + + computeIntensityVector_enc_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx, &intensity_real_e, q ); computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], intensity_real_e, NULL ); @@ -1478,20 +1484,27 @@ static void ivas_omasa_dmx_fx( } void computeIntensityVector_enc_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], /* o : Intensity vector */ - Word16 guard_bits ) + const Word16 *band_grouping, + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /*inp_q*/ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /*inp_q*/ + const Word16 num_frequency_bands, + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], /*exp: exp_intensity_real*/ + Word16 *exp_intensity_real, + Word16 inp_q ) { - /* Reminder - * X = a + ib; Y = c + id - * X*Y = ac - bd + i(ad +bc) - */ Word16 i, j; Word32 real, img; - Word16 brange[2]; + Word16 brange[2], shift = 63; + move16(); + Flag is_zero = 0; + move16(); + + Word64 intensity_real64[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + set64_fx( intensity_real64[i], 0, MASA_FREQUENCY_BANDS ); + } FOR( i = 0; i < num_frequency_bands; i++ ) { @@ -1510,21 +1523,55 @@ void computeIntensityVector_enc_fx( FOR( j = brange[0]; j < brange[1]; j++ ) { real = Cldfb_RealBuffer[0][j]; - img = Cldfb_ImagBuffer[0][j]; - /* Intensity is XYZ order, audio is WYZX order. */ - intensity_real[0][i] = L_add( intensity_real[0][i], L_add( L_shr( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), guard_bits ), L_shr( Mpy_32_32( Cldfb_ImagBuffer[3][j], img ), guard_bits ) ) ); // output Q= 2* input_q -31-guard_bits - move32(); - intensity_real[1][i] = L_add( intensity_real[1][i], L_add( L_shr( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), guard_bits ), L_shr( Mpy_32_32( Cldfb_ImagBuffer[1][j], img ), guard_bits ) ) ); // output Q= 2* input_q -31-guard_bits move32(); - intensity_real[2][i] = L_add( intensity_real[2][i], L_add( L_shr( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), guard_bits ), L_shr( Mpy_32_32( Cldfb_ImagBuffer[2][j], img ), guard_bits ) ) ); // output Q= 2* input_q -31-guard_bits + img = Cldfb_ImagBuffer[0][j]; move32(); + /* Intensity is XYZ order, audio is WYZX order. */ + intensity_real64[0][i] = W_add( intensity_real64[0][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[3][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q= 2* input_q + move64(); + intensity_real64[1][i] = W_add( intensity_real64[1][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[1][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q= 2* input_q + move64(); + intensity_real64[2][i] = W_add( intensity_real64[2][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[2][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q= 2* input_q + move64(); + } + } + + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + is_zero = is_zero_arr64( intensity_real64[i], MASA_FREQUENCY_BANDS ); + IF( is_zero == 0 ) + { + BREAK; } } + IF( is_zero == 0 ) + { + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + shift = s_min( shift, W_norm_arr( intensity_real64[i], MASA_FREQUENCY_BANDS ) ); + } + + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + intensity_real[i][j] = W_extract_h( W_shl( intensity_real64[i][j], shift ) ); + move32(); + } + } + + *exp_intensity_real = sub( 31, sub( add( shift, shl( inp_q, 1 ) ), 32 ) ); + move16(); + } + ELSE + { + *exp_intensity_real = 0; + move16(); + } return; } - static void computeReferencePower_omasa_ivas_fx( const Word16 *band_grouping, /* i : Band grouping for estimation */ Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Q6*/ -- GitLab From 42eb3f1e3ebd08e695c9c2be9ee1944d7f5fd785 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 10 Jun 2025 11:08:09 +0200 Subject: [PATCH 38/54] Fix for fx-fx job --- .gitlab-ci.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d10993ad6..df6069de2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,10 +37,10 @@ workflow: IVAS_PIPELINE_NAME: 'Run encoder dmx comparison against float ref: $CI_COMMIT_BRANCH' - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-long' variables: - IVAS_PIPELINE_NAME: 'Run comparison tools against float ref FX-FX (long test vectors): $CI_COMMIT_BRANCH' + IVAS_PIPELINE_NAME: 'Run comparison tools against float ref (long test vectors): $CI_COMMIT_BRANCH' - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-long-fx-fx' variables: - IVAS_PIPELINE_NAME: 'Run comparison tools against float ref (long test vectors): $CI_COMMIT_BRANCH' + IVAS_PIPELINE_NAME: 'Run comparison tools against float ref FX-FX (long test vectors): $CI_COMMIT_BRANCH' - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-to-input' variables: IVAS_PIPELINE_NAME: 'Run comparison tools against input (pass-through only): $CI_COMMIT_BRANCH' @@ -196,7 +196,7 @@ workflow: .ivas-pytest-anchor: &ivas-pytest-anchor stage: test needs: ["build-codec-linux-make"] - timeout: "360 minutes" + timeout: "15 hours" variables: # keep "mld" in artifact name for backwards compatibility reasons CSV_ARTIFACT_NAME: "mld--$CI_JOB_NAME-$CI_JOB_ID--sha-$CI_COMMIT_SHORT_SHA.csv" @@ -1352,6 +1352,8 @@ ivas-pytest-compare_ref-long-fx-fx: extends: - .rules-pytest-long-fx-fx - .test-job-linux + tags: + - ivas-linux before_script: - USE_LTV=1 - REF_ENCODER_PATH=./$DUT_ENCODER_PATH @@ -1364,6 +1366,8 @@ ivas-pytest-compare_ref-long-fx-fx-lev-10: extends: - .rules-pytest-long-fx-fx - .test-job-linux + tags: + - ivas-linux before_script: - USE_LTV=1 - REF_ENCODER_PATH=./$DUT_ENCODER_PATH @@ -1376,6 +1380,8 @@ ivas-pytest-compare_ref-long-fx-fx-lev+10: extends: - .rules-pytest-long-fx-fx - .test-job-linux + tags: + - ivas-linux before_script: - USE_LTV=1 - REF_ENCODER_PATH=./$DUT_ENCODER_PATH -- GitLab From 211901e3cdd524c03c565c7f92662e695629732a Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 10 Jun 2025 13:09:47 +0200 Subject: [PATCH 39/54] add missing pop_wmops() --- lib_com/options.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index cd57657b0..0da972932 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -101,12 +101,10 @@ #define VEC_ARITH_OPT_v1 #define FIX_1486_IND_SHB_RES /* VA: Fix for issue 1486: align the usage of IND_SHB_RES_GS indices with float code */ #define FIX_1511_POC_RENORM /* NTT: Fix for issue 1511: Renorm for POC. */ - #define TEST_HR #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ - #define FIX_1713_EXP /* VA: proposed correction to exp in ic-BWE*/ - #define FIX_1733_CLDFB_BUG +#define FIX_1740_MISING_POP_WMOPS /* VA: fix issue 1740: missing pop_wmops() */ #endif -- GitLab From 24afafdf5f31ec85672e066716e95693accd65b8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 10 Jun 2025 18:35:20 +0530 Subject: [PATCH 40/54] Fix for 3GPP issue 1724: Renderer MASA output metadata difference Link #1724 --- lib_com/ivas_dirac_com_fx.c | 39 +++++++++++++++++------------------ lib_rend/ivas_dirac_ana_fx.c | 17 +++++++++++++-- lib_rend/ivas_mcmasa_ana_fx.c | 2 +- lib_rend/ivas_omasa_ana_fx.c | 22 ++++++++++++-------- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/lib_com/ivas_dirac_com_fx.c b/lib_com/ivas_dirac_com_fx.c index 0922e0289..feea9c5af 100644 --- a/lib_com/ivas_dirac_com_fx.c +++ b/lib_com/ivas_dirac_com_fx.c @@ -783,7 +783,6 @@ void computeDirectionVectors_fx( * * *------------------------------------------------------------------------*/ - void computeDiffuseness_fixed( Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], // i: Q(q_factor_intensity) const Word32 *buffer_energy, // i: Q(q_factor_energy) @@ -796,10 +795,10 @@ void computeDiffuseness_fixed( { Word32 intensity_slow[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX]; Word32 intensity_slow_abs[CLDFB_NO_CHANNELS_MAX]; - Word64 tmp_intensity_slow_abs[CLDFB_NO_CHANNELS_MAX]; - Word16 intensity_slow_abs_exp[CLDFB_NO_CHANNELS_MAX]; + Word64 intensity_slow_abs_64[CLDFB_NO_CHANNELS_MAX]; + Word16 intensity_slow_abs_q[CLDFB_NO_CHANNELS_MAX]; Word32 energy_slow[CLDFB_NO_CHANNELS_MAX]; - Word16 i, j, k, tmp16; + Word16 i, j, k; Word32 tmp = 0; move32(); Word32 *p_tmp; @@ -809,10 +808,8 @@ void computeDiffuseness_fixed( /* Compute Intensity slow and energy slow buffer_intensity and buffer_energy */ - set_zero_fx( intensity_slow, DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( intensity_slow, i_mult( DIRAC_NUM_DIMS, CLDFB_NO_CHANNELS_MAX ) ); set_zero_fx( intensity_slow_abs, CLDFB_NO_CHANNELS_MAX ); - set16_fx( intensity_slow_abs_exp, 0, CLDFB_NO_CHANNELS_MAX ); - set64_fx( tmp_intensity_slow_abs, 0, CLDFB_NO_CHANNELS_MAX ); set_zero_fx( energy_slow, CLDFB_NO_CHANNELS_MAX ); /* Calculate max possible shift for the buffer buffer_energy and buffer_intensity */ @@ -896,27 +893,31 @@ void computeDiffuseness_fixed( q_intensity = s_min( q_intensity, q_tmp ); } - scale_sig32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ), -2 ); - q_intensity = sub( q_intensity, 2 ); - + min_q_shift1 = getScaleFactor32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ) ); + min_q_shift1 = sub( min_q_shift1, idiv1616( add( find_guarded_bits_fx( DIRAC_NUM_DIMS ), 1 ), 2 ) ); + scale_sig32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ), min_q_shift1 ); + q_intensity = add( q_intensity, min_q_shift1 ); + FOR( k = 0; k < num_freq_bands; k++ ) + { + intensity_slow_abs_64[k] = 0; + move64(); + } + /* intensity_slow.^2 + intensity_slow_abs*/ FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { p_tmp = intensity_slow + j * num_freq_bands; - FOR( k = 0; k < num_freq_bands; k++ ) { - tmp_intensity_slow_abs[k] = W_mac_32_32( tmp_intensity_slow_abs[k], p_tmp[k], p_tmp[k] ); - move64(); + intensity_slow_abs_64[k] = W_add( intensity_slow_abs_64[k], W_mult_32_32( p_tmp[k], p_tmp[k] ) ); // 2*q_intensity+1 } } - FOR( k = 0; k < num_freq_bands; k++ ) { - tmp16 = W_norm( tmp_intensity_slow_abs[k] ); - intensity_slow_abs[k] = W_extract_h( W_shl( tmp_intensity_slow_abs[k], tmp16 ) ); + Word16 shift = W_norm( intensity_slow_abs_64[k] ); + intensity_slow_abs[k] = W_extract_h( W_shl( intensity_slow_abs_64[k], shift ) ); move32(); - intensity_slow_abs_exp[k] = sub( 31, sub( add( add( shl( q_intensity, 1 ), 1 ), tmp16 ), 32 ) ); + intensity_slow_abs_q[k] = sub( add( add( q_intensity, q_intensity ), shift ), 31 ); move16(); } @@ -926,8 +927,7 @@ void computeDiffuseness_fixed( move16(); FOR( i = 0; i < num_freq_bands; ++i ) { - exp1 = intensity_slow_abs_exp[i]; - move16(); + exp1 = sub( 31, intensity_slow_abs_q[i] ); tmp = Sqrt32( p_tmp[i], &exp1 ); tmp = BASOP_Util_Divide3232_Scale_newton( tmp, L_add( energy_slow[i], EPSILLON_FX ), &exp2 ); @@ -966,7 +966,6 @@ void computeDiffuseness_fixed( return; } - Word32 deindex_azimuth_fx( /* o : output Q22 */ Word16 id_phi, /* i : index */ const Word16 no_bits, /* i : number of bits for the spherical grid */ diff --git a/lib_rend/ivas_dirac_ana_fx.c b/lib_rend/ivas_dirac_ana_fx.c index f282e8390..df75d6d0a 100644 --- a/lib_rend/ivas_dirac_ana_fx.c +++ b/lib_rend/ivas_dirac_ana_fx.c @@ -138,6 +138,7 @@ ivas_error ivas_dirac_ana_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); } + set16_fx( hDirAC->direction_vector_e[i][j], 31, MASA_FREQUENCY_BANDS ); } } @@ -257,6 +258,7 @@ void ivas_dirac_ana_fx( /* Estimate MASA parameters from the SBA signals */ ivas_dirac_param_est_ana_fx( hDirAC, data_fx, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame ); /* Create MASA metadata buffer from the estimated values */ + ivas_create_masa_out_meta_fx( hDirAC->hMasaOut, hDirAC->sph_grid16, nchan_transport, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, Q31, Q31, Q31 ); /* Downmix */ @@ -334,13 +336,22 @@ static void ivas_dirac_param_est_ana_fx( move32(); hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; move32(); + + hDirAC->direction_vector_e[0][block_m_idx][band_m_idx] = 0; + move16(); + hDirAC->direction_vector_e[1][block_m_idx][band_m_idx] = 0; + move16(); + hDirAC->direction_vector_e[2][block_m_idx][band_m_idx] = 0; + move16(); } /* Need to initialize renormalization_factors, and variables to be normalized */ set32_fx( renormalization_factor_diff_fx, 0, hDirAC->nbands ); + set16_fx( renormalization_factor_diff_e, 31, hDirAC->nbands ); set32_fx( diffuseness_m_fx, 0, hDirAC->nbands ); + set16_fx( diffuseness_e, 0, hDirAC->nbands ); set32_fx( hDirAC->energy_fx[block_m_idx], 0, MASA_FREQUENCY_BANDS ); - set32_fx( hDirAC->energy_fx[block_m_idx], 0, MASA_FREQUENCY_BANDS ); + set16_fx( hDirAC->energy_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { @@ -351,7 +362,9 @@ static void ivas_dirac_param_est_ana_fx( move16(); FOR( i = 0; i < numAnalysisChannels; i++ ) { - cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][( l_ts * ts )] ), Foa_RealBuffer_fx[i], Foa_ImagBuffer_fx[i], l_ts, hDirAC->cldfbAnaEnc[i], &inp_q ); + inp_q = Q7; + move16(); + cldfbAnalysis_ts_fx_var_q( &( data_fx[i][l_ts * ts] ), Foa_RealBuffer_fx[i], Foa_ImagBuffer_fx[i], l_ts, hDirAC->cldfbAnaEnc[i], &inp_q ); cr_q = s_min( cr_q, getScaleFactor32( Foa_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); ci_q = s_min( ci_q, getScaleFactor32( Foa_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); } diff --git a/lib_rend/ivas_mcmasa_ana_fx.c b/lib_rend/ivas_mcmasa_ana_fx.c index cfdd43116..bce7a4a5a 100644 --- a/lib_rend/ivas_mcmasa_ana_fx.c +++ b/lib_rend/ivas_mcmasa_ana_fx.c @@ -634,7 +634,7 @@ void ivas_mcmasa_param_est_ana_fx( { inp_q = q_data; move16(); - cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hMcMasa->cldfbAnaEnc[i], &inp_q ); + cldfbAnalysis_ts_fx_var_q( &( data_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hMcMasa->cldfbAnaEnc[i], &inp_q ); cr_q = s_min( cr_q, getScaleFactor32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); ci_q = s_min( ci_q, getScaleFactor32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); } diff --git a/lib_rend/ivas_omasa_ana_fx.c b/lib_rend/ivas_omasa_ana_fx.c index bce8870c8..d82346d34 100644 --- a/lib_rend/ivas_omasa_ana_fx.c +++ b/lib_rend/ivas_omasa_ana_fx.c @@ -41,7 +41,6 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" - /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ @@ -170,6 +169,7 @@ ivas_error ivas_omasa_ana_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); } + set16_fx( hOMasa->direction_vector_e[i][j], 0, MASA_FREQUENCY_BANDS ); } } @@ -319,11 +319,11 @@ void ivas_omasa_ana_fx( ivas_omasa_param_est_ana_fx( hOMasa, data_in_f_fx, *data_in_q, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, &energyRatio_q, spreadCoherence_fx, &spreadCoherence_q, surroundingCoherence_fx, &sorroundingCoherence_q, input_frame, nchan_ism ); /* Create MASA metadata buffer from the estimated values */ - ivas_create_masa_out_meta_fx( hOMasa->hMasaOut, hOMasa->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); /* Downmix */ ivas_omasa_dmx_fx( data_in_f_fx, data_in_q, input_frame, nchan_transport, nchan_ism, hOMasa->ism_azimuth_fx, hOMasa->ism_elevation_fx, hOMasa->prev_object_dm_gains_fx, hOMasa->interpolator_fx ); + return; } @@ -372,7 +372,6 @@ static void ivas_omasa_param_est_ana_fx( Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; Word16 renormalization_factor_diff_e[MASA_FREQUENCY_BANDS]; Word32 norm_tmp_fx; - Word16 tmp_ener_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 dir_v_fx[DIRAC_NUM_DIMS] /*, L_tmp1, L_tmp2*/; Word16 dir_v_q /*, norm_tmp_q*/; @@ -422,15 +421,23 @@ static void ivas_omasa_param_est_ana_fx( move32(); hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; move32(); + + hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] = 0; + move16(); + hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] = 0; + move16(); + hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] = 0; + move16(); } /* Need to initialize renormalization_factors, and variables to be normalized */ set_zero_fx( renormalization_factor_diff_fx, hOMasa->nbands ); + set16_fx( renormalization_factor_diff_e, 0, hOMasa->nbands ); set_zero_fx( diffuseness_m_fx, hOMasa->nbands ); + set16_fx( diffuseness_e, 0, hOMasa->nbands ); set_zero_fx( hOMasa->energy_fx[block_m_idx], MASA_FREQUENCY_BANDS ); - - set16_fx( tmp_ener_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); + set16_fx( hOMasa->energy_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { @@ -441,10 +448,8 @@ static void ivas_omasa_param_est_ana_fx( move16(); FOR( i = 0; i < nchan_ism; i++ ) { - inp_q = data_f_q; - move16(); - cldfbAnalysis_ts_fx_fixed_q( &( data_f_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &inp_q ); + cldfbAnalysis_ts_fx_var_q( &( data_f_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &inp_q ); cr_q = s_min( cr_q, getScaleFactor32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); ci_q = s_min( ci_q, getScaleFactor32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); @@ -554,7 +559,6 @@ static void ivas_omasa_param_est_ana_fx( FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { norm_tmp_fx = L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ), 1 ); /*2*inp_q-30*/ - hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], hOMasa->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), shl( c_e, 1 ), &hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ); move32(); hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], hOMasa->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), shl( c_e, 1 ), &hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ); -- GitLab From 9c90a8621750ca145a5ce48112830f527c00f2b7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 10 Jun 2025 18:39:50 +0530 Subject: [PATCH 41/54] Clang formatting --- lib_com/ivas_dirac_com_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/ivas_dirac_com_fx.c b/lib_com/ivas_dirac_com_fx.c index feea9c5af..c08dade43 100644 --- a/lib_com/ivas_dirac_com_fx.c +++ b/lib_com/ivas_dirac_com_fx.c @@ -902,7 +902,7 @@ void computeDiffuseness_fixed( intensity_slow_abs_64[k] = 0; move64(); } - + /* intensity_slow.^2 + intensity_slow_abs*/ FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { -- GitLab From 7de08c8f10180f2ff578fbadb88769b437a478f8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 11 Jun 2025 10:22:48 +0530 Subject: [PATCH 42/54] Precision improvements for processIGF, in McMASA and OMASA paths --- lib_com/ivas_dirac_com_fx.c | 3 +- lib_com/ivas_prot_fx.h | 6 +- lib_com/prot_fx.h | 4 +- lib_com/rom_com.c | 24 +-- lib_com/stat_com.h | 1 + lib_enc/cod_tcx_fx.c | 8 +- lib_enc/igf_enc.c | 194 +++++++++---------------- lib_enc/igf_enc_fx.c | 85 ++++++++++- lib_enc/ivas_dirac_enc_fx.c | 42 +++--- lib_enc/ivas_mcmasa_enc_fx.c | 136 ++++++++++------- lib_enc/ivas_mct_enc_mct_fx.c | 18 ++- lib_enc/ivas_omasa_enc_fx.c | 142 +++++++++--------- lib_enc/ivas_stereo_mdct_core_enc_fx.c | 23 ++- lib_enc/prot_fx_enc.h | 7 + lib_enc/tcx_utils_enc_fx.c | 2 +- 15 files changed, 377 insertions(+), 318 deletions(-) diff --git a/lib_com/ivas_dirac_com_fx.c b/lib_com/ivas_dirac_com_fx.c index 0922e0289..21f5d4995 100644 --- a/lib_com/ivas_dirac_com_fx.c +++ b/lib_com/ivas_dirac_com_fx.c @@ -608,8 +608,7 @@ void computeDirectionVectors_fixed( Word32 *direction_vector_x, /* o: Q30*/ Word32 *direction_vector_y, /* o: Q30*/ Word32 *direction_vector_z, /* o: Q30*/ - Word16 i_e /*Exponent of all the intensity buffers*/ - , + Word16 i_e, /*Exponent of all the intensity buffers*/ Word16 *i_e_band ) { Word16 i; diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 00f0ba43b..74e682a4b 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3230,8 +3230,7 @@ void computeDirectionVectors_fixed( Word32 *direction_vector_x, /*Q30*/ Word32 *direction_vector_y, /*Q30*/ Word32 *direction_vector_z, /*Q30*/ - Word16 i_e /*Exponent of all the intensity buffers*/ - , + Word16 i_e, /*Exponent of all the intensity buffers*/ Word16 *i_e_band ); @@ -3293,8 +3292,7 @@ void computeReferencePower_enc_fx( Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ const Word16 nchan_ana, /* i : number of analysis channels */ Word16 inp_q, /* i : q of cld buffers */ - Word16 *ref_q /* i : output q */ -); + Word16 q_reference_power[DIRAC_NO_FB_BANDS_MAX] ); void computeReferencePower_enc_fx_dirac( const Word16 *band_grouping, /* i : Band grouping for estimation */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 0a11364dc..38a6077e8 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10502,7 +10502,7 @@ void ProcessStereoIGF_fx( Word16 q_pITFMDCTSpectrum_1, Word16 q_pITFMDCTSpectrum_2, Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ @@ -10519,7 +10519,7 @@ void IGFEncApplyStereo_fx( const Word16 igfGridIdx, /* i : IGF grid index */ Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index a5c8a3b7c..9eaf690f1 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -20441,42 +20441,42 @@ const Word16 qGains[2][1 << kTcxHmNumGainBits] = const struct TnsParameters tnsParametersIGF32kHz_LowBR[1] = { - { 600, 3, /*1.85f, 0.075f, 4.4f,*/ 237/*1.85f Q7*/, 2458/*0.075f Q15*/,563 /*4.4f Q7*/ } + { 600, 3, /*1.85f, 0.075f, 4.4f,*/ 237/*1.85f Q7*/, 15518925/*1.85f Q23*/, 2458/*0.075f Q15*/,563 /*4.4f Q7*/ } }; const struct TnsParameters tnsParameters32kHz[2] = { - { 4500, 3, /*1.35f, 0.0300f, 1.0f ,*/ 173/*1.35f Q7*/, 983/*0.0300f Q15*/, 128/*1.0f Q7*/}, - { 600, 1, /*1.75f, 0.0625f, 4.4f ,*/ 224/*1.75f Q7*/, 2048/*0.0625f Q15*/, 563 /*4.4f Q7*/ } + { 4500, 3, /*1.35f, 0.0300f, 1.0f ,*/ 173/*1.35f Q7*/,11324621/*1.35f Q23*/, 983/*0.0300f Q15*/, 128/*1.0f Q7*/}, + { 600, 1, /*1.75f, 0.0625f, 4.4f ,*/ 224/*1.75f Q7*/,14680064/*1.75f Q23*/, 2048/*0.0625f Q15*/, 563 /*4.4f Q7*/ } }; const struct TnsParameters tnsParameters32kHz_grouped[2] = { - { 8400, 3, /*1.375f, 0.03125f, 1.0f ,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ }, - { 800, 3, /*1.375f, 0.03125f, 1.0f ,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/} + { 8400, 3, /*1.375f, 0.03125f, 1.0f ,*/ 176/*1.375f Q7*/,11534336/*1.375f Q23*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ }, + { 800, 3, /*1.375f, 0.03125f, 1.0f ,*/ 176/*1.375f Q7*/,11534336/*1.375f Q23*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/} }; const struct TnsParameters tnsParameters16kHz[1] = { - { 600, 3, /*1.5f, 0.05f, 4.4f,*/ 192/*1.5f Q7*/, 1638/*0.05f Q15*/ ,563 /*4.4f Q7*/ } + { 600, 3, /*1.5f, 0.05f, 4.4f,*/ 192/*1.5f Q7*/, 12582912/*1.5f Q23*/, 1638/*0.05f Q15*/ ,563 /*4.4f Q7*/ } }; const struct TnsParameters tnsParameters16kHz_grouped[2] = { - { 4400, 3, /*1.5f, 0.05f, 1.0f,*/ 192/*1.5f Q7*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/}, - { 800, 3, /*1.5f, 0.05f, 1.0f,*/ 192/*1.5f Q7*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/} + { 4400, 3, /*1.5f, 0.05f, 1.0f,*/ 192/*1.5f Q7*/, 12582912/*1.5f Q23*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/}, + { 800, 3, /*1.5f, 0.05f, 1.0f,*/ 192/*1.5f Q7*/, 12582912/*1.5f Q23*/, 1638/*0.05f Q15*/ , 128/*1.0f Q7*/} }; const struct TnsParameters tnsParameters48kHz_grouped[2] = { - { 10400, 3, /*1.375f, 0.03125f, 1.0f,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/}, - { 800, 3, /*1.375f, 0.03125f, 1.0f,*/ 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ } + { 10400, 3, /*1.375f, 0.03125f, 1.0f,*/ 176/*1.375f Q7*/,11534336/*1.375f Q23*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/}, + { 800, 3, /*1.375f, 0.03125f, 1.0f,*/ 176/*1.375f Q7*/,11534336/*1.375f Q23*/, 1024/*0.03125f Q15*/ , 128/*1.0f Q7*/ } }; const struct TnsParameters tnsParameters32kHz_Stereo[2]= { - { 4500, 3, /*1.35f, 0.0300f, 1.0f ,*/ 173/*1.35f Q7*/, 983/*0.0300f Q15*/ , 128/*1.0f Q7*/}, - { 600, 3, /*1.75f, 0.0625f, 4.4f ,*/ 224/*1.75f Q7*/, 2048/*0.0625f Q15*/ ,563 /*4.4f Q7*/ } + { 4500, 3, /*1.35f, 0.0300f, 1.0f ,*/ 173/*1.35f Q7*/, 11324621/*1.35f Q23*/, 983/*0.0300f Q15*/ , 128/*1.0f Q7*/}, + { 600, 3, /*1.75f, 0.0625f, 4.4f ,*/ 224/*1.75f Q7*/,14680064/*1.75f Q23*/, 2048/*0.0625f Q15*/ ,563 /*4.4f Q7*/ } }; const Word16 tnsAcfWindow_fx[TNS_MAX_FILTER_ORDER] = diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 80822f59e..712c1d702 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -561,6 +561,7 @@ struct TnsParameters Word16 startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ Word16 nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ + Word32 minPredictionGain_32; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ Word16 minEnergyChange; /* Minimum energy change required to turn on the TNS filter. Exponent = 8 */ }; diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index c40db6678..27f3d2aa6 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -4914,8 +4914,8 @@ void TNSAnalysisStereo_fx( test(); test(); test(); - IF( GT_32( pFilter[0]->predictionGain32, L_shl_sat( L_deposit_h( pTnsParameters[0]->minPredictionGain ), sub( PRED_GAIN_E, pFilter[0]->predictionGain_e ) ) ) && LT_32( sts[0]->element_brate, IVAS_80k ) && - GT_32( pFilter[1]->predictionGain32, L_shl_sat( L_deposit_h( pTnsParameters[1]->minPredictionGain ), sub( PRED_GAIN_E, pFilter[1]->predictionGain_e ) ) ) && EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) + IF( GT_32( pFilter[0]->predictionGain32, L_shl_sat( ( pTnsParameters[0]->minPredictionGain_32 ), sub( PRED_GAIN_E, pFilter[0]->predictionGain_e ) ) ) && LT_32( sts[0]->element_brate, IVAS_80k ) && + GT_32( pFilter[1]->predictionGain32, L_shl_sat( ( pTnsParameters[1]->minPredictionGain_32 ), sub( PRED_GAIN_E, pFilter[1]->predictionGain_e ) ) ) && EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) { pFilter[0]->predictionGain32 = pFilter[1]->predictionGain32 = meanPredictionGain_fx; /* more TNS filter sync at 48kbps */ move32(); @@ -4947,7 +4947,7 @@ void TNSAnalysisStereo_fx( test(); test(); - IF( GT_32( meanPredictionGain_fx, L_shl_sat( L_deposit_h( pTnsParameters[0]->minPredictionGain ), sub( PRED_GAIN_E, meanPredictionGain_e ) ) ) || GT_16( maxAvgSqrCoef_fx, pTnsParameters[0]->minAvgSqrCoef ) ) + IF( GT_32( meanPredictionGain_fx, L_shl_sat( ( pTnsParameters[0]->minPredictionGain_32 ), sub( PRED_GAIN_E, meanPredictionGain_e ) ) ) || GT_16( maxAvgSqrCoef_fx, pTnsParameters[0]->minAvgSqrCoef ) ) { test(); test(); @@ -5245,7 +5245,7 @@ void TNSAnalysisStereo_fx( } test(); - IF( GT_32( pFilter->predictionGain32, L_shl_sat( L_deposit_h( pTnsParameters->minPredictionGain ), sub( PRED_GAIN_E, pFilter->predictionGain_e ) ) ) || GT_16( pFilter->avgSqrCoef, pTnsParameters->minAvgSqrCoef ) ) + IF( GT_32( pFilter->predictionGain32, L_shl_sat( ( pTnsParameters->minPredictionGain_32 ), sub( PRED_GAIN_E, pFilter->predictionGain_e ) ) ) || GT_16( pFilter->avgSqrCoef, pTnsParameters->minAvgSqrCoef ) ) { test(); test(); diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 91e1b8520..db77144df 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -246,94 +246,6 @@ static Word16 IGF_getSFM_new_fx( /*! r: spectral tilt value */ /* Returns value with exponent as 9 and Q as 22*/ -static Word32 IGF_getTNR_fx( - const Word32 *powerSpectrum, /* i : energies */ - const Word16 start, /* i : start subband index */ - const Word16 stop, /* i : stop subband index */ - const Word16 adap, /* i : SFB width adaptation */ - Word16 e_ps, /*Stores exponent for powerSpectrum*/ - Word16 e_adap /*Stores exponent for adap*/ -) -{ - Word16 i; - Word16 width; - Word32 avg; - Word32 tonal; - Word16 tonal_e; /* holds exp for tonal*/ - Word32 noise; - Word16 noise_e; /* holds exp for noise*/ - Word32 tonalToNoise; - Word32 rootSpec[300]; - Word16 rootSpec_e[300]; /*rootSpec_e[i] holds exp for rootSpec[i]*/ - Word16 avg_e; /* holds exp for avg*/ - Word16 tmp_e; - avg = 0; - tonal = 0; - noise = EPSILON_FX; - tonal_e = 0; - noise_e = 0; - avg_e = 0; - tmp_e = 0; - move32(); - move32(); - move32(); - move16(); - move16(); - move16(); - move16(); - - set32_fx( rootSpec, 0, 300 ); - set16_fx( rootSpec_e, 0, 300 ); - - width = sub( stop, start ); - FOR( i = start; i < stop; i++ ) - { - rootSpec_e[i - start] = e_ps; - move16(); - rootSpec[i - start] = Sqrt32( powerSpectrum[i], &rootSpec_e[i - start] ); /*rootSpec[i - start] = sqrtf( powerSpectrum[i] );*/ - move32(); - avg = BASOP_Util_Add_Mant32Exp( avg, avg_e, rootSpec[i - start], rootSpec_e[i - start], &avg_e ); /*avg += rootSpec[i - start];resultant exponent is avg_e*/ - } - avg = BASOP_Util_Divide3216_Scale( avg, width, &tmp_e ); /*avg /= width;*/ - avg_e = add( 16, sub( add( avg_e, tmp_e ), 15 ) ); - - FOR( i = start; i < stop; i++ ) - { - Word16 normSpec_e; /*stores resultant exponent for normSpec*/ - Word16 normSpec = BASOP_Util_Divide3232_Scale( rootSpec[i - start], avg, &normSpec_e ); /*rootSpec[i - start] / avg;*/ - normSpec_e = add( normSpec_e, sub( rootSpec_e[i - start], avg_e ) ); - IF( GT_32( normSpec, L_add( L_shl( 1, sub( 15, normSpec_e ) ), L_shl( adap, sub( e_adap, normSpec_e ) ) ) ) ) - { - tonal = BASOP_Util_Add_Mant32Exp( tonal, tonal_e, rootSpec[i - start], rootSpec_e[i - start], &tonal_e ); /*tonal += rootSpec[i - start];*/ - } - ELSE IF( LT_32( normSpec, L_shl( 1, sub( 15, normSpec_e ) ) ) ) - { - noise = BASOP_Util_Add_Mant32Exp( noise, noise_e, rootSpec[i - start], rootSpec_e[i - start], &noise_e ); /*noise += rootSpec[i - start];*/ - } - } - - /*tonalToNoise = 20.f * log10f( max( 1e-018f, tonal / noise ) )*/ - IF( noise == 0 ) // To handle condition if denom = 0 - { - tonalToNoise = imult3216( L_shr( L_add( L_shl( 18 /* log10f(1e-018f) */, Q25 ), Mpy_32_16_1( L_add( BASOP_Util_Log2( tonal ), L_shl( tonal_e, Q25 ) ) /*Q25*/, INV_Log2_10_Q15 ) /*25+15-15*/ ), 3 ) /*Q22*/, 20 ); - } - ELSE - { - Word16 temp = BASOP_Util_Divide3232_Scale( tonal, noise, &tmp_e ); /*tonal / noise*/ - tmp_e = add( tmp_e, sub( tonal_e, noise_e ) ); - IF( GE_16( temp, 1 ) ) - { - tonalToNoise = imult3216( Mult_32_16( L_add( BASOP_Util_Log2( temp ), L_shl( add( 16, tmp_e ), Q25 ) ) /*Q25*/, INV_Log2_10_Q12 ) /*25+12-15*/, 20 ); /*Q22*/ - } - ELSE - { - tonalToNoise = -1509949440; /*-360.f Q22*/ - move32(); - } - } - - return tonalToNoise; -} static Word32 IGF_getTNR_ivas_fx( const Word32 *powerSpectrum, /* i : energies */ @@ -1000,7 +912,7 @@ static void IGF_CalculateStereoEnvelope_fx( const Word32 *pMDCTSpectrumMsInv_fx, /* i : MDCT spectrum */ Word16 pMDCTSpectrumMsInv_e, /* i : expontent for pMDCTSpectrumMsInv_fx */ const Word32 *pPowerSpectrum_fx, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 pPowerSpectrum_e, /* i : exponent for pPowerSpectrum_fx */ + Word16 *pPowerSpectrum_e, /* i : exponent for pPowerSpectrum_fx */ const Word32 *pPowerSpectrumMsInv_fx, /* i : inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv, /* i : Q for pPowerSpectrumMsInv_fx */ const Word16 igfGridIdx, /* i : IGF grid index */ @@ -1033,19 +945,19 @@ static void IGF_CalculateStereoEnvelope_fx( Word16 sfm; Word16 crest; Word16 temp; - Word16 mean_x_e, mean_y_e; /*Stores exponent for mean_x and mean_y respectively*/ - Word16 mean_xy_e, mean_x2_e; /*stores exponent for mean_xy and mean_x2 respectively*/ - Word16 tileSrcSpec_e; /*Exponent for tileSrcSpec_fx*/ - Word16 sfbEnergyTileR_e; /*Exponent for sfbEnergyTileR_fx*/ - Word16 sfbEnergyTileC_e; /*Exponent for sfbEnergyTileC_fx*/ - Word16 sfbEnergyC_e; /*Exponent for sfbEnergyC_fx*/ - Word16 gain_e; /*exponent for gain_fx*/ - Word16 crest_exp; /*stores exponent for output from crest*/ - Word16 sfm_exp; /*stores exponent for ouput from sfm*/ - Word16 tmp_tb_e; /*Stores exponent for tmp_tb_fx*/ - Word16 tmp_sb_e; /*stores exponent for tmp_sb_fx*/ - Word16 slope_e; /*stores exponent for slope_fx*/ - Word16 sfbEnergyR_e; /*stores exponent for sfbEnergyR*/ + Word16 mean_x_e, mean_y_e; /*Stores exponent for mean_x and mean_y respectively*/ + Word16 mean_xy_e, mean_x2_e; /*stores exponent for mean_xy and mean_x2 respectively*/ + Word16 tileSrcSpec_e[MAX_IGF_SFB_LEN]; /*Exponent for tileSrcSpec_fx*/ + Word16 sfbEnergyTileR_e; /*Exponent for sfbEnergyTileR_fx*/ + Word16 sfbEnergyTileC_e; /*Exponent for sfbEnergyTileC_fx*/ + Word16 sfbEnergyC_e; /*Exponent for sfbEnergyC_fx*/ + Word16 gain_e; /*exponent for gain_fx*/ + Word16 crest_exp; /*stores exponent for output from crest*/ + Word16 sfm_exp; /*stores exponent for ouput from sfm*/ + Word16 tmp_tb_e; /*Stores exponent for tmp_tb_fx*/ + Word16 tmp_sb_e; /*stores exponent for tmp_sb_fx*/ + Word16 slope_e; /*stores exponent for slope_fx*/ + Word16 sfbEnergyR_e; /*stores exponent for sfbEnergyR*/ Word16 tmp_e; Word32 temp_pPowerSpectrumMsInv[N_MAX], length; Word16 q_temp_pPowerSpectrumMsInv = Q31, i; @@ -1110,7 +1022,7 @@ static void IGF_CalculateStereoEnvelope_fx( /*hPrivateData->logSpec[sb] = max( 0, (Word16) ( logf( max( FLT_MIN, pPowerSpectrum[sb] ) ) * INV_LOG_2 ) );*/ IF( LE_32( 1, pPowerSpectrum_fx[sb] ) ) { - hPrivateData->logSpec[sb] = s_max( 0, (Word16) L_shr( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e, Q25 ) ), 25 ) ); + hPrivateData->logSpec[sb] = s_max( 0, (Word16) L_shr( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e[sb], Q25 ) ), 25 ) ); } ELSE { @@ -1152,25 +1064,25 @@ static void IGF_CalculateStereoEnvelope_fx( { IF( NE_16( coreMsMask[sb], coreMsMask[strt_cpy] ) ) { - sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e, &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ + sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e[sb], &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ norm_exp = norm_l( pMDCTSpectrumMsInv_fx[strt_cpy] ); final_exp = sub( pMDCTSpectrumMsInv_e, norm_exp ); scaled_value = L_shl( pMDCTSpectrumMsInv_fx[strt_cpy], norm_exp ); sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrumMsInv_fx[strt_cpy], sub( 31, q_pPowerSpectrumMsInv[strt_cpy] ), &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ - tileSrcSpec_fx[sub( strt_cpy, tmp )] = temp_pPowerSpectrumMsInv[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ - tileSrcSpec_e = sub( 31, q_temp_pPowerSpectrumMsInv ); + tileSrcSpec_fx[strt_cpy - tmp] = temp_pPowerSpectrumMsInv[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ + tileSrcSpec_e[strt_cpy - tmp] = sub( 31, q_temp_pPowerSpectrumMsInv ); } ELSE { - sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e, &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ + sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e[sb], &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ norm_exp = norm_l( pMDCTSpectrum_fx[strt_cpy] ); final_exp = sub( pMDCTSpectrum_e, norm_exp ); scaled_value = L_shl( pMDCTSpectrum_fx[strt_cpy], norm_exp ); sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ - sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrum_fx[strt_cpy], pPowerSpectrum_e, &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ - tileSrcSpec_fx[sub( strt_cpy, tmp )] = pPowerSpectrum_fx[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ - tileSrcSpec_e = pPowerSpectrum_e; + sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrum_fx[strt_cpy], pPowerSpectrum_e[strt_cpy], &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ + tileSrcSpec_fx[strt_cpy - tmp] = pPowerSpectrum_fx[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ + tileSrcSpec_e[strt_cpy - tmp] = pPowerSpectrum_e[strt_cpy]; } move32(); move16(); @@ -1197,14 +1109,14 @@ static void IGF_CalculateStereoEnvelope_fx( move16(); // tmp_tb = IGF_getSFM_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); - crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); + sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); + crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/ // tmp_sb = IGF_getSFM_ivas(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest_ivas(tileSrcSpec, 0, strt_cpy - tmp); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, tileSrcSpec_fx, &tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); - crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); + sfm = IGF_getSFM_ivas_fx( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); + crest = IGF_getCrest_ivas( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); tmp_sb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_sb_fx*/ @@ -1320,7 +1232,7 @@ static void IGF_CalculateStereoEnvelope_fx( } ELSE { - y = imult1616( 20, extract_l( L_shr( Mult_32_16( ( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e, Q25 ) ) ), INV_Log2_10_Q15 ), 25 ) ) ); /*Q0*/ + y = imult1616( 20, extract_l( L_shr( Mult_32_16( ( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e[sb], Q25 ) ) ), INV_Log2_10_Q15 ), 25 ) ) ); /*Q0*/ } mean_y_fx = add( mean_y_fx, y ); /*Q0*/ mean_xy_fx = L_add( mean_xy_fx, L_mult0( y, x ) ); /*Q0*/ @@ -1348,8 +1260,8 @@ static void IGF_CalculateStereoEnvelope_fx( { Word16 shift = shr( width, 1 ); // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); - crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); + sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); + crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); } ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), threshold_fx, add( threshold_e, 16 ) ), 1 ) && ( NE_16( sfb, sub( hGrid->sfbWrap[hGrid->nTiles], 1 ) ) ) ) @@ -1357,8 +1269,8 @@ static void IGF_CalculateStereoEnvelope_fx( Word16 shift; shift = shr( width, 1 ); // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); - crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); + sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); + crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); } IF( shiftedSFM_fx ) @@ -1410,7 +1322,7 @@ static void IGF_CalculateStereoEnvelope_fx( tonalToNoise_e = 9; /*stores exponent for tonalToNoise*/ move16(); adap = BASOP_Util_Divide1616_Scale( width, 30, &adap_e ); - tonalToNoise = IGF_getTNR_fx( pPowerSpectrum_fx, swb_offset[sfb], swb_offset[sfb + 1], adap, pPowerSpectrum_e, adap_e ); /*Q22*/ + tonalToNoise = IGF_getTNR_ivas_fx( pPowerSpectrum_fx, swb_offset[sfb], swb_offset[sfb + 1], adap, pPowerSpectrum_e, adap_e ); /*Q22*/ IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tonalToNoise, tonalToNoise_e, L_add( L_shl( 10, sub( 15, adap_e ) ), adap ), add( 16, adap_e ) ), -1 ) ) { // currDampingFactor += 0.1f * ( ( 10 + adap ) - tonalToNoise ); @@ -2564,7 +2476,7 @@ void IGFEncApplyMono_ivas_fx( Word32 common_pPowerSpectrum_fx[N_MAX + L_MDCT_OVLP_MAX]; - set32_fx( common_pPowerSpectrum_fx, 0, N_MAX + L_MDCT_OVLP_MAX ); + set32_fx( common_pPowerSpectrum_fx, 0, N_MAX); Word16 common_pPowerSpectrum_exp = MIN16B; move16(); @@ -2652,7 +2564,7 @@ void IGFEncApplyStereo_fx( const Word16 igfGridIdx, /* i : IGF grid index */ Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ @@ -2662,13 +2574,19 @@ void IGFEncApplyStereo_fx( const Word32 element_brate, /* i : element bitrate */ const Word16 mct_on ) { - Word32 *pPowerSpectrumParameter_fx[NB_DIV]; /* If it is NULL it informs a function that specific handling is needed */ + Word32 *pPowerSpectrumParameter_fx[NB_DIV]; /* If it is NULL it informs a function that specific handling is needed */ + Word16 *exp_pPowerSpectrumParameter_fx[NB_DIV]; /* If it is NULL it informs a function that specific handling is needed */ Word32 *pPowerSpectrumParameterMsInv_fx[NB_DIV]; Word16 *q_pPowerSpectrumParameterMsInv_fx[NB_DIV]; Word16 coreMsMask[N_MAX]; Word16 sfb, ch, last_core_acelp; STEREO_MDCT_BAND_PARAMETERS *sfbConf; - Word16 exp_pPowerSpectrum[L_FRAME48k]; + Word32 common_pPowerSpectrum_fx[N_MAX]; + + set32_fx( common_pPowerSpectrum_fx, 0, N_MAX ); + + Word16 common_pPowerSpectrum_exp = MIN16B; + move16(); /* assumptions: stereo filling was already done on the flattened spectra * IGF region is always coded M/S, never L/R (to be done in the encoder) @@ -2705,7 +2623,9 @@ void IGFEncApplyStereo_fx( IF( EQ_16( sts[0]->core, TCX_20_CORE ) && !sts[0]->hTcxEnc->fUseTns[frameno] && !sts[1]->hTcxEnc->fUseTns[frameno] ) { pPowerSpectrumParameter_fx[0] = &pPowerSpectrum_fx[0][0]; + exp_pPowerSpectrumParameter_fx[0] = &exp_pPowerSpectrum_fx[0][0]; pPowerSpectrumParameter_fx[1] = &pPowerSpectrum_fx[1][0]; + exp_pPowerSpectrumParameter_fx[1] = &exp_pPowerSpectrum_fx[1][0]; pPowerSpectrumParameterMsInv_fx[0] = pPowerSpectrumMsInv_fx[0][0]; pPowerSpectrumParameterMsInv_fx[1] = pPowerSpectrumMsInv_fx[1][0]; q_pPowerSpectrumParameterMsInv_fx[0] = q_pPowerSpectrumMsInv_fx[0][0]; @@ -2732,17 +2652,37 @@ void IGFEncApplyStereo_fx( IF( EQ_16( sts[ch]->core, TCX_20_CORE ) ) { pPowerSpectrumParameter_fx[ch] = pPowerSpectrum_fx[ch]; + exp_pPowerSpectrumParameter_fx[ch] = exp_pPowerSpectrum_fx[ch]; } ELSE { pPowerSpectrumParameter_fx[ch] = NULL; } - set16_fx( exp_pPowerSpectrum, exp_pPowerSpectrum_fx[ch], L_FRAME48k ); + IGF_Whitening_ivas_fx( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], exp_pPowerSpectrumParameter_fx[ch], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); - IGF_Whitening_ivas_fx( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], &exp_pPowerSpectrum[0], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); + IF( pPowerSpectrumParameter_fx[ch] ) + { + Word16 length = N_MAX; + move16(); + if ( mct_on ) + { + length = L_FRAME48k; + move16(); + } + FOR( Word16 i = 0; i < length; i++ ) + { + common_pPowerSpectrum_exp = s_max( common_pPowerSpectrum_exp, exp_pPowerSpectrumParameter_fx[ch][i] ); + } - IGF_ErodeSpectrum_ivas_fx( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], exp_pPowerSpectrum_fx[ch], igfGridIdx, mct_on ); + FOR( Word16 i = 0; i < length; i++ ) + { + common_pPowerSpectrum_fx[i] = L_shl( pPowerSpectrumParameter_fx[ch][i], sub( exp_pPowerSpectrumParameter_fx[ch][i], common_pPowerSpectrum_exp ) ); + move32(); + } + pPowerSpectrumParameter_fx[ch] = common_pPowerSpectrum_fx; + } + IGF_ErodeSpectrum_ivas_fx( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], common_pPowerSpectrum_exp, igfGridIdx, mct_on ); } return; } diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index f78ad2025..2befbe8ba 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -781,6 +781,87 @@ Word16 IGF_getCrest( /**< ou return crest; } +Word16 IGF_getCrest_ivas( /**< out: Q15| crest factor */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ +) +{ + Word16 i; + Word16 x; + Word16 s; + Word32 x_eff32; + Word16 x_max; + Word16 crest; + Word16 tmp; + Word32 tmp32; + + x_eff32 = 0; + move32(); + x_max = 0; + move16(); + crest = 16384 /*.5f Q15*/; + move16(); + *crest_exp = 1; + move16(); + + FOR( i = start; i < stop; i++ ) + { + /*x = max(0, (int)(log(powerSpectrum[i]) * INV_LOG_2));*/ + + /*see IGF_getSFM for more comment */ + x = sub( sub( powerSpectrum_exp[i], norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ + if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ + { + x = 0; + move16(); + } + x = s_max( 0, x ); + x_eff32 = L_mac0( x_eff32, x, x ); /*Q0*/ + x_max = s_max( x_max, x ); /*Q0*/ + } + + /*x_eff /= (stop - start);*/ + x_eff32 = BASOP_Util_Divide3216_Scale( x_eff32, sub( stop, start ), &s ); /*Q-1, s*/ + s = add( s, 32 ); /*make x_eff Q31*/ + + /*trunkate to int*/ + x_eff32 = L_shr( x_eff32, sub( 31, s ) ); + x_eff32 = L_shl( x_eff32, sub( 31, s ) ); + + test(); + IF( x_eff32 > 0 && x_max > 0 ) + { + /*crest = max(1.f, (float)x_max/sqrt(x_eff));*/ + tmp32 = ISqrt32( x_eff32, &s ); /*Q31, s*/ + tmp32 = Mpy_32_16_1( tmp32 /*Q31, s*/, x_max /*Q0*/ ); /*Q16, s*/ + i = norm_l( tmp32 ); + tmp32 = L_shl( tmp32, i ); /*Q31, s-i+15*/ + crest = extract_h( tmp32 ); + *crest_exp = add( sub( s, i ), 15 ); + move16(); + /* limit crest factor to a lower bound of 1, may overflow */ + BASOP_SATURATE_WARNING_OFF_EVS + tmp = shl_sat( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ + tmp = add_sat( crest, tmp ); + BASOP_SATURATE_WARNING_ON_EVS + if ( tmp < 0 ) + { + crest = 1; + move16(); + } + if ( tmp < 0 ) + { + *crest_exp = 15; + move16(); + } + } + + return crest; +} + /************************************************************************* calculates spectral flatness measurment **************************************************************************/ @@ -932,7 +1013,7 @@ Word16 IGF_getSFM_ivas_fx( /**< out: Q15| SFM value /* n = sub(n,31); */ /*<- -Qx */ /* n = add(n,*energy_exp); */ /*<- +xExp */ - n = sub( sub( *energy_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ + n = sub( sub( energy_exp[i], norm_l( energy[i] ) ), 1 ); /*<-- short form*/ if ( energy[i] == 0 ) /*special case: energy is zero*/ { @@ -943,7 +1024,7 @@ Word16 IGF_getSFM_ivas_fx( /**< out: Q15| SFM value n = s_max( 0, n ); num = L_add( num, L_deposit_l( n ) ); /*Q0*/ - denom = BASOP_Util_Add_Mant32Exp( energy[i], *energy_exp, denom, denom_exp, &denom_exp ); + denom = BASOP_Util_Add_Mant32Exp( energy[i], energy_exp[i], denom, denom_exp, &denom_exp ); } /* calculate SFM only if signal is present */ diff --git a/lib_enc/ivas_dirac_enc_fx.c b/lib_enc/ivas_dirac_enc_fx.c index 615a6f4b6..be15b5048 100644 --- a/lib_enc/ivas_dirac_enc_fx.c +++ b/lib_enc/ivas_dirac_enc_fx.c @@ -849,16 +849,17 @@ void computeReferencePower_enc_fx( Word16 ref_power_w, /* i : use 0 if hodirac is enabled Q0*/ const Word16 nchan_ana, /* i : number of analysis channels Q0*/ Word16 inp_q, /* i : q of cld buffers */ - Word16 *ref_exp /* i : output q */ -) + Word16 q_reference_power[DIRAC_NO_FB_BANDS_MAX] ) { Word16 brange[2]; Word16 ch_idx, i, j; - Word16 ref_Q = 63; - move16(); + Word16 num_bins, guard_bits, norm; Word64 reference_power_tmp[DIRAC_MAX_NBANDS]; Word64 reference_power_W[DIRAC_MAX_NBANDS]; + + Word16 shift_ref_power = sub( shl( inp_q, 1 ), 31 ); + FOR( i = 0; i < num_freq_bands; i++ ) { brange[0] = band_grouping[i + enc_param_start_band]; /* Q0 */ @@ -871,24 +872,28 @@ void computeReferencePower_enc_fx( move64(); reference_power_tmp[i] = 0; move64(); + + num_bins = sub( brange[1], brange[0] ); + guard_bits = find_guarded_bits_fx( num_bins ); + FOR( j = brange[0]; j < brange[1]; j++ ) { - // 2*inp_q + 1 - reference_power_W[i] = W_add( reference_power_W[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ) ); + reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ), guard_bits ) ); // 2*inp_q + 1 - guard_bits move64(); } - reference_power_tmp[i] = W_add( reference_power_tmp[i], reference_power_W[i] ); // 2*inp_q + 1 + reference_power_tmp[i] = W_add( reference_power_tmp[i], reference_power_W[i] ); // 2*inp_q + 1 - guard_bits move64(); FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) { /* abs()^2 */ FOR( j = brange[0]; j < brange[1]; j++ ) { - reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); + reference_power_tmp[i] = W_add( reference_power_tmp[i], W_shr( W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ), guard_bits ) ); // 2*inp_q + 1 - guard_bits move64(); } - // 2*inp_q + 1 } + q_reference_power[i] = sub( shift_ref_power, guard_bits ); + move16(); } FOR( i = 0; i < num_freq_bands; i++ ) { @@ -908,20 +913,21 @@ void computeReferencePower_enc_fx( } } } + FOR( i = 0; i < num_freq_bands; i++ ) { - ref_Q = s_min( ref_Q, W_norm( reference_power_tmp[i] ) ); - } - FOR( i = 0; i < num_freq_bands; i++ ) - { - reference_power_tmp[i] = W_shl( reference_power_tmp[i], ref_Q ); // 2*inp_q + 1 + ref_Q - move64(); - reference_power[i] = W_extract_h( reference_power_tmp[i] ); // 2*inp_q + ref_Q - 31 + norm = 63; + move16(); + IF( reference_power_tmp[i] != 0 ) + { + norm = W_norm( reference_power_tmp[i] ); + } + reference_power[i] = W_extract_h( W_shl( reference_power_tmp[i], norm ) ); // 2 * inp_q + 1 - guard_bits + norm - 32 move32(); + q_reference_power[i] = add( q_reference_power[i], norm ); + move16(); } - *ref_exp = sub( Q31, ( sub( add( shl( inp_q, Q1 ), ref_Q ), Q31 ) ) ); - move16(); return; } /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_mcmasa_enc_fx.c b/lib_enc/ivas_mcmasa_enc_fx.c index b89424e76..314424341 100644 --- a/lib_enc/ivas_mcmasa_enc_fx.c +++ b/lib_enc/ivas_mcmasa_enc_fx.c @@ -89,7 +89,7 @@ static void computeIntensityVector_enc_fx( const Word16 enc_param_start_band, /* i : first band to process */ const Word16 num_frequency_bands, Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], - Word16 *exp_intensity_real, + Word16 q_intensity_real[MASA_FREQUENCY_BANDS], Word16 inp_q ); static void computeVerticalDiffuseness_fx( @@ -947,7 +947,9 @@ void ivas_mcmasa_param_est_enc_fx( Word32 renormalization_factor_coh_fx[MASA_FREQUENCY_BANDS]; // renormalization_factor_coh_e Word16 renormalization_factor_coh_e[MASA_FREQUENCY_BANDS]; Word16 surroundingCoherence_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 numAnalysisChannels, shift; + Word16 numAnalysisChannels; + Word16 q_intensity_real_fx[MASA_FREQUENCY_BANDS], q_intensity_even_real_fx[MASA_FREQUENCY_BANDS], q_reference_power_fx[DIRAC_NO_FB_BANDS_MAX]; + Word16 c_e, ref_e, shift; FOR( i = 0; i < MCMASA_MAX_ANA_CHANS; i++ ) { @@ -1038,7 +1040,7 @@ void ivas_mcmasa_param_est_enc_fx( FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { - Word16 cr_q = MAX_16, ci_q = MAX_16, sf, c_e; + Word16 cr_q = MAX_16, ci_q = MAX_16, sf; Word16 inp_q = q_inp; move16(); move16(); @@ -1062,7 +1064,6 @@ void ivas_mcmasa_param_est_enc_fx( scale_sig32( Chnl_ImagBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX, sf ); // Q-> inp_q + sf } inp_q = add( inp_q, sf ); - c_e = sub( 31, inp_q ); /* Compute covariance matrix */ FOR( i = 0; i < num_freq_bands; i++ ) @@ -1177,7 +1178,9 @@ void ivas_mcmasa_param_est_enc_fx( Foa_ImagBuffer_fx, 0, num_freq_bands, - intensity_real_fx, &c_e, inp_q ); + intensity_real_fx, + q_intensity_real_fx, + inp_q ); computeDirectionVectors_fixed( intensity_real_fx[0], @@ -1187,8 +1190,9 @@ void ivas_mcmasa_param_est_enc_fx( num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], - direction_vector_fx[2], c_e, - NULL ); + direction_vector_fx[2], + 0, + q_intensity_real_fx ); /* Power and intensity estimation for diffuseness */ computeIntensityVector_enc_fx( @@ -1197,19 +1201,54 @@ void ivas_mcmasa_param_est_enc_fx( FoaEven_ImagBuffer_fx, 0, num_freq_bands, - intensity_even_real_fx, &shift, inp_q ); + intensity_even_real_fx, + q_intensity_even_real_fx, + inp_q ); - Word16 ref_e = 0; - move16(); - computeReferencePower_enc_fx( hMcMasa->band_grouping, - FoaEven_RealBuffer_fx, - FoaEven_ImagBuffer_fx, - reference_power_fx[ts], - 0, - num_freq_bands, - MC_FORMAT, - 0, - FOA_CHANNELS, inp_q, &ref_e ); + computeReferencePower_enc_fx( + hMcMasa->band_grouping, + FoaEven_RealBuffer_fx, + FoaEven_ImagBuffer_fx, + reference_power_fx[ts], + 0, + num_freq_bands, + MC_FORMAT, + 0, + FOA_CHANNELS, + inp_q, + q_reference_power_fx ); + + minimum_fx( q_intensity_real_fx, num_freq_bands, &c_e ); + minimum_fx( q_intensity_even_real_fx, num_freq_bands, &shift ); + minimum_fx( q_reference_power_fx, num_freq_bands, &ref_e ); + + Word16 tmp; + FOR( i = 0; i < num_freq_bands; i++ ) + { + tmp = sub( c_e, q_intensity_real_fx[i] ); + intensity_real_fx[0][i] = L_shl( intensity_real_fx[0][i], tmp ); + move32(); + intensity_real_fx[1][i] = L_shl( intensity_real_fx[1][i], tmp ); + move32(); + intensity_real_fx[2][i] = L_shl( intensity_real_fx[2][i], tmp ); + move32(); + + tmp = sub( shift, q_intensity_even_real_fx[i] ); + intensity_even_real_fx[0][i] = L_shl( intensity_even_real_fx[0][i], tmp ); + move32(); + intensity_even_real_fx[1][i] = L_shl( intensity_even_real_fx[1][i], tmp ); + move32(); + intensity_even_real_fx[2][i] = L_shl( intensity_even_real_fx[2][i], tmp ); + move32(); + + tmp = sub( ref_e, q_reference_power_fx[i] ); + reference_power_fx[ts][i] = L_shl( reference_power_fx[ts][i], tmp ); + move32(); + } + + c_e = sub( Q31, c_e ); + shift = sub( Q31, shift ); + ref_e = sub( Q31, ref_e ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hMcMasa->index_buffer_intensity = add( ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ @@ -2089,15 +2128,13 @@ static void computeIntensityVector_enc_fx( const Word16 enc_param_start_band, /* i : first band to process */ const Word16 num_frequency_bands, Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], /*exp: exp_intensity_real*/ - Word16 *exp_intensity_real, + Word16 q_intensity_real[MASA_FREQUENCY_BANDS], Word16 inp_q ) { Word16 i, j; Word32 real, img; - Word16 brange[2], shift = 63; - move16(); - Flag is_zero = 0; - move16(); + Word16 brange[2]; + Word16 shift_intensity_real, num_bins, guard_bits, norm; Word64 intensity_real64[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; @@ -2106,6 +2143,8 @@ static void computeIntensityVector_enc_fx( set64_fx( intensity_real64[i], 0, MASA_FREQUENCY_BANDS ); } + shift_intensity_real = sub( shl( inp_q, 1 ), 32 ); + FOR( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; i++ ) { brange[0] = band_grouping[i]; @@ -2113,6 +2152,9 @@ static void computeIntensityVector_enc_fx( brange[1] = band_grouping[i + 1]; move16(); + num_bins = sub( brange[1], brange[0] ); + guard_bits = find_guarded_bits_fx( num_bins ); + intensity_real[0][i] = 0; move32(); intensity_real[1][i] = 0; @@ -2127,45 +2169,37 @@ static void computeIntensityVector_enc_fx( img = Cldfb_ImagBuffer[0][j]; move32(); /* Intensity is XYZ order, audio is WYZX order. */ - intensity_real64[0][i] = W_add( intensity_real64[0][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[3][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q= 2* input_q + intensity_real64[0][i] = W_add( intensity_real64[0][i], W_shr( W_add( W_mult0_32_32( Cldfb_RealBuffer[3][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[3][j], img ) ), guard_bits ) ); // output Q= 2* input_q - guard_bits move32(); - intensity_real64[1][i] = W_add( intensity_real64[1][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[1][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q= 2* input_q + intensity_real64[1][i] = W_add( intensity_real64[1][i], W_shr( W_add( W_mult0_32_32( Cldfb_RealBuffer[1][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[1][j], img ) ), guard_bits ) ); // output Q= 2* input_q - guard_bits move32(); - intensity_real64[2][i] = W_add( intensity_real64[2][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[2][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q= 2* input_q + intensity_real64[2][i] = W_add( intensity_real64[2][i], W_shr( W_add( W_mult0_32_32( Cldfb_RealBuffer[2][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[2][j], img ) ), guard_bits ) ); // output Q= 2* input_q - guard_bits move32(); } - } - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - is_zero = is_zero_arr64( intensity_real64[i], MASA_FREQUENCY_BANDS ); - IF( is_zero == 0 ) + norm = 63; + move16(); + IF( intensity_real64[0][i] != 0 ) { - BREAK; + norm = s_min( norm, W_norm( intensity_real64[0][i] ) ); } - } - IF( is_zero == 0 ) - { - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + IF( intensity_real64[1][i] != 0 ) { - shift = s_min( shift, W_norm_arr( intensity_real64[i], MASA_FREQUENCY_BANDS ) ); + norm = s_min( norm, W_norm( intensity_real64[1][i] ) ); } - - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + IF( intensity_real64[2][i] != 0 ) { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - intensity_real[i][j] = W_extract_h( W_shl( intensity_real64[i][j], shift ) ); - move32(); - } + norm = s_min( norm, W_norm( intensity_real64[2][i] ) ); } - *exp_intensity_real = sub( 31, sub( add( shift, shl( inp_q, 1 ) ), 32 ) ); - move16(); - } - ELSE - { - *exp_intensity_real = 0; + intensity_real[0][i] = W_extract_h( W_shl( intensity_real64[0][i], norm ) ); /*2 * inp_q - guard_bits + norm - 32*/ + move32(); + intensity_real[1][i] = W_extract_h( W_shl( intensity_real64[1][i], norm ) ); /*2 * inp_q - guard_bits + norm - 32*/ + move32(); + intensity_real[2][i] = W_extract_h( W_shl( intensity_real64[2][i], norm ) ); /*2 * inp_q - guard_bits + norm - 32*/ + move32(); + + q_intensity_real[i] = add( shift_intensity_real, sub( norm, guard_bits ) ); move16(); } diff --git a/lib_enc/ivas_mct_enc_mct_fx.c b/lib_enc/ivas_mct_enc_mct_fx.c index 8ff17ae01..8acbd42fc 100644 --- a/lib_enc/ivas_mct_enc_mct_fx.c +++ b/lib_enc/ivas_mct_enc_mct_fx.c @@ -996,6 +996,7 @@ void mctStereoIGF_enc_fx( Word32 *p_inv_spectrum_fx[CPE_CHANNELS][NB_DIV]; Word32 *p_orig_spectrum_fx[CPE_CHANNELS][NB_DIV]; Word32 *p_powerSpec_fx[NB_DIV]; + Word16 *p_exp_powerSpec_fx[NB_DIV]; Word16 b, nSubframes, L_subframeTCX; Word16 p_ch[2], n, ch, ch1, ch2; @@ -1004,7 +1005,7 @@ void mctStereoIGF_enc_fx( Encoder_State *st; Word16 singleChEle[MCT_MAX_CHANNELS]; Word16 q_spectrum; - Word16 exp_powerSpec[MCT_MAX_CHANNELS][N_MAX + L_MDCT_OVLP_MAX]; + Word16 exp_powerSpec[MCT_MAX_CHANNELS][L_FRAME48k]; L_subframeTCX = 0; /* to avoid compilation warning */ move16(); @@ -1042,7 +1043,9 @@ void mctStereoIGF_enc_fx( } p_powerSpec_fx[0] = powerSpec_fx[ch1]; // q_powerSpec + p_exp_powerSpec_fx[0] = exp_powerSpec[ch1]; // q_powerSpec p_powerSpec_fx[1] = powerSpec_fx[ch2]; + p_exp_powerSpec_fx[1] = exp_powerSpec[ch2]; /* Band-wise M/S for MDST */ nSubframes = NB_DIV; @@ -1072,17 +1075,16 @@ void mctStereoIGF_enc_fx( IF( NE_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[n], hMCT->hBlockData[b]->hStereoMdct->IGFStereoMode[n] ) || EQ_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[n], SMDCT_BW_MS ) ) { - Word16 exp_powerSpec_fx[CPE_CHANNELS], exp_inv_spectrum_fx[CPE_CHANNELS]; + Word16 exp_inv_spectrum_fx[CPE_CHANNELS]; FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - exp_powerSpec_fx[ch] = sub( Q31, q_pS_ch[ch] ); exp_inv_spectrum_fx[ch] = p_st[ch]->hTcxEnc->spectrum_e[n]; move16(); - move16(); } - - ProcessStereoIGF_fx( hMCT->hBlockData[b]->hStereoMdct, p_st, hMCT->hBlockData[b]->mask, p_orig_spectrum_fx, q_origSpec, q_origSpec, p_powerSpec_fx, exp_powerSpec_fx, + set16_fx( exp_powerSpec[ch1], sub( Q31, q_pS_ch[0] ), L_FRAME48k ); + set16_fx( exp_powerSpec[ch2], sub( Q31, q_pS_ch[1] ), L_FRAME48k ); + ProcessStereoIGF_fx( hMCT->hBlockData[b]->hStereoMdct, p_st, hMCT->hBlockData[b]->mask, p_orig_spectrum_fx, q_origSpec, q_origSpec, p_powerSpec_fx, p_exp_powerSpec_fx, p_powerSpecMsInv_fx, q_p_powerSpecMsInv_fx, p_inv_spectrum_fx, exp_inv_spectrum_fx, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 ); } ELSE @@ -1100,7 +1102,7 @@ void mctStereoIGF_enc_fx( q_spectrum = sub( 31, st->hTcxEnc->spectrum_e[n] ); - set16_fx( exp_powerSpec[p_ch[ch]], sub( Q31, q_powerSpec[p_ch[ch]] ), N_MAX + L_MDCT_OVLP_MAX ); + set16_fx( exp_powerSpec[p_ch[ch]], sub( Q31, q_powerSpec[p_ch[ch]] ), L_FRAME48k ); ProcessIGF_ivas_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[p_ch[ch]][n], q_origSpec, &powerSpec_fx[p_ch[ch]][n * L_subframeTCX], &exp_powerSpec[p_ch[ch]][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); st->hTcxEnc->spectrum_e[n] = sub( 31, q_spectrum ); @@ -1141,7 +1143,7 @@ void mctStereoIGF_enc_fx( { q_spectrum = sub( 31, st->hTcxEnc->spectrum_e[n] ); - set16_fx( exp_powerSpec[ch], sub( Q31, q_powerSpec[ch] ), N_MAX + L_MDCT_OVLP_MAX ); + set16_fx( exp_powerSpec[ch], sub( Q31, q_powerSpec[ch] ), L_FRAME48k ); ProcessIGF_ivas_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[ch][n], q_origSpec, &powerSpec_fx[ch][n * L_subframeTCX], &exp_powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); st->hTcxEnc->spectrum_e[n] = sub( 31, q_spectrum ); diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index 58ba680d6..0b0aa90c5 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -82,14 +82,16 @@ static void ivas_omasa_dmx_fx( Word16 prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], /*o:q15*/ const Word16 interpolator[L_FRAME48k] /*i:q15*/ ); + void computeIntensityVector_enc_fx( const Word16 *band_grouping, Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /*inp_q*/ Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /*inp_q*/ const Word16 num_frequency_bands, Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], /*exp: exp_intensity_real*/ - Word16 *exp_intensity_real, + Word16 q_intensity_real[MASA_FREQUENCY_BANDS], Word16 inp_q ); + static void computeReferencePower_omasa_ivas_fx( const Word16 *band_grouping, Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], Word32 *reference_power, const Word16 enc_param_start_band, const Word16 num_freq_bands, Word16 q_Cldfb, Word16 *ref_exp ); /*--------------------------------------------------------------------------* * ivas_omasa_enc_open() @@ -1037,6 +1039,7 @@ static void ivas_omasa_param_est_enc_fx( Word16 q; /*stores q for cldfb buffers*/ Word32 temp; Word16 temp_e; + Word16 q_intensity_real_fx[MASA_FREQUENCY_BANDS], q_reference_power_fx[CLDFB_NO_CHANNELS_MAX]; ref_exp = 0; norm_buff = MAX16B; @@ -1188,24 +1191,34 @@ static void ivas_omasa_param_est_enc_fx( v_multc_acc_32_32( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); /*q*/ } /* Direction estimation */ - norm_buff = L_norm_arr( &Foa_RealBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX ); - norm_buff = s_min( norm_buff, L_norm_arr( &Foa_ImagBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX ) ); - guard_bits = find_guarded_bits_fx( max_band_grouping_diff ); - guard_bits = add( guard_bits, sub( 1, norm_buff ) ); + computeIntensityVector_enc_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx, q_intensity_real_fx, q ); - scale_sig32( &Foa_RealBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX, negate( guard_bits ) ); - scale_sig32( &Foa_ImagBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX, negate( guard_bits ) ); + computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], 0, q_intensity_real_fx ); - q = sub( q, guard_bits ); + /* Power estimation for diffuseness */ - computeIntensityVector_enc_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx, &intensity_real_e, q ); + computeReferencePower_omasa_ivas_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx[ts], 0, num_freq_bands, q, q_reference_power_fx ); - computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], intensity_real_e, - NULL ); + minimum_fx( q_intensity_real_fx, num_freq_bands, &intensity_real_e ); + minimum_fx( q_reference_power_fx, num_freq_bands, &ref_exp ); - /* Power estimation for diffuseness */ + Word16 tmp; + FOR( i = 0; i < num_freq_bands; i++ ) + { + tmp = sub( intensity_real_e, q_intensity_real_fx[i] ); + intensity_real_fx[0][i] = L_shl( intensity_real_fx[0][i], tmp ); // intensity_real_e + move32(); + intensity_real_fx[1][i] = L_shl( intensity_real_fx[1][i], tmp ); // intensity_real_e + move32(); + intensity_real_fx[2][i] = L_shl( intensity_real_fx[2][i], tmp ); // intensity_real_e + move32(); + + tmp = sub( ref_exp, q_reference_power_fx[i] ); + reference_power_fx[ts][i] = L_shl( reference_power_fx[ts][i], tmp ); // ref_exp + } - computeReferencePower_omasa_ivas_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx[ts], 0, num_freq_bands, q, &ref_exp ); + intensity_real_e = sub( Q31, intensity_real_e ); + ref_exp = sub( Q31, ref_exp ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hOMasa->index_buffer_intensity = add( ( hOMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ), 1 ); /* averaging_length = 32 */ @@ -1489,15 +1502,13 @@ void computeIntensityVector_enc_fx( Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /*inp_q*/ const Word16 num_frequency_bands, Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS], /*exp: exp_intensity_real*/ - Word16 *exp_intensity_real, + Word16 q_intensity_real[MASA_FREQUENCY_BANDS], Word16 inp_q ) { Word16 i, j; Word32 real, img; - Word16 brange[2], shift = 63; - move16(); - Flag is_zero = 0; - move16(); + Word16 brange[2]; + Word16 shift_intensity_real, num_bins, guard_bits, norm; Word64 intensity_real64[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; @@ -1506,6 +1517,8 @@ void computeIntensityVector_enc_fx( set64_fx( intensity_real64[i], 0, MASA_FREQUENCY_BANDS ); } + shift_intensity_real = sub( shl( inp_q, 1 ), 32 ); + FOR( i = 0; i < num_frequency_bands; i++ ) { brange[0] = band_grouping[i]; @@ -1513,12 +1526,8 @@ void computeIntensityVector_enc_fx( brange[1] = band_grouping[i + 1]; move16(); - intensity_real[0][i] = 0; - move32(); - intensity_real[1][i] = 0; - move32(); - intensity_real[2][i] = 0; - move32(); + num_bins = sub( brange[1], brange[0] ); + guard_bits = find_guarded_bits_fx( num_bins ); FOR( j = brange[0]; j < brange[1]; j++ ) { @@ -1527,45 +1536,34 @@ void computeIntensityVector_enc_fx( img = Cldfb_ImagBuffer[0][j]; move32(); /* Intensity is XYZ order, audio is WYZX order. */ - intensity_real64[0][i] = W_add( intensity_real64[0][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[3][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q= 2* input_q + intensity_real64[0][i] = W_add( intensity_real64[0][i], W_shr( W_add( W_mult0_32_32( Cldfb_RealBuffer[3][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[3][j], img ) ), guard_bits ) ); // output Q= 2* input_q -guard_bits move64(); - intensity_real64[1][i] = W_add( intensity_real64[1][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[1][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q= 2* input_q + intensity_real64[1][i] = W_add( intensity_real64[1][i], W_shr( W_add( W_mult0_32_32( Cldfb_RealBuffer[1][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[1][j], img ) ), guard_bits ) ); // output Q= 2* input_q - guard_bits move64(); - intensity_real64[2][i] = W_add( intensity_real64[2][i], W_add( W_mult0_32_32( Cldfb_RealBuffer[2][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q= 2* input_q + intensity_real64[2][i] = W_add( intensity_real64[2][i], W_shr( W_add( W_mult0_32_32( Cldfb_RealBuffer[2][j], real ), W_mult0_32_32( Cldfb_ImagBuffer[2][j], img ) ), guard_bits ) ); // output Q= 2* input_q - guard_bits move64(); } - } - - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - is_zero = is_zero_arr64( intensity_real64[i], MASA_FREQUENCY_BANDS ); - IF( is_zero == 0 ) + norm = 63; + move16(); + IF( intensity_real64[0][i] != 0 ) { - BREAK; + norm = s_min( norm, W_norm( intensity_real64[0][i] ) ); } - } - IF( is_zero == 0 ) - { - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + IF( intensity_real64[1][i] != 0 ) { - shift = s_min( shift, W_norm_arr( intensity_real64[i], MASA_FREQUENCY_BANDS ) ); + norm = s_min( norm, W_norm( intensity_real64[1][i] ) ); } - - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + IF( intensity_real64[2][i] != 0 ) { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - intensity_real[i][j] = W_extract_h( W_shl( intensity_real64[i][j], shift ) ); - move32(); - } + norm = s_min( norm, W_norm( intensity_real64[2][i] ) ); } - - *exp_intensity_real = sub( 31, sub( add( shift, shl( inp_q, 1 ) ), 32 ) ); - move16(); - } - ELSE - { - *exp_intensity_real = 0; + intensity_real[0][i] = W_extract_h( W_shl( intensity_real64[0][i], norm ) ); // output Q = 2 * inp_q - guard_bits + norm - 32 + move32(); + intensity_real[1][i] = W_extract_h( W_shl( intensity_real64[1][i], norm ) ); // output Q = 2 * inp_q - guard_bits + norm - 32 + move32(); + intensity_real[2][i] = W_extract_h( W_shl( intensity_real64[2][i], norm ) ); // output Q = 2 * inp_q - guard_bits + norm - 32 + move32(); + q_intensity_real[i] = add( shift_intensity_real, sub( norm, guard_bits ) ); move16(); } @@ -1580,13 +1578,14 @@ static void computeReferencePower_omasa_ivas_fx( const Word16 enc_param_start_band, /* i : first band to process */ const Word16 num_freq_bands, /* i : Number of frequency bands */ Word16 q_Cldfb, - Word16 *ref_exp ) + Word16 q_reference_power[CLDFB_NO_CHANNELS_MAX] ) { Word16 brange[2]; Word16 ch_idx, i, j; Word64 reference_power_tmp[CLDFB_NO_CHANNELS_MAX]; - Word16 ref_Q = 63; - move16(); + Word16 shift_ref_power, num_bins, guard_bits, norm; + + shift_ref_power = sub( shl( q_Cldfb, 1 ), 30 ); FOR( i = 0; i < num_freq_bands; i++ ) { @@ -1599,34 +1598,29 @@ static void computeReferencePower_omasa_ivas_fx( reference_power_tmp[i] = 0; move64(); + num_bins = sub( brange[1], brange[0] ); + guard_bits = find_guarded_bits_fx( num_bins ); + FOR( ch_idx = 0; ch_idx < FOA_CHANNELS; ch_idx++ ) { /* abs()^2 */ FOR( j = brange[0]; j < brange[1]; j++ ) { - reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); // Q13 (Q6+Q6+1) + reference_power_tmp[i] = W_add( reference_power_tmp[i], W_shr( W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ), guard_bits ) ); // output Q = 2 * q_cldfb + 1 - guard_bits move64(); } } - } - // v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); - FOR( i = 0; i < num_freq_bands; i++ ) - { - reference_power_tmp[i] = W_shr( reference_power_tmp[i], 1 ); - move64(); - ref_Q = s_min( ref_Q, W_norm( reference_power_tmp[i] ) ); - } - - FOR( i = 0; i < num_freq_bands; i++ ) - { - reference_power_tmp[i] = W_shl( reference_power_tmp[i], ref_Q ); // Q13 + ref_Q - move64(); - reference_power[i] = W_extract_h( reference_power_tmp[i] ); // Q13 + ref_Q -32 + norm = 63; + move16(); + IF( reference_power_tmp[i] != 0 ) + { + norm = W_norm( reference_power_tmp[i] ); + } + reference_power[i] = W_extract_h( W_shl( reference_power_tmp[i], norm ) ); // output Q = 2 * q_cldfb + 2 - guard_bits + norm - 32 move32(); + q_reference_power[i] = add( shift_ref_power, sub( norm, guard_bits ) ); + move16(); } - // ref_exp = 31- ((13+ref_Q) -32) - *ref_exp = sub( 31, ( sub( add( ref_Q, 2 * q_Cldfb + 1 ), 32 ) ) ); - move16(); return; } diff --git a/lib_enc/ivas_stereo_mdct_core_enc_fx.c b/lib_enc/ivas_stereo_mdct_core_enc_fx.c index 2a71fc34d..6bb6af1b3 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_core_enc_fx.c @@ -577,9 +577,11 @@ void stereo_mdct_core_enc_fx( { IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS]; Word32 powerSpec_fx[CPE_CHANNELS][N_MAX], *p_powerSpec_fx[CPE_CHANNELS]; - Word16 exp_powSpec[CPE_CHANNELS]; + Word16 exp_powSpec[CPE_CHANNELS][N_MAX], *p_exp_powSpec[CPE_CHANNELS]; p_powerSpec_fx[0] = powerSpec_fx[0]; + p_exp_powSpec[0] = exp_powSpec[0]; p_powerSpec_fx[1] = powerSpec_fx[1]; + p_exp_powSpec[1] = exp_powSpec[1]; { /* Copy powerSpec values from 64 bit buffer to 32 bit buffer */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -598,24 +600,19 @@ void stereo_mdct_core_enc_fx( { length = add( length, shr( length, 2 ) ); } - exp = sub( exp_powerSpec64[ch][0], W_norm_arr( powerSpec64[ch], length ) ); - IF( EQ_16( nsub, 2 ) ) - { - exp = s_max( exp, sub( exp_powerSpec64[ch][1], W_norm_arr( powerSpec64[ch] + length, length ) ) ); - } FOR( n1 = 0; n1 < nsub; n1++ ) { - shift1 = sub( sub( exp_powerSpec64[ch][n1], exp ), 32 ); FOR( i = 0; i < length; i++ ) { /* This doesn't result in saturation */ - powerSpec_fx[ch][i + n1 * length] = W_shl_sat_l( powerSpec64[ch][i + n1 * length], shift1 ); // exp: exp + shift1 = W_norm( powerSpec64[ch][i + n1 * length] ); + powerSpec_fx[ch][i + n1 * length] = W_extract_h( W_shl( powerSpec64[ch][i + n1 * length], shift1 ) ); // exp: exp move32(); + exp_powSpec[ch][i + n1 * length] = sub( exp_powerSpec64[ch][n1], shift1 ); } } set32_fx( powerSpec_fx[ch] + length, 0, sub( N_MAX, length ) ); - exp_powSpec[ch] = exp; // exp: exp - move16(); + set16_fx( exp_powSpec[ch] + length, 0, sub( N_MAX, length ) ); } } @@ -627,13 +624,13 @@ void stereo_mdct_core_enc_fx( move16(); ProcessStereoIGF_fx( hStereoMdct, sts, ms_mask, orig_spectrum_fx, sub( Q31, p_orig_spectrum_e[0] ), sub( Q31, p_orig_spectrum_e[1] ), - p_powerSpec_fx, exp_powSpec, powerSpecMsInv_fx, q_powerSpecMsInv_fx, inv_spectrum_fx, exp_inv_spectrum, + p_powerSpec_fx, p_exp_powSpec, powerSpecMsInv_fx, q_powerSpecMsInv_fx, inv_spectrum_fx, exp_inv_spectrum, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate, 0 ); } ELSE { Word32 powerSpec_fx[CPE_CHANNELS][N_MAX]; // each value has a different exponent - Word16 exp_powerSpec[CPE_CHANNELS][N_MAX + L_MDCT_OVLP_MAX]; + Word16 exp_powerSpec[CPE_CHANNELS][N_MAX]; { /* Copy powerSpec values from 64 bit buffer to 32 bit buffer */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -665,7 +662,7 @@ void stereo_mdct_core_enc_fx( } } set32_fx( powerSpec_fx[ch] + length, 0, sub( N_MAX, length ) ); - set16_fx( exp_powerSpec[ch] + length, 0, sub( N_MAX + L_MDCT_OVLP_MAX, length ) ); + set16_fx( exp_powerSpec[ch] + length, 0, sub( N_MAX, length ) ); } } FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index c433dcb2c..75f318151 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3041,6 +3041,13 @@ Word16 IGF_getCrest( /**< out: Q15| crest factor const Word16 start, /**< in: Q0 | start subband index */ const Word16 stop /**< in: Q0 | stop subband index */ ); +Word16 IGF_getCrest_ivas( /**< out: Q15| crest factor */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ +); Word16 IGF_getSFM( /**< out: Q15| SFM value */ Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ const Word32 *energy, /**< in: Q31| energies */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 680a69fa5..f8f6f5fac 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -4030,7 +4030,7 @@ void ProcessStereoIGF_fx( Word16 q_pITFMDCTSpectrum_1, Word16 q_pITFMDCTSpectrum_2, Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ -- GitLab From f4b38f0289b69ce443a3cd4c572520b757da1470 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 11 Jun 2025 10:26:51 +0530 Subject: [PATCH 43/54] Clang formatting changes --- lib_com/prot_fx.h | 4 ++-- lib_com/stat_com.h | 12 ++++++------ lib_enc/igf_enc.c | 2 +- lib_enc/igf_enc_fx.c | 14 +++++++------- lib_enc/ivas_mct_enc_mct_fx.c | 2 +- lib_enc/prot_fx_enc.h | 12 ++++++------ lib_enc/tcx_utils_enc_fx.c | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 38a6077e8..ec2aec450 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10502,7 +10502,7 @@ void ProcessStereoIGF_fx( Word16 q_pITFMDCTSpectrum_1, Word16 q_pITFMDCTSpectrum_2, Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ @@ -10519,7 +10519,7 @@ void IGFEncApplyStereo_fx( const Word16 igfGridIdx, /* i : IGF grid index */ Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 712c1d702..e5081d2be 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -558,12 +558,12 @@ typedef struct ParamsBitMap struct TnsParameters { /* Parameters for each TNS filter */ - Word16 startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ - Word16 nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ - Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ - Word32 minPredictionGain_32; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ - Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ - Word16 minEnergyChange; /* Minimum energy change required to turn on the TNS filter. Exponent = 8 */ + Word16 startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ + Word16 nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ + Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ + Word32 minPredictionGain_32; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ + Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ + Word16 minEnergyChange; /* Minimum energy change required to turn on the TNS filter. Exponent = 8 */ }; /**********************************************/ diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index db77144df..70b5166df 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -2476,7 +2476,7 @@ void IGFEncApplyMono_ivas_fx( Word32 common_pPowerSpectrum_fx[N_MAX + L_MDCT_OVLP_MAX]; - set32_fx( common_pPowerSpectrum_fx, 0, N_MAX); + set32_fx( common_pPowerSpectrum_fx, 0, N_MAX ); Word16 common_pPowerSpectrum_exp = MIN16B; move16(); diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 2befbe8ba..a7b5eabb3 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -781,12 +781,12 @@ Word16 IGF_getCrest( /**< ou return crest; } -Word16 IGF_getCrest_ivas( /**< out: Q15| crest factor */ - Word16 *crest_exp, /**< out: | exponent of crest factor */ - const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ - const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +Word16 IGF_getCrest_ivas( /**< out: Q15| crest factor */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ ) { Word16 i; @@ -813,7 +813,7 @@ Word16 IGF_getCrest_ivas( /* /*see IGF_getSFM for more comment */ x = sub( sub( powerSpectrum_exp[i], norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ - if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ + if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ { x = 0; move16(); diff --git a/lib_enc/ivas_mct_enc_mct_fx.c b/lib_enc/ivas_mct_enc_mct_fx.c index 8acbd42fc..f28adafa4 100644 --- a/lib_enc/ivas_mct_enc_mct_fx.c +++ b/lib_enc/ivas_mct_enc_mct_fx.c @@ -1042,7 +1042,7 @@ void mctStereoIGF_enc_fx( sts[ch2]->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; } - p_powerSpec_fx[0] = powerSpec_fx[ch1]; // q_powerSpec + p_powerSpec_fx[0] = powerSpec_fx[ch1]; // q_powerSpec p_exp_powerSpec_fx[0] = exp_powerSpec[ch1]; // q_powerSpec p_powerSpec_fx[1] = powerSpec_fx[ch2]; p_exp_powerSpec_fx[1] = exp_powerSpec[ch2]; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 75f318151..6ef6991d4 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3041,12 +3041,12 @@ Word16 IGF_getCrest( /**< out: Q15| crest factor const Word16 start, /**< in: Q0 | start subband index */ const Word16 stop /**< in: Q0 | stop subband index */ ); -Word16 IGF_getCrest_ivas( /**< out: Q15| crest factor */ - Word16 *crest_exp, /**< out: | exponent of crest factor */ - const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ - const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +Word16 IGF_getCrest_ivas( /**< out: Q15| crest factor */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ ); Word16 IGF_getSFM( /**< out: Q15| SFM value */ Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index f8f6f5fac..e1b067ac3 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -4030,7 +4030,7 @@ void ProcessStereoIGF_fx( Word16 q_pITFMDCTSpectrum_1, Word16 q_pITFMDCTSpectrum_2, Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word16 *exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ -- GitLab From eb2cb6cfd72389bd3d787c63b8d13b0e453241d8 Mon Sep 17 00:00:00 2001 From: malenov Date: Wed, 11 Jun 2025 12:43:35 +0200 Subject: [PATCH 44/54] fix missing pop_wmops() --- lib_rend/lib_rend_fx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index e92922964..b46d13610 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -5715,6 +5715,9 @@ static ivas_error renderLfeToBinaural_fx( ELSE { /* no LFE to render */ +#ifdef FIX_1740_MISING_POP_WMOPS + pop_wmops(); +#endif return IVAS_ERR_OK; } -- GitLab From 131aedf4654587a27ab2e4ca651a62c150ebf55b Mon Sep 17 00:00:00 2001 From: malenov Date: Wed, 11 Jun 2025 12:49:50 +0200 Subject: [PATCH 45/54] fix missing pop_wmops() --- lib_rend/lib_rend_fx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index e92922964..b46d13610 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -5715,6 +5715,9 @@ static ivas_error renderLfeToBinaural_fx( ELSE { /* no LFE to render */ +#ifdef FIX_1740_MISING_POP_WMOPS + pop_wmops(); +#endif return IVAS_ERR_OK; } -- GitLab From 5ef310e6bd42d9ee925174f08ac1c90d500ba2f7 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 12 Jun 2025 08:37:35 +0200 Subject: [PATCH 46/54] Update IVAS_CODEC_CI_REF to get HRTF model file restoration update --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index df6069de2..59d11a2e9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: # note: GitLab cannot reference variables defined by users in the include ref:, we need to use a YAML anchor for this # see https://docs.gitlab.com/ci/yaml/includes/#use-variables-with-include for more information - IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF 44cb5638949b874ce0f5c3bf4359f9db860d88bc + IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF 41186736915f5c0a857ac92e8ab438c434e5247d include: - local: .gitlab-ci/variables.yml -- GitLab From 30acb8787ed053fdb43503b773896b91ee343f74 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 12 Jun 2025 15:18:30 +0530 Subject: [PATCH 47/54] Fix for 3GPP issue 950: High MLD for ParamMC 5.1 at 48/64/80kbps or 7.1+4 at 128kbps Link #950, #1023, #1024 --- lib_dec/ivas_jbm_dec_fx.c | 7 +++++++ lib_dec/ivas_mc_param_dec_fx.c | 13 ++++++++----- lib_dec/ivas_stat_dec.h | 2 +- lib_rend/ivas_dirac_decorr_dec_fx.c | 6 ++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index 3f67962dc..6b5023a70 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -4032,6 +4032,13 @@ void ivas_jbm_dec_copy_tc_no_tsm_fx( &cldfb_real_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands], &cldfb_imag_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands], num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch], &Q_tc ); + IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) ) + { + st_ivas->hParamMC->Cldfb_RealBuffer_tc_e = sub( 31, Q_tc ); + st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e = sub( 31, Q_tc ); + move16(); + move16(); + } } } } diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index 0e2de6c01..f1bbec638 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -106,7 +106,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, cons static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY ); -static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const Word16 num_freq_bands /*, Word16 RealBuffer_fx_e, Word16 ImagBuffer_fx_e, Word16 *common_e*/ ); +static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const Word16 num_freq_bands, Word16 Cldfb_Real_Imag_exp, Word16 *proto_frame_f_fx_q /* Word16 ImagBuffer_fx_e, Word16 *common_e*/ ); /*------------------------------------------------------------------------- * ivas_param_mc_dec_open() @@ -1983,7 +1983,7 @@ void ivas_param_mc_dec_render_fx( param_mc_protoSignalComputation_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], hParamMC->proto_frame_f_fx, hParamMC->diff_proto_info, - hParamMC->num_freq_bands ); + hParamMC->num_freq_bands, hParamMC->Cldfb_RealBuffer_tc_e, &hParamMC->proto_frame_f_fx_q ); /*-----------------------------------------------------------------* * frequency domain decorrelation *-----------------------------------------------------------------*/ @@ -1995,7 +1995,7 @@ void ivas_param_mc_dec_render_fx( DIRAC_SYNTHESIS_COV_MC_LS, nchan_transport, hParamMC->proto_frame_f_fx, - Q5, + hParamMC->proto_frame_f_fx_q, hParamMC->diff_proto_info->num_protos_diff, hParamMC->diff_proto_info->proto_index_diff, hParamMC->proto_frame_dec_f_fx, // output @@ -2321,8 +2321,9 @@ static void param_mc_protoSignalComputation_fx( Word32 *ImagBuffer_fx, /* i : CLDFB samples of the transport channels (imaginary part) */ Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */ const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */ - const Word16 num_freq_bands /* i : number of frequency bands for the prototypes */ -) + const Word16 num_freq_bands, /* i : number of frequency bands for the prototypes */ + const Word16 Cldfb_Real_Imag_exp, /*i: Exponent of real and imag buffers */ + Word16 *proto_frame_f_fx_q ) { Word16 band; Word16 proto_ch_idx, source_ch_cnt; @@ -2367,6 +2368,8 @@ static void param_mc_protoSignalComputation_fx( move32(); p_proto_frame_fx++; } + *proto_frame_f_fx_q = sub( 30, Cldfb_Real_Imag_exp ); + move16(); } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 891be05be..4eb40f337 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -573,7 +573,7 @@ typedef struct ivas_param_mc_dec_data_structure Word32 *proto_matrix_int_fx; Word16 proto_matrix_int_len; Word16 proto_matrix_int_e; - + Word16 proto_frame_f_fx_q; /*sub-modules*/ HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params; HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state; diff --git a/lib_rend/ivas_dirac_decorr_dec_fx.c b/lib_rend/ivas_dirac_decorr_dec_fx.c index 9b2bf02d7..aa4aed84c 100644 --- a/lib_rend/ivas_dirac_decorr_dec_fx.c +++ b/lib_rend/ivas_dirac_decorr_dec_fx.c @@ -482,6 +482,7 @@ void ivas_dirac_dec_decorr_process_fx( q_shift = 0; move16(); } + set32_fx( aux_buffer_fx, 0, 2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX ); FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { v_shr( &input_frame_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], negate( q_shift ), &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], imult1616( 2, num_freq_bands ) ); // Q - q_shift @@ -496,6 +497,11 @@ void ivas_dirac_dec_decorr_process_fx( { v_add_inc_fx( &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) )], 2, &aux_buffer_fx[add( imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) ), 1 )], 2, &aux_buffer_fx[imult1616( ch_idx, max_band_decorr_temp )], 1, max_band_decorr_temp ); // q_aux_buffer } + if ( is_zero_arr( aux_buffer_fx, 2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX ) ) + { + q_aux_buffer = 31; + move16(); + } /* compute onset filter */ max_band_decorr = h_freq_domain_decorr_ap_params->max_band_decorr; move16(); -- GitLab From a1a5235b6e35314ad21b6d9cbce4370e60b56e26 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 12 Jun 2025 17:28:11 +0530 Subject: [PATCH 48/54] Clang formatting changes --- lib_dec/ivas_mc_param_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index f1bbec638..b6868dbb1 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -2322,7 +2322,7 @@ static void param_mc_protoSignalComputation_fx( Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */ const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */ const Word16 num_freq_bands, /* i : number of frequency bands for the prototypes */ - const Word16 Cldfb_Real_Imag_exp, /*i: Exponent of real and imag buffers */ + const Word16 Cldfb_Real_Imag_exp, /*i: Exponent of real and imag buffers */ Word16 *proto_frame_f_fx_q ) { Word16 band; -- GitLab From d5bf98b49cae75aa0356d6088c3367a19753b3b2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 12 Jun 2025 14:23:20 +0530 Subject: [PATCH 49/54] Fix for 3GPP issue 1512: Decoder 160 kbit/s 7.1+4: Binaural Rendering introduces bigger differences Link #1512 --- lib_dec/dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 883024002..b9084df88 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -5137,7 +5137,7 @@ void decoder_tcx_imdct_fx( } } - ITF_Detect_fx( x_fx + IGF_START_MN, startLine, endLine, 8 /*maxOrder*/, A_itf_fx, &q_a_itf, &predictionGain_fx, &curr_order, shl( x_e, 1 ) ); + ITF_Detect_ivas_fx( x_fx + IGF_START_MN, startLine, endLine, 8 /*maxOrder*/, A_itf_fx, &q_a_itf, &predictionGain_fx, &curr_order, q_x ); ITF_Apply_fx( x_fx, startLine, endLine, A_itf_fx, q_a_itf, curr_order ); -- GitLab From 9a4a10bade86fc7cf6a8bdb9ce8e71766b558378 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 13 Jun 2025 14:32:22 +0530 Subject: [PATCH 50/54] Fix for 3GPP issue 1593: Somewhat high MLD in BASOP decoder for McMASA with rate switching and FER Link #1593 --- lib_com/pred_lt4_fx.c | 57 ++++++++++++++++++++++++++++++ lib_com/prot_fx.h | 10 ++++++ lib_com/rom_com.c | 12 +++++++ lib_com/rom_com.h | 3 +- lib_dec/LD_music_post_filter_fx.c | 9 ++++- lib_dec/acelp_core_switch_dec_fx.c | 21 ++++++++--- lib_dec/dec_gen_voic_fx.c | 10 ++++-- lib_dec/dec_pit_exc_fx.c | 10 ++++-- lib_dec/ivas_td_low_rate_dec_fx.c | 10 ++++-- lib_dec/transition_dec_fx.c | 54 ++++++++++++++++++++++++---- 10 files changed, 177 insertions(+), 19 deletions(-) diff --git a/lib_com/pred_lt4_fx.c b/lib_com/pred_lt4_fx.c index 4f8dd8712..465138bde 100644 --- a/lib_com/pred_lt4_fx.c +++ b/lib_com/pred_lt4_fx.c @@ -20,6 +20,63 @@ * (adaptive codebook excitation) * *-------------------------------------------------------------------*/ +void pred_lt4_ivas_fx( + const Word16 excI[], /* in : excitation buffer Q_exc*/ + Word16 excO[], /* out: excitation buffer Q_exc*/ + const Word16 T0, /* input : integer pitch lag Q0*/ + Word16 frac, /* input : fraction of lag Q0*/ + const Word16 L_subfr, /* input : subframe size Q0*/ + const Word32 *win, /* i : interpolation window Q31*/ + const Word16 nb_coef, /* i : nb of filter coef Q0*/ + const Word16 up_sample /* i : up_sample Q0*/ +) +{ + Word16 i, j; + Word32 s; + const Word16 *x0, *x1, *x2; + const Word32 *c1, *c2; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + x0 = &excI[-T0]; + + frac = negate( frac ); + + IF( frac < 0 ) + { + frac = add( frac, up_sample ); /* Q0 */ + x0--; + } + + FOR( j = 0; j < L_subfr; j++ ) + { + x1 = x0++; /* Q_exc */ + x2 = x1 + 1; /* Q_exc */ + c1 = ( &win[frac] ); /* Q14 */ + c2 = ( &win[up_sample - frac] ); /* Q14 */ + + { + Word64 s64 = 0; + move64(); + FOR( i = 0; i < nb_coef; i++ ) + { + /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/ + s64 = W_mac_32_32( s64, L_deposit_l( *x1-- ), ( *c1 ) ); /* Q_exc + Q32 */ + s64 = W_mac_32_32( s64, L_deposit_l( *x2++ ), ( *c2 ) ); /* Q_exc + Q32 */ + + c1 += up_sample; + c2 += up_sample; + } + s = W_sat_l( W_shr( s64, 16 ) ); /* Q_exc + Q16 */ + } + + excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */ + move16(); + } + return; +} + void pred_lt4( const Word16 excI[], /* in : excitation buffer Q_exc*/ Word16 excO[], /* out: excitation buffer Q_exc*/ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ec2aec450..d533c5612 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7183,6 +7183,16 @@ void pred_lt4( const Word16 up_sample /* i : up_sample Q0*/ ); +void pred_lt4_ivas_fx( + const Word16 excI[], /* in : excitation buffer Q_exc*/ + Word16 excO[], /* out: excitation buffer Q_exc*/ + const Word16 T0, /* input : integer pitch lag Q0*/ + Word16 frac, /* input : fraction of lag Q0*/ + const Word16 L_subfr, /* input : subframe size Q0*/ + const Word32 *win, /* i : interpolation window Q31*/ + const Word16 nb_coef, /* i : nb of filter coef Q0*/ + const Word16 up_sample /* i : up_sample Q0*/ +); void pred_lt4_tc_fx( Word16 exc[], /* i/o: excitation buffer Q0*/ diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 9eaf690f1..5d0a7f303 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -1332,6 +1332,18 @@ const Word16 inter4_2_fx[] = }; /* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) */ +const Word32 L_pitch_inter4_2[PIT_FIR_SIZE2] = { /* Q31 */ + 2018634624, 1839083520, 1357785216, 724904576, 126856152, -281447072, + -428193216, -340524320, -121030032, 102233104, 229241728, 222704784, + 111802296, -32603096, -136805440, -158183648, -99851544, -2110976, + 82091856, 114123720, 86026048, 19988778, -46544560, -81104016, + -71266392, -27977416, 22982370, 55621972, 56517476, 29680372, + -7827578, -36105644, -42638288, -27414776, -1138166, 21646636, + 30326764, 22885734, 5570572, -11516955, -20066088, -17396766, + -6833293, 5003637, 12101070, 11944304, 6107443, -1346472, -6427418, + -7219840, -4389456, -249108, 2823941, 3633542, 2471753, 556198, + -895500, -1327144, -932007, -285615, 135291, 210453, 103079, 15032, 0 +}; const Word16 pitch_inter4_2[PIT_FIR_SIZE2] = { /* cut-off frequency at 0.94*fs/2 */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 73156b989..a87ee8d0d 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -175,7 +175,8 @@ extern const Word16 fft256_read_indexes[]; /* FFT Q0*/ extern const Word16 inter4_2_fx_Q15[]; // Q15 /* 1/4 resolution interpolation filter */ extern const Word16 inter4_2_fx[]; extern const Word16 pitch_inter4_1[UP_SAMP * L_INTERPOL1 + 1]; /*1Q14*/ -extern const Word16 pitch_inter4_2[PIT_FIR_SIZE2]; /*1Q14*/ +extern const Word16 pitch_inter4_2[PIT_FIR_SIZE2]; /*Q15*/ +extern const Word32 L_pitch_inter4_2[PIT_FIR_SIZE2]; /*Q31*/ extern const Word16 Assym_window_W16fx[]; // Q15 extern const Word16 assym_window_16k_fx[]; // Q15 extern const Word16 grid50_fx[( GRID50_POINTS - 1 ) / 2 - 1]; // Q15 diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index 5b48ab472..12a13a4ec 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -832,7 +832,14 @@ void Prep_music_postP_fx( * Extrapolation of the last future part and windowing *------------------------------------------------------------*/ pt1 = exc_buffer_in + DCT_L_POST - OFFSET2; /*Q_exc*/ - pred_lt4( pt1, pt1, s_pit, fr_pit, OFFSET2, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( pt1, pt1, s_pit, fr_pit, OFFSET2, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( pt1, pt1, s_pit, fr_pit, OFFSET2, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } /*------------------------------------------------------------* * windowing right side *------------------------------------------------------------*/ diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 363db8202..b12682385 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -921,9 +921,14 @@ static void decod_gen_voic_core_switch_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector. *--------------------------------------------------------------*/ - - pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ @@ -991,8 +996,14 @@ static void decod_gen_voic_core_switch_fx( /*-----------------------------------------------------------------* * long term prediction on the 2nd sub frame *-----------------------------------------------------------------*/ - - pred_lt4( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } pt1 = exc + L_SUBFR; FOR( i = 0; i < L_SUBFR; i++ ) diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index b9f488942..14d9d1772 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -166,8 +166,14 @@ ivas_error decod_gen_voic_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index a18029cdc..ca6660fab 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -182,8 +182,14 @@ void dec_pit_exc_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector. *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } /*--------------------------------------------------------------* * Innovation decoding diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index f48d3fabc..fb984f11f 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -278,8 +278,14 @@ void decod_gen_2sbfr_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ - - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, inter4_2_fx_Q15, L_INTERPOL2, PIT_UP_SAMP ); + IF( st->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } /*--------------------------------------------------------------* * LP filtering of the adaptive excitation diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index b9ad17fcf..102a81b9d 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -209,7 +209,14 @@ void transition_dec_fx( limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max */ /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); @@ -239,7 +246,14 @@ void transition_dec_fx( limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max */ /* Find the adaptive codebook vector. ACELP long-term prediction */ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); move16(); /* penality for 2 ptrs initialization */ @@ -308,7 +322,14 @@ void transition_dec_fx( } /* Find the adaptive codebook vector. ACELP long-term prediction */ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); move16(); /* penality for 2 ptrs initialization */ @@ -330,7 +351,14 @@ void transition_dec_fx( delta_pit_dec_fx( 2, index, T0, T0_frac, *T0_min ); /* Find the adaptive codebook vector. ACELP long-term prediction */ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); move16(); /* penality for 2 ptrs initialization */ @@ -351,7 +379,14 @@ void transition_dec_fx( pit_Q_dec_fx( 0, index, nBits, 8, pit_flag, limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); /* Find the adaptive codebook vector */ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); move16(); /* penality for 2 ptrs initialization */ @@ -544,7 +579,14 @@ void transition_dec_fx( ELSE { /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode != EVS_MONO ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, L_frame ); move16(); move16(); /* penalty for 2 ptrs initialization */ -- GitLab From e1ce3fb898faed74c4001636436e7b89e6bb88bb Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 13 Jun 2025 18:29:27 +0530 Subject: [PATCH 51/54] Crash fix for [Multi-channel 7_1_4 bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, HOA3 out] fxd enc fxd dec case and warning fix --- lib_dec/ivas_mc_param_dec_fx.c | 2 +- lib_dec/ivas_sba_rendering_internal_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index b6868dbb1..c25ec972f 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -106,7 +106,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, cons static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY ); -static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const Word16 num_freq_bands, Word16 Cldfb_Real_Imag_exp, Word16 *proto_frame_f_fx_q /* Word16 ImagBuffer_fx_e, Word16 *common_e*/ ); +static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const Word16 num_freq_bands, const Word16 Cldfb_Real_Imag_exp, Word16 *proto_frame_f_fx_q /* Word16 ImagBuffer_fx_e, Word16 *common_e*/ ); /*------------------------------------------------------------------------- * ivas_param_mc_dec_open() diff --git a/lib_dec/ivas_sba_rendering_internal_fx.c b/lib_dec/ivas_sba_rendering_internal_fx.c index d9ee47c84..5a15a357e 100644 --- a/lib_dec/ivas_sba_rendering_internal_fx.c +++ b/lib_dec/ivas_sba_rendering_internal_fx.c @@ -211,7 +211,7 @@ void ivas_mc2sba_fx( FOR( k = 0; k < output_frame; k++ ) { #ifdef OPT_BIN_RENDERER_V2 - buffer_tmp_fx[j][k] = Madd_32_32( buffer_tmp_fx[j][k], L_shl( in_buffer_td_fx[i][k], 2 ), gains_fx[j] ); /*Q+29-31+2==Q*/ + buffer_tmp_fx[j][k] = Madd_32_32( buffer_tmp_fx[j][k], L_shl_sat( in_buffer_td_fx[i][k], 2 ), gains_fx[j] ); /*Q+29-31+2==Q*/ #else /* OPT_BIN_RENDERER_V2 */ buffer_tmp_fx[j][k] = L_add( buffer_tmp_fx[j][k], L_shl( Mult_32_32( in_buffer_td_fx[i][k], gains_fx[j] ), 2 ) ); /*Q+29-31+2==Q*/ #endif /* OPT_BIN_RENDERER_V2 */ -- GitLab From 79ae9a3cc39dc5e5be2cd87faae4be74ccf0b8b3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 13 Jun 2025 18:34:27 +0530 Subject: [PATCH 52/54] Clang formatting changes --- lib_dec/ivas_sba_rendering_internal_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_sba_rendering_internal_fx.c b/lib_dec/ivas_sba_rendering_internal_fx.c index 5a15a357e..ba8c529d7 100644 --- a/lib_dec/ivas_sba_rendering_internal_fx.c +++ b/lib_dec/ivas_sba_rendering_internal_fx.c @@ -212,9 +212,9 @@ void ivas_mc2sba_fx( { #ifdef OPT_BIN_RENDERER_V2 buffer_tmp_fx[j][k] = Madd_32_32( buffer_tmp_fx[j][k], L_shl_sat( in_buffer_td_fx[i][k], 2 ), gains_fx[j] ); /*Q+29-31+2==Q*/ -#else /* OPT_BIN_RENDERER_V2 */ +#else /* OPT_BIN_RENDERER_V2 */ buffer_tmp_fx[j][k] = L_add( buffer_tmp_fx[j][k], L_shl( Mult_32_32( in_buffer_td_fx[i][k], gains_fx[j] ), 2 ) ); /*Q+29-31+2==Q*/ -#endif /* OPT_BIN_RENDERER_V2 */ +#endif /* OPT_BIN_RENDERER_V2 */ move32(); } } -- GitLab From 734b270395cda470643392d1ebabc9a7511fc97b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 13 Jun 2025 18:36:00 +0530 Subject: [PATCH 53/54] Bug fix --- lib_enc/cod4t64_fast_fx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib_enc/cod4t64_fast_fx.c b/lib_enc/cod4t64_fast_fx.c index e24f3b678..7079f6597 100644 --- a/lib_enc/cod4t64_fast_fx.c +++ b/lib_enc/cod4t64_fast_fx.c @@ -145,7 +145,8 @@ void acelp_fast_fx( Word16 track_order[NB_TRACK_FCB_4T * MAX_NUM_INTER], m0_track[NB_TRACK_FCB_4T]; Word16 ind_stream[NPMAXPT * NB_TRACK_FCB_4T], idx; Word16 G, G1, G2, G3, Gn, Gd; - Word32 Gd32; + Word32 Gd32 = 0; + move32(); Word16 y_tmp[L_SUBFR_MAX]; Word32 dn[L_SUBFR_MAX]; Word32 crit_num, crit_den, crit_num_max, crit_den_max, L_tmp1, L_tmp2; @@ -718,8 +719,6 @@ void acelp_fast_fx( IF( GE_16( nb_pulse, 4 ) ) { Gn = add( Gn, i_mult( s[2], dn_orig[m[2]] ) ); // Q_dn - Gd32 = Gd; - move16(); temp1 = alp[0]; move32(); temp2 = L_mult0( i_mult( shl( s[0], 1 ), s[2] ), alp[m[0] - m[2]] ); @@ -770,8 +769,6 @@ void acelp_fast_fx( IF( GE_16( nb_pulse, 5 ) ) { Gn = add( Gn, i_mult( s[3], dn_orig[m[3]] ) ); // Q_dn - Gd32 = Gd; - move16(); temp1 = alp[0]; move32(); temp2 = L_mult0( i_mult( shl( s[0], 1 ), s[3] ), alp[m[0] - m[3]] ); -- GitLab From fca13dbc7f379ce2301e365145ec40efd46ab443 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Wed, 16 Jul 2025 12:10:12 +0200 Subject: [PATCH 54/54] apply clang-format --- lib_dec/ivas_dirac_dec_fx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index 0337643f0..3ffcde306 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -1883,8 +1883,8 @@ void ivas_qmetadata_to_dirac_fx( } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) @@ -3940,8 +3940,8 @@ void ivas_dirac_dec_render_sf_fx( const Word32 azi_fx = L_shl( az1_32, Q22 - Q16 ); // Q16 -> Q22 const Word32 ele_fx = L_shl( el1_32, Q22 - Q16 ); // Q16 -> Q22 #else - const Word32 azi_fx = L_shl( az1, Q22 ); // Q0 -> Q22 - const Word32 ele_fx = L_shl( el1, Q22 ); // Q0 -> Q22 + const Word32 azi_fx = L_shl( az1, Q22 ); // Q0 -> Q22 + const Word32 ele_fx = L_shl( el1, Q22 ); // Q0 -> Q22 #endif efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azi_fx, ele_fx, EFAP_MODE_EFAP ); } -- GitLab