From 7c72b652b56ed8d7b61e854684a4b893c1fca865 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 22 Jan 2026 09:19:06 -0500 Subject: [PATCH 1/3] harmonisation of mult_harm --- lib_com/options.h | 1 + lib_enc/ivas_front_vad_fx.c | 4 + lib_enc/multi_harm_fx.c | 151 ++++++++++++++++++++++++++---------- lib_enc/nois_est_fx.c | 10 +++ lib_enc/prot_fx_enc.h | 5 ++ 5 files changed, 129 insertions(+), 42 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index b38e1d635..f4a802d2a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -101,6 +101,7 @@ #define FIX_BASOP_2332_ASAN_OVERFLOW_IN_EXT_DIRAC_REND /* Nokia: basop issue 2332: Uses predefined memory sizes instead computing wrong */ #define FIX_BASOP_2333_MCMASA_ANA_MEMORY_LEAK /* Nokia: basop issue 2333: Add missing free for direction_vector_e to ivas_mcmasa_ana_fx.c */ #define HARM_COREDECODER_FUNCTIONS /* VA: basop issue 2347: Remove various duplicated code in core-decoder */ +#define FIX_2364_HARM_MULT_HARM /* VA: basop issue 2364 : harmonizing multi_harm_fx function */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index bab92da6e..ba7c84a16 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -698,7 +698,11 @@ ivas_error front_vad_spar_fx( { cor_strong_limit = &dummy_int; } +#ifndef FIX_2364_HARM_MULT_HARM loc_harm = multi_harm_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */ +#else + loc_harm = multi_harm_fx( EVS_MONO, st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */ +#endif } scale = getScaleFactor32( epsP_fx, M + 1 ); diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 76b465777..07a80bb85 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -22,7 +22,9 @@ /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_fx( - +#ifdef FIX_2364_HARM_MULT_HARM + const Word16 element_mode, /* i : IVAS element_mode Q0 */ +#endif const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ @@ -43,7 +45,9 @@ Word16 multi_harm_fx( Word32 L_acc; Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum; Word16 mean_dyn; - +#ifdef FIX_2364_HARM_MULT_HARM + Word32 tmp2_32; +#endif /*------------------------------------------------------------------* * initialization *------------------------------------------------------------------*/ @@ -120,35 +124,65 @@ Word16 multi_harm_fx( move16(); step = 0; move16(); - - FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ ) +#ifdef FIX_2364_HARM_MULT_HARM + IF( element_mode != EVS_MONO ) { - /* we are at the end of the next minimum */ - IF( EQ_16( i, *pt_mins ) ) + FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ ) { - pt_mins++; - flor = Bin_E[i]; - move16(); /*Q7*/ - /* calculate the new step */ - /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ - tmp16 = sub( *pt_mins, i ); - tmpdB = sub( Bin_E[*pt_mins], Bin_E[i] ); - sign_fx = shr( tmpdB, 15 ); /* 0 if positive else -1 */ - ExpdB = sub( norm_s( tmpdB ), 1 ); - tmpdB = abs_s( shl( tmpdB, ExpdB ) ); - ExpInd = norm_s( tmp16 ); - tmp16 = shl( tmp16, ExpInd ); - tmp16 = div_s( tmpdB, tmp16 ); - tmp16 = sub( s_xor( tmp16, sign_fx ), sign_fx ); - step = shr( tmp16, add( sub( ExpdB, ExpInd ), 15 ) ); /* Q7 */ + /* we are at the end of the next minimum */ + IF( EQ_16( i, *pt_mins ) ) + { + pt_mins++; + flor = Bin_E[i]; + move16(); /*Q7*/ + + /* calculate the new step */ + /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ + + tmp16 = div_s( 1, sub( *pt_mins, i ) ); // Q15 + step = msu_r( L_mult( Bin_E[*pt_mins], tmp16 ), Bin_E[i], tmp16 ); // Q7 (15+7+1-16) + } + + /* subtract the floor */ + S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 ); + move16(); + + /* update the floor */ + flor = add( flor, step ); /*Q7*/ } + } + ELSE +#endif + { + FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ ) + { + /* we are at the end of the next minimum */ + IF( EQ_16( i, *pt_mins ) ) + { + pt_mins++; + flor = Bin_E[i]; + move16(); /*Q7*/ + /* calculate the new step */ + /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ + tmp16 = sub( *pt_mins, i ); + tmpdB = sub( Bin_E[*pt_mins], Bin_E[i] ); + sign_fx = shr( tmpdB, 15 ); /* 0 if positive else -1 */ + ExpdB = sub( norm_s( tmpdB ), 1 ); + tmpdB = abs_s( shl( tmpdB, ExpdB ) ); + ExpInd = norm_s( tmp16 ); + tmp16 = shl( tmp16, ExpInd ); + tmp16 = div_s( tmpdB, tmp16 ); + tmp16 = sub( s_xor( tmp16, sign_fx ), sign_fx ); + step = shr( tmp16, add( sub( ExpdB, ExpInd ), 15 ) ); /* Q7 */ + } - /* subtract the floor */ - S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 ); - move16(); + /* subtract the floor */ + S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 ); + move16(); - /* update the floor */ - flor = add( flor, step ); /*Q7*/ + /* update the floor */ + flor = add( flor, step ); /*Q7*/ + } } } @@ -285,35 +319,67 @@ Word16 multi_harm_fx( Lcor_map_LT_sum = L_deposit_l( 0 ); tmp2 = 0; move16(); - +#ifdef FIX_2364_HARM_MULT_HARM + tmp2_32 = 0; + move32(); +#endif cor_strong = 0; move16(); pt1 = cor_map_LT; // Q15 move16(); pt2 = cor_map; move16(); - FOR( i = 0; i < L; i++ ) +#ifdef FIX_2364_HARM_MULT_HARM + IF( element_mode != EVS_MONO ) { - /* tmp2 += S[i]; */ - tmp2 = add( tmp2, shl( S[i], 1 ) ); /* tmp2 in Q8; max value is 128) */ + FOR( i = 0; i < L; i++ ) + { + /* tmp2 += S[i]; */ + tmp2_32 = L_add( tmp2_32, cor_map[i] ); /* tmp2_32 in Q15; max value is 128) */ - /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */ - *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 ); - move16(); + /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */ + *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 ); + move16(); - /* cor_map_LT_sum += *pt1 */ - Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */ + /* cor_map_LT_sum += *pt1 */ + Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */ - if ( GT_16( *pt1, 31130 ) /*0.95f.Q15*/ ) + if ( GT_16( *pt1, 31130 ) /*0.95f*/ ) + { + cor_strong = 1; + move16(); + } + + pt1++; + pt2++; + } + tmp2 = extract_l( L_shr_sat( tmp2_32, 7 ) ); // q15-> q8 + } + ELSE +#endif + { + FOR( i = 0; i < L; i++ ) { - cor_strong = 1; + /* tmp2 += S[i]; */ + tmp2 = add( tmp2, shl( S[i], 1 ) ); /* tmp2 in Q8; max value is 128) */ + + /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */ + *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 ); move16(); - } - pt1++; - pt2++; - } + /* cor_map_LT_sum += *pt1 */ + Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */ + + if ( GT_16( *pt1, 31130 ) /*0.95f.Q15*/ ) + { + cor_strong = 1; + move16(); + } + pt1++; + pt2++; + } + } IF( ( bwidth == NB ) ) { /* cor_map_LT_sum *= 1.53f; */ @@ -360,7 +426,7 @@ Word16 multi_harm_fx( return harm; } - +#ifndef FIX_2364_HARM_MULT_HARM /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_ivas_fx( const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ @@ -695,3 +761,4 @@ Word16 multi_harm_ivas_fx( } return harm; } +#endif \ No newline at end of file diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 756ee4ac3..188f08246 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -1105,8 +1105,13 @@ void noise_est_fx( { i = 0; move16(); +#ifndef FIX_2364_HARM_MULT_HARM *loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); +#else + *loc_harm = multi_harm_fx( EVS_MONO, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, + st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); +#endif move16(); } @@ -2400,8 +2405,13 @@ void noise_est_ivas_fx( { i = 0; move16(); +#ifndef FIX_2364_HARM_MULT_HARM *loc_harm = multi_harm_ivas_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); +#else + *loc_harm = multi_harm_fx( st_fx->element_mode, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, + st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); +#endif move16(); } } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index f6fc25fde..6233e8689 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4207,6 +4207,9 @@ Word32 mslvq_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_fx( +#ifdef FIX_2364_HARM_MULT_HARM + const Word16 element_mode, /* i : IVAS element_mode Q0 */ +#endif const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ @@ -4221,6 +4224,7 @@ Word16 multi_harm_fx( Word16 S_map[] /* o : short-term correlation map Q7 */ ); +#ifndef FIX_2364_HARM_MULT_HARM /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_ivas_fx( const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ @@ -4236,6 +4240,7 @@ Word16 multi_harm_ivas_fx( Word16 *sp_floor, /* o: noise floor estimate Q7 */ Word16 S_map[] /* o : short-term correlation map Q7 */ ); +#endif void pvq_encode_frame_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ -- GitLab From 9feb2922838009e18233776a02cd059f86483f94 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 22 Jan 2026 10:14:26 -0500 Subject: [PATCH 2/3] fix clang-format --- lib_enc/multi_harm_fx.c | 2 +- lib_enc/nois_est_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 07a80bb85..cfba37d19 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -761,4 +761,4 @@ Word16 multi_harm_ivas_fx( } return harm; } -#endif \ No newline at end of file +#endif diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 188f08246..4fa371533 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2410,7 +2410,7 @@ void noise_est_ivas_fx( st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); #else *loc_harm = multi_harm_fx( st_fx->element_mode, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, - st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); + st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); #endif move16(); } -- GitLab From e4f6113a97298476dad19d4800c0f15dad757cbd Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 23 Jan 2026 14:40:20 +0100 Subject: [PATCH 3/3] formatting --- lib_enc/multi_harm_fx.c | 7 ++- lib_enc/nois_est_fx.c | 108 ++++++++++++++++++++++------------------ 2 files changed, 66 insertions(+), 49 deletions(-) diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index cfba37d19..a042bcbc4 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -48,6 +48,7 @@ Word16 multi_harm_fx( #ifdef FIX_2364_HARM_MULT_HARM Word32 tmp2_32; #endif + /*------------------------------------------------------------------* * initialization *------------------------------------------------------------------*/ @@ -124,6 +125,7 @@ Word16 multi_harm_fx( move16(); step = 0; move16(); + #ifdef FIX_2364_HARM_MULT_HARM IF( element_mode != EVS_MONO ) { @@ -214,6 +216,7 @@ Word16 multi_harm_fx( *cor_strong_limit = 1; move16(); } + test(); if ( LT_32( total_brate, ACELP_9k60 ) || GT_32( total_brate, ACELP_16k40 ) ) { @@ -329,6 +332,7 @@ Word16 multi_harm_fx( move16(); pt2 = cor_map; move16(); + #ifdef FIX_2364_HARM_MULT_HARM IF( element_mode != EVS_MONO ) { @@ -380,6 +384,7 @@ Word16 multi_harm_fx( pt2++; } } + IF( ( bwidth == NB ) ) { /* cor_map_LT_sum *= 1.53f; */ @@ -423,9 +428,9 @@ Word16 multi_harm_fx( { Copy( S, S_map, L ); } + return harm; } - #ifndef FIX_2364_HARM_MULT_HARM /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_ivas_fx( diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 4fa371533..67e7fbf35 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -62,10 +62,11 @@ * y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx) *-----------------------------------------------------------------*/ -Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ - Word16 x, /* i : Qx x(n) */ - Word16 y, /* i : Qx y(n-1) */ - Word16 alpha /*i : Q15 scaling of driving x(n) */ +/* o : Qx y(n) */ +Word16 noise_est_AR1_Qx( + Word16 x, /* i : Qx x(n) */ + Word16 y, /* i : Qx y(n-1) */ + Word16 alpha /*i : Q15 scaling of driving x(n) */ ) { Word16 alpham1; @@ -75,10 +76,11 @@ 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) */ +/* o : Qx y(n) */ +Word32 noise_est_AR1_Qx_32( + Word32 x, /* i : Qx x(n) */ + Word32 y, /* i : Qx y(n-1) */ + Word32 alpha /*i : Q15 scaling of driving x(n) */ ) { Word32 alpham1; @@ -89,6 +91,7 @@ Word32 noise_est_AR1_Qx_32( /* o : Qx y(n) */ return Madd_32_32( Mpy_32_32( y, alpham1 ), x, alpha ); } + /*-----------------------------------------------------------------* * noise_est_ln_q8_fx() * @@ -126,12 +129,13 @@ static Word16 noise_est_ln_q8_fx( * *-----------------------------------------------------------------*/ -static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */ - Word16 eps_num_h, /* num high ,*/ - Word16 eps_num_l, /* num low (signed) ,*/ - Word16 eps_den_h, /* den low */ - Word16 eps_den_l, /* den low (signed),*/ - Word16 q_out /* range 15...0 , tested with 11 and 12 */ +/* o: eps_num/eps_den in q_out */ +static Word32 eps_quota_fx( + Word16 eps_num_h, /* num high ,*/ + Word16 eps_num_l, /* num low (signed) ,*/ + Word16 eps_den_h, /* den low */ + Word16 eps_den_l, /* den low (signed),*/ + Word16 q_out /* range 15...0 , tested with 11 and 12 */ ) { Word32 L_tmp_num, L_tmp_den; @@ -139,7 +143,6 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out Word16 m_num, m_den; Word16 num_shift; - L_tmp_num = L_Comp( eps_num_h, eps_num_l ); L_tmp_den = L_Comp( eps_den_h, eps_den_l ); @@ -166,11 +169,13 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out return L_shr( m_num, num_shift ); } + /*-----------------------------------------------------------------* * noise_est_init_fx() * * Initialization of Noise estimator *-----------------------------------------------------------------*/ + void noise_est_init_fx( NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */ ) @@ -385,6 +390,8 @@ void noise_est_init_ivas_fx( return; } + + /*-----------------------------------------------------------------* * noise_est_pre_fx() * @@ -432,7 +439,6 @@ void noise_est_pre_fx( hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, 20 ); move16(); /* 20 = .08 in Q8 */ - /* Could even be higher but it also delays first entry to DTX */ IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) ) { @@ -611,6 +617,8 @@ void noise_est_pre_32fx( return; } + + /*==================================================================================*/ /* FUNCTION : noise_est_down_fx() */ /*----------------------------------------------------------------------------------*/ @@ -638,7 +646,6 @@ void noise_est_pre_32fx( /* _ (Word32[]) tmpN_he1 : temporary noise update 1 Q_new+QSCALE */ /*----------------------------------------------------------------------------------*/ - void noise_est_down_fx( const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ Word32 bckr[], /* i/o: per band background noise energy estimate */ @@ -689,6 +696,7 @@ void noise_est_down_fx( Ltmp = Mpy_32_16( e_Noise, f_Noise, LG10 ); *totalNoise = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/ move16(); + /*-----------------------------------------------------------------* * Average energy per frame for each frequency band *-----------------------------------------------------------------*/ @@ -836,6 +844,7 @@ void noise_est_down_ivas_fx( /*-----------------------------------------------------------------* * Background noise energy update *-----------------------------------------------------------------*/ + FOR( i = 0; i < NB_BANDS; i++ ) { /* tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; */ @@ -896,9 +905,11 @@ void noise_est_down_ivas_fx( move16(); move16(); move16(); + /*------------------------------------------------------------------* * Energy variation update *------------------------------------------------------------------*/ + /*Etot_v = (float) fabs(*Etot_last - Etot);*/ L_Etot_v = L_abs( L_sub( L_Etot_last, L_Etot ) ); /* Q24 */ @@ -914,11 +925,13 @@ void noise_est_down_ivas_fx( return; } + /*-----------------------------------------------------------------* * noise_est_fx() * * Noise energy estimation (noise energy is updated in case of noise-only frame) *-----------------------------------------------------------------*/ + void noise_est_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ @@ -995,6 +1008,7 @@ void noise_est_fx( /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ + vad_bwidth_fx = st_fx->input_bwidth; move16(); @@ -1109,6 +1123,7 @@ void noise_est_fx( *loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); #else + test(); *loc_harm = multi_harm_fx( EVS_MONO, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); #endif @@ -1162,7 +1177,6 @@ void noise_est_fx( } Lsum_den = L_shr( Lsum_den, tmpExp ); - /* calculation of spectral diversity */ /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */ spec_div = 0; @@ -1224,7 +1238,6 @@ void noise_est_fx( /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */ hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp ); - nchar_thr = THR_NCHAR_WB_FX; move16(); /* 1.0 Q11 */ if ( vad_bwidth_fx == NB ) @@ -1263,6 +1276,7 @@ void noise_est_fx( /*if( alpha > 0.999f { alpha = 0.999f;} */ alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */ + /*--------------------------------------------------------------* * during significant attacks, replace the LT energy by the * current energy this will cause non_sta2 failures to occur in @@ -1374,6 +1388,7 @@ void noise_est_fx( move16(); } } + test(); IF( GE_16( i, 2 ) && LE_16( i, 16 ) ) { @@ -1442,11 +1457,15 @@ void noise_est_fx( test(); *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); move16(); + + test(); + test(); if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_16( round_fx( Ltmp ), COR_MAX_NNE_FX ) ) ) ) { *st_harm_cor_cnt = 0; move16(); } + test(); test(); test(); @@ -1457,6 +1476,7 @@ void noise_est_fx( { *st_harm_cor_cnt = 1; } + test(); test(); if ( GT_16( *st_harm_cor_cnt, 1 ) && @@ -1470,10 +1490,10 @@ void noise_est_fx( move16(); } - /*-----------------------------------------------------------------* * Energy based pause length counter *-----------------------------------------------------------------*/ + test(); IF( ( *bg_cnt >= 0 ) && ( GT_16( sub( Etot, Etot_l_lp ), 1280 ) /*5.0 in Q8*/ ) ) { @@ -1491,6 +1511,7 @@ void noise_est_fx( move16(); } } + if ( *bg_cnt >= 0 ) { *bg_cnt = add( *bg_cnt, 1 ); @@ -1511,7 +1532,6 @@ void noise_est_fx( epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */ - /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */ alpha = 4915; move16(); /*0.15 in Q15 */ @@ -1536,7 +1556,6 @@ void noise_est_fx( /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/ epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */ - /*-----------------------------------------------------------------* * Linear predition efficiency 2 to 16 order *-----------------------------------------------------------------*/ @@ -1551,7 +1570,6 @@ void noise_est_fx( epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */ - /* if (epsP_2_16 > st->epsP_2_16_lp){ st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp; } else { @@ -1573,7 +1591,6 @@ void noise_est_fx( move16(); epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx ); - /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) { st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2; } else { @@ -1644,7 +1661,6 @@ void noise_est_fx( hNoiseEst->low_tn_track_cnt = tmp; move16(); - /* update of the long-term non-stationarity measure (between 0 and 1) */ /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) { st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1; @@ -1662,10 +1678,10 @@ void noise_est_fx( hNoiseEst->act_pred_fx = tmp; move16(); - /*-----------------------------------------------------------------* * Background noise adaptation enable flag *-----------------------------------------------------------------*/ + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); cor_tmp = mac_r_sat( Ltmp, corr_shift, MAX_16 ); @@ -1729,17 +1745,14 @@ void noise_est_fx( } hNoiseEst->aEn = add( hNoiseEst->aEn, tmp ); - hNoiseEst->aEn = s_min( hNoiseEst->aEn, 6 ); hNoiseEst->aEn = s_max( hNoiseEst->aEn, 0 ); /* Additional NNE detectors */ - /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ /* Q15 Q15 Q12 */ comb_ahc_epsP = s_max( s_max( shr( hNoiseEst->act_pred_fx, 15 - 12 ), shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ) ), epsP_2_16_dlp ); /* Q12 */ - /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ /* Q15 Q12 Q12 */ comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */ @@ -1793,7 +1806,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); @@ -1803,7 +1815,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); @@ -1822,7 +1833,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */ SD_1 = 0; move16(); @@ -1922,7 +1932,6 @@ void noise_est_fx( tmp = s_and( tmp, SD_1_inv ); PAU = s_or( PAU, s_and( tmp, s_or( s_and( PD_3, s_or( PD_1, PD_2 ) ), s_or( PD_4, PD_5 ) ) ) ); - /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */ NEW_POS_BG = s_and( s_or( PAU, BG_1 ), bg_bgd3 ); @@ -1936,7 +1945,6 @@ void noise_est_fx( move16(); } - /* When the signal dynamics is high and the energy is close to the background estimate */ /* sd1_bgd = (st->sign_dyn_lp > 15) && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2 @@ -2187,11 +2195,13 @@ void noise_est_fx( return; } + /*-----------------------------------------------------------------* * noise_est_fx() * * Noise energy estimation (noise energy is updated in case of noise-only frame) *-----------------------------------------------------------------*/ + void noise_est_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ @@ -2284,10 +2294,10 @@ void noise_est_ivas_fx( /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ + vad_bwidth_fx = st_fx->input_bwidth; move16(); - /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ temp = 0; move64(); @@ -2341,6 +2351,7 @@ void noise_est_ivas_fx( } } } + /*-----------------------------------------------------------------* * Set the threshold for eps & non_sta based on input sampling rate * The reason is that in case of 8kHz sampling input, there is nothing @@ -2394,11 +2405,10 @@ void noise_est_ivas_fx( move16(); /* low correlation -> probably inactive signal */ } - /* Update */ - /*-----------------------------------------------------------------* * Multi-harmonic analysis *-----------------------------------------------------------------*/ + IF( hFrontVad == NULL ) { IF( st_fx->hSpMusClas != NULL ) @@ -2415,9 +2425,11 @@ void noise_est_ivas_fx( move16(); } } + /*-----------------------------------------------------------------* * Detection of frames with non-stationary spectral content *-----------------------------------------------------------------*/ + /* weighted sum of spectral changes per critical bands */ w_sum_num = 0; move64(); @@ -2429,6 +2441,7 @@ void noise_est_ivas_fx( Word16 exp, exp2; w_sum_den = 0; move64(); + FOR( i = 10; i <= st_fx->max_band; i++ ) { Lnum = L_max( *pt1, *pt2 ); @@ -2441,7 +2454,6 @@ void noise_est_ivas_fx( num = extract_h( Mpy_32_32( Lnum, Lnum ) ); // 2*(q_fr_bands+exp)-31-16 ExpNum = add( sub( shl( q_fr_bands, 1 ), 47 ), shl( exp, 1 ) ); - den = E_MIN_FXQ31 >> 8; // 29360, 0.0035f in Q23 ExpDen = Q23; move32(); @@ -2606,6 +2618,7 @@ void noise_est_ivas_fx( /*if( alpha > 0.999f { alpha = 0.999f;} */ alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */ + /*--------------------------------------------------------------* * during significant attacks, replace the LT energy by the * current energy this will cause non_sta2 failures to occur in @@ -2780,7 +2793,8 @@ 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 */ ) ) @@ -2814,6 +2828,7 @@ void noise_est_ivas_fx( Word16 exp_tmp; st_E_var_est_fx = BASOP_Util_Add_Mant32Exp( hNoiseEst->L_Etot_sq_st_est_fx, Q15, L_negate( Mpy_32_32( hNoiseEst->L_Etot_st_est_fx, hNoiseEst->L_Etot_st_est_fx ) ), Q16, &exp_tmp ); // exp(exp_tmp) + /*-----------------------------------------------------------------* * Count frames since last correlation or harmonic event *-----------------------------------------------------------------*/ @@ -2823,6 +2838,7 @@ void noise_est_ivas_fx( *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); move16(); + test(); test(); if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_32( Ltmp, 1825361101 /* 0.85 in Q31 */ ) ) ) ) @@ -2841,6 +2857,7 @@ void noise_est_ivas_fx( *st_harm_cor_cnt = 1; move16(); } + test(); test(); IF( GT_16( *st_harm_cor_cnt, 1 ) && GT_16( Etot, 7680 /* 30.0f in Q8 */ ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( st_E_var_est_fx, exp_tmp, 524288 /* 8.0f in Q16 */, Q15 ), 1 ) ) @@ -2850,7 +2867,6 @@ void noise_est_ivas_fx( move16(); } - /*-----------------------------------------------------------------* * Energy based pause length counter *-----------------------------------------------------------------*/ @@ -3003,7 +3019,6 @@ void noise_est_ivas_fx( hNoiseEst->lt_Ellp_dist_fx = mac_r( L_mult( tmp, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_Ellp_dist_fx, 31785 /* 0.97 in Q15*/ ); // Q8 move16(); - /* if (st->harm_cor_cnt == 0) { st->lt_haco_ev = 0.03f*1.0 + 0.97f*st->lt_haco_ev; } else { @@ -3057,6 +3072,7 @@ void noise_est_ivas_fx( /*-----------------------------------------------------------------* * Background noise adaptation enable flag *-----------------------------------------------------------------*/ + /* if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW ) && ( ( non_sta > th_sta ) || @@ -3088,7 +3104,6 @@ void noise_est_ivas_fx( LepsP = extract_l( div_s( num, den ) ); // Q15+exp-exp2 LepsP = L_shr( LepsP, add( sub( exp, exp2 ), 4 ) ); // Q11 - test(); test(); test(); @@ -3128,9 +3143,11 @@ void noise_est_ivas_fx( move16(); move16(); } + /*-----------------------------------------------------------------* * Stereo classifier - save raw aEn *-----------------------------------------------------------------*/ + IF( hStereoClassif != NULL ) { /* @@ -3161,14 +3178,11 @@ void noise_est_ivas_fx( move16(); } - /* Additional NNE detectors */ - /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ /* Q15 Q15 Q12 */ comb_ahc_epsP = s_max( shr( s_max( hNoiseEst->act_pred_fx, hNoiseEst->lt_haco_ev_fx ), 15 - 12 ), epsP_2_16_dlp ); /* Q12 */ - /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ /* Q15 Q12 Q12 */ comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */ @@ -3222,7 +3236,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); @@ -3232,7 +3245,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); @@ -3251,7 +3263,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */ SD_1 = 0; move16(); @@ -3588,6 +3599,7 @@ void noise_est_ivas_fx( } } } + /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f) *st->lt_aEn_zero;*/ /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */ L_tmp = 0; -- GitLab