From 1d29f81de7a485037e0b152bee5c484a36d5f00a Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 13:19:48 -0500 Subject: [PATCH 01/10] harmonized find_uv --- lib_com/options.h | 1 + lib_enc/find_uv_fx.c | 61 +++++++++++++++++++++------ lib_enc/ivas_core_pre_proc_front_fx.c | 6 ++- lib_enc/pre_proc_fx.c | 6 ++- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8eda542ad..0ee84c145 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -109,6 +109,7 @@ #define FIX_FLOAT_1501_UNIT_VALUE_IN_OMASA /* Nokia: Fix float issue 1501, uninitialized value in ivas_masa_combine_directions for OMASA */ #define FIX_BASOP_2323_DIRAC_ENC_WRONG_INIT /* Nokia/FhG: basop issue 2323: Use correct init size */ #define FIX_BASOP_2324_MISSING_SET_TO_ZERO /* Nokia: basop issue 2324: Fix issue by setting the exponent to zero where it should be */ +#define FIX_2349_HARM_FIND_UV /* VA: basop issue 2349 : harmonizing find_uv function */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index a0fa4dbbd..9f2dd523e 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -82,7 +82,7 @@ static Word16 find_ener_decrease_fx( /* o : maximum * * Decision about coder type *-------------------------------------------------------------------*/ - +#ifndef FIX_2349_HARM_FIND_UV Word16 find_uv_fx( /* o : coding type */ Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ @@ -573,6 +573,9 @@ Word16 find_uv_fx( /* o : coding type * Decision about coder type *-------------------------------------------------------------------*/ Word16 find_uv_ivas_fx( /* o : coding type */ +#else +Word16 find_uv_fx( /* o : coding type */ +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ @@ -587,6 +590,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ const Word16 last_core_orig, /* i : original last core Q0*/ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 Q_new, + const Word16 shift, const Word16 q_hp_E ) { Word16 coder_type, i; @@ -607,7 +611,16 @@ Word16 find_uv_ivas_fx( /* o : coding typ SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; Word16 Last_Resort; Word16 vadnoise; - +#ifdef FIX_2349_HARM_FIND_UV + Word16 Q_in, loc_lp_noise; + + Q_in = Q_new; + move16(); + if( st_fx->element_mode == EVS_MONO ) + { + Q_in = sub( Q_new, 1 ); + } +#endif IF( hSC_VBR != NULL ) { Last_Resort = hSC_VBR->Last_Resort; /* Q0 */ @@ -637,7 +650,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ pt_enr_ssf = enr_ssf + 2 * NB_SSF; FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ ) { - emaximum_fx( Q_new, pt_speech, SSF, pt_enr_ssf ); + emaximum_fx( Q_in, pt_speech, SSF, pt_enr_ssf ); pt_speech += ( SSF / 2 ); pt_enr_ssf++; } @@ -675,7 +688,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ pt_enr_ssf1++; } - IF( hStereoClassif != NULL ) + IF( hStereoClassif != NULL ) /* IVAS only */ { IF( st_fx->idchan == 0 ) { @@ -717,7 +730,12 @@ Word16 find_uv_ivas_fx( /* o : coding typ *-----------------------------------------------------------------*/ dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/ - +#ifdef FIX_2349_HARM_FIND_UV + if ( st_fx->element_mode == EVS_MONO ) /* Overwrite DE3 in case of EVS */ + { + dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/ + } +#endif /*-----------------------------------------------------------------* * Energy decrease after spike (dE2) *-----------------------------------------------------------------*/ @@ -806,7 +824,12 @@ Word16 find_uv_ivas_fx( /* o : coding typ } E_min_th = L_shl( E_MIN_IVAS_FX_Q31, sub( q_hp_E, Q31 ) ); - +#ifdef FIX_2349_HARM_FIND_UV + if ( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ + { + E_min_th = L_shl( E_MIN_FX, Q_new ); + } +#endif test(); test(); test(); @@ -836,16 +859,22 @@ Word16 find_uv_ivas_fx( /* o : coding typ { ee1_th = 544; /*8.5f Q6*/ move16(); - + loc_lp_noise = extract_h( st_fx->lp_noise_32fx ); +#ifdef FIX_2349_HARM_FIND_UV + if ( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ + { + loc_lp_noise = st_fx->lp_noise_fx; + } +#endif /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */ 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 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 + L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, loc_lp_noise ); // 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 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 + L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, loc_lp_noise ); // Q24 } relE_thres = round_fx( L_tmp ); } @@ -853,7 +882,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 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 + L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, loc_lp_noise ); // Q24 relE_thres = round_fx( L_tmp ); } relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */ @@ -889,7 +918,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); test(); - IF( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + if( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ @@ -917,7 +946,9 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ +#ifdef FIX_2349_HARM_FIND_UV + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) && st_fx->element_mode == EVS_MONO ) && /* normalized correlation low on look-ahead - onset detection */ +#endif ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ @@ -1037,9 +1068,13 @@ Word16 find_uv_ivas_fx( /* o : coding typ move16(); /* Current frame cannot be compressed to pack the partial redundancy;*/ - IF( NE_16( st_fx->rf_mode, st_fx->Opt_RF_ON ) ) + IF( NE_16( st_fx->rf_mode, st_fx->Opt_RF_ON ) ) /* can happen only for EVS-BE modes*/ { +#ifdef FIX_2349_HARM_FIND_UV + core_coder_mode_switch_fx( st_fx, st_fx->last_total_brate, 0, shift ); +#else core_coder_mode_switch_ivas_fx( st_fx, st_fx->last_total_brate, 0 ); +#endif } } } diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 8090f9ede..4e8846cf7 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1292,9 +1292,13 @@ ivas_error pre_proc_front_ivas_fx( find_tilt_ivas_fx( fr_bands_fx, fr_bands_fx_q, bckr_temp, scale, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, q_lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); - +#ifdef FIX_2349_HARM_FIND_UV + st->coder_type = find_uv_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, + &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, shift, fr_bands_fx_q ); // Q0 +#else st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, fr_bands_fx_q ); // Q0 +#endif Copy_Scale_sig_16_32_no_sat( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); /*-----------------------------------------------------------------* diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 978df321a..1c5ffc863 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -520,9 +520,13 @@ void pre_proc_fx( find_tilt_fx( fr_bands, hNoiseEst->bckr_fx, ee, st->pitch, st->voicing_fx, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, st->codec_mode, *Q_new, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); +#ifdef FIX_2349_HARM_FIND_UV + st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, NULL, corr_shift, relE, *Etot, hp_E, + &flag_spitch, last_core_orig, NULL, *Q_new, *shift, NULL ); // Q0 +#else st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig ); - +#endif /*-----------------------------------------------------------------* * channel aware mode configuration * *-----------------------------------------------------------------*/ -- GitLab From 3267a954786ea875ccaec03731b0f7af2095ba75 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 13:29:55 -0500 Subject: [PATCH 02/10] fix gcc --- lib_enc/pre_proc_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 1c5ffc863..f30216517 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -521,8 +521,8 @@ void pre_proc_fx( st->max_band, hp_E, st->codec_mode, *Q_new, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); #ifdef FIX_2349_HARM_FIND_UV - st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, NULL, corr_shift, relE, *Etot, hp_E, - &flag_spitch, last_core_orig, NULL, *Q_new, *shift, NULL ); // Q0 + st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, 0, corr_shift, relE, *Etot, hp_E, + &flag_spitch, last_core_orig, NULL, *Q_new, *shift, 0 ); // Q0 #else st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig ); -- GitLab From efda00c4a361c7df35446d1a9f7c21f343e1026b Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 13:39:38 -0500 Subject: [PATCH 03/10] fix gcc --- lib_enc/pre_proc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index f30216517..78f52dd37 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -521,7 +521,7 @@ void pre_proc_fx( st->max_band, hp_E, st->codec_mode, *Q_new, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); #ifdef FIX_2349_HARM_FIND_UV - st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, 0, corr_shift, relE, *Etot, hp_E, + st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, 0L, corr_shift, relE, *Etot, hp_E, &flag_spitch, last_core_orig, NULL, *Q_new, *shift, 0 ); // Q0 #else st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, -- GitLab From 2a1dbfab84f3d3e649d17b832a54ac3ffe8cabc0 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 13:41:16 -0500 Subject: [PATCH 04/10] missing modifications --- lib_enc/ivas_core_pre_proc_front_fx.c | 2 +- lib_enc/prot_fx_enc.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 4e8846cf7..82d1cdcc9 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1294,7 +1294,7 @@ ivas_error pre_proc_front_ivas_fx( corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); #ifdef FIX_2349_HARM_FIND_UV st->coder_type = find_uv_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, - &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, shift, fr_bands_fx_q ); // Q0 + &flag_spitch, last_core_orig, hStereoClassif, *Q_new, 0, fr_bands_fx_q ); // Q0 #else st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, fr_bands_fx_q ); // Q0 diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d6caa4780..303c0b0dc 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -241,9 +241,12 @@ void find_tilt_fx( Word32 *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise Q16*/ Word16 Opt_vbr_mode /* Q0 */ ); - +#ifndef FIX_2349_HARM_FIND_UV /* o : coding type */ Word16 find_uv_ivas_fx( +#else +Word16 find_uv_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ @@ -258,8 +261,10 @@ Word16 find_uv_ivas_fx( const Word16 last_core_orig, /* i : original last core Q0*/ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 Q_new, + const Word16 shift, const Word16 q_hp_E ); +#ifndef FIX_2349_HARM_FIND_UV /* o : coding type */ Word16 find_uv_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -276,6 +281,7 @@ Word16 find_uv_fx( const Word16 shift, const Word16 last_core_orig /* i : original last core Q0*/ ); +#endif void fine_gain_quant_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ -- GitLab From 13d4e22e0a7d992b1995797cd6d0b342e0a7a7ca Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 14:04:48 -0500 Subject: [PATCH 05/10] modification to ensure build even if switch not activated --- lib_enc/find_uv_fx.c | 8 ++++++-- lib_enc/prot_fx_enc.h | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 9f2dd523e..2f64f8d5f 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -590,7 +590,9 @@ Word16 find_uv_fx( /* o : coding type const Word16 last_core_orig, /* i : original last core Q0*/ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 Q_new, +#ifdef FIX_2349_HARM_FIND_UV const Word16 shift, +#endif const Word16 q_hp_E ) { Word16 coder_type, i; @@ -611,16 +613,18 @@ Word16 find_uv_fx( /* o : coding type SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; Word16 Last_Resort; Word16 vadnoise; -#ifdef FIX_2349_HARM_FIND_UV Word16 Q_in, loc_lp_noise; - + Q_in = Q_new; move16(); + +#ifdef FIX_2349_HARM_FIND_UV if( st_fx->element_mode == EVS_MONO ) { Q_in = sub( Q_new, 1 ); } #endif + IF( hSC_VBR != NULL ) { Last_Resort = hSC_VBR->Last_Resort; /* Q0 */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 303c0b0dc..0eec956d0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -261,8 +261,11 @@ Word16 find_uv_fx( const Word16 last_core_orig, /* i : original last core Q0*/ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 Q_new, +#ifdef FIX_2349_HARM_FIND_UV const Word16 shift, - const Word16 q_hp_E ); +#endif + const Word16 q_hp_E +); #ifndef FIX_2349_HARM_FIND_UV /* o : coding type */ -- GitLab From 7d747298c186ff7aecbf91a6292263eb79ebbdcd Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 14:10:53 -0500 Subject: [PATCH 06/10] fix clang format --- lib_enc/find_uv_fx.c | 40 +++++++++++++-------------- lib_enc/ivas_core_pre_proc_front_fx.c | 2 +- lib_enc/prot_fx_enc.h | 3 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 2f64f8d5f..7f7834ff6 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -572,7 +572,7 @@ Word16 find_uv_fx( /* o : coding type * * Decision about coder type *-------------------------------------------------------------------*/ -Word16 find_uv_ivas_fx( /* o : coding type */ +Word16 find_uv_ivas_fx( /* o : coding type */ #else Word16 find_uv_fx( /* o : coding type */ #endif @@ -619,7 +619,7 @@ Word16 find_uv_fx( /* o : coding type move16(); #ifdef FIX_2349_HARM_FIND_UV - if( st_fx->element_mode == EVS_MONO ) + if ( st_fx->element_mode == EVS_MONO ) { Q_in = sub( Q_new, 1 ); } @@ -922,16 +922,16 @@ Word16 find_uv_fx( /* o : coding type test(); test(); test(); - if( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) + if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; @@ -953,14 +953,14 @@ Word16 find_uv_fx( /* o : coding type #ifdef FIX_2349_HARM_FIND_UV ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) && st_fx->element_mode == EVS_MONO ) && /* normalized correlation low on look-ahead - onset detection */ #endif - ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ + ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 82d1cdcc9..cddc64ad1 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1294,7 +1294,7 @@ ivas_error pre_proc_front_ivas_fx( corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); #ifdef FIX_2349_HARM_FIND_UV st->coder_type = find_uv_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, - &flag_spitch, last_core_orig, hStereoClassif, *Q_new, 0, fr_bands_fx_q ); // Q0 + &flag_spitch, last_core_orig, hStereoClassif, *Q_new, 0, fr_bands_fx_q ); // Q0 #else st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, fr_bands_fx_q ); // Q0 diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 0eec956d0..3ca145caf 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -264,8 +264,7 @@ Word16 find_uv_fx( #ifdef FIX_2349_HARM_FIND_UV const Word16 shift, #endif - const Word16 q_hp_E -); + const Word16 q_hp_E ); #ifndef FIX_2349_HARM_FIND_UV /* o : coding type */ -- GitLab From 4b38f9082d4369c0582928bd329c89db25f1d59d Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 15:19:45 -0500 Subject: [PATCH 07/10] fix wrong condition --- lib_enc/find_uv_fx.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 7f7834ff6..432f3583e 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -938,6 +938,25 @@ Word16 find_uv_fx( /* o : coding type move16(); } } +#ifdef FIX_2349_HARM_FIND_UV + ELSE IF( st_fx->element_mode == EVS_MONO ) + { + if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.8 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ + { + coder_type = UNVOICED; + move16(); + } + } +#endif ELSE { test(); @@ -950,9 +969,7 @@ Word16 find_uv_fx( /* o : coding type test(); test(); if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ -#ifdef FIX_2349_HARM_FIND_UV - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) && st_fx->element_mode == EVS_MONO ) && /* normalized correlation low on look-ahead - onset detection */ -#endif + /* ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ -- GitLab From 757a568f7dc3818e7e7b50d806296289bb812c4e Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 15:25:56 -0500 Subject: [PATCH 08/10] fix clang-format --- lib_enc/find_uv_fx.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 432f3583e..1338ac5c9 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -954,7 +954,7 @@ Word16 find_uv_fx( /* o : coding type { coder_type = UNVOICED; move16(); - } + } } #endif ELSE @@ -969,15 +969,15 @@ Word16 find_uv_fx( /* o : coding type test(); test(); if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - /* ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ + /* ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); -- GitLab From 63842b01fb4041c8b0b3d665cefa9d5e82fbf653 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 16:40:40 -0500 Subject: [PATCH 09/10] fix some asan errors --- lib_enc/find_uv_fx.c | 20 ++++++++++++++++---- lib_enc/pre_proc_fx.c | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 1338ac5c9..7a35b7bca 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -733,13 +733,19 @@ Word16 find_uv_fx( /* o : coding type * Total frame energy difference (dE3) *-----------------------------------------------------------------*/ - dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/ #ifdef FIX_2349_HARM_FIND_UV - if ( st_fx->element_mode == EVS_MONO ) /* Overwrite DE3 in case of EVS */ + IF ( st_fx->element_mode == EVS_MONO ) /* Overwrite DE3 in case of EVS */ { dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/ } + ELSE + { + dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/ + } +#else + dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/ #endif + /*-----------------------------------------------------------------* * Energy decrease after spike (dE2) *-----------------------------------------------------------------*/ @@ -863,13 +869,19 @@ Word16 find_uv_fx( /* o : coding type { ee1_th = 544; /*8.5f Q6*/ move16(); - loc_lp_noise = extract_h( st_fx->lp_noise_32fx ); #ifdef FIX_2349_HARM_FIND_UV - if ( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ + IF ( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ { loc_lp_noise = st_fx->lp_noise_fx; } + ELSE + { + loc_lp_noise = extract_h( st_fx->lp_noise_32fx ); + } +#else + loc_lp_noise = extract_h( st_fx->lp_noise_32fx ); #endif + /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */ IF( st_fx->input_bwidth != NB ) { diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 78f52dd37..8b0b79bd9 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -522,7 +522,7 @@ void pre_proc_fx( #ifdef FIX_2349_HARM_FIND_UV st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, 0L, corr_shift, relE, *Etot, hp_E, - &flag_spitch, last_core_orig, NULL, *Q_new, *shift, 0 ); // Q0 + &flag_spitch, last_core_orig, NULL, *Q_new, *shift, 31 ); // Q0 #else st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig ); -- GitLab From d263f62c4b5e58745d3cf2a54e6c383608d3dcbc Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 20 Jan 2026 20:10:53 -0500 Subject: [PATCH 10/10] correct clang-format --- lib_enc/find_uv_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 7a35b7bca..650d6ddc6 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -574,7 +574,7 @@ Word16 find_uv_fx( /* o : coding type *-------------------------------------------------------------------*/ Word16 find_uv_ivas_fx( /* o : coding type */ #else -Word16 find_uv_fx( /* o : coding type */ +Word16 find_uv_fx( /* o : coding type */ #endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ @@ -734,7 +734,7 @@ Word16 find_uv_fx( /* o : coding type *-----------------------------------------------------------------*/ #ifdef FIX_2349_HARM_FIND_UV - IF ( st_fx->element_mode == EVS_MONO ) /* Overwrite DE3 in case of EVS */ + IF( st_fx->element_mode == EVS_MONO ) /* Overwrite DE3 in case of EVS */ { dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/ } @@ -870,7 +870,7 @@ Word16 find_uv_fx( /* o : coding type ee1_th = 544; /*8.5f Q6*/ move16(); #ifdef FIX_2349_HARM_FIND_UV - IF ( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ + IF( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ { loc_lp_noise = st_fx->lp_noise_fx; } -- GitLab