From 20969b1c2549c451090f12763c234bff3b6ffbb5 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 18 Mar 2026 09:40:00 +0100 Subject: [PATCH 01/21] added macro FIX_2485_HARMONIZE_perform_noise_estimation_enc and harmoninzed perform_noise_estimation_enc*_fx() --- lib_com/options.h | 1 + lib_enc/fd_cng_enc_fx.c | 255 +++++++++++++++++++++++++- lib_enc/ivas_core_pre_proc_front_fx.c | 9 +- lib_enc/pre_proc_fx.c | 4 + lib_enc/prot_fx_enc.h | 13 ++ 5 files changed, 280 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 40df8a614..8d309d1d3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -99,6 +99,7 @@ #define FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC /* Nokia: Fix to convert non-converted binary operations */ #define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ #define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ +#define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 2dbb0ac90..9797f9282 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -553,6 +553,7 @@ void resetFdCngEnc_fx( return; } +#ifndef FIX_2485_HARMONIZE_perform_noise_estimation_enc /* perform_noise_estimation_enc_fx @@ -713,6 +714,7 @@ void perform_noise_estimation_enc_fx( return; } +#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/ /* AdjustFirstSID_fx @@ -2286,7 +2288,7 @@ Word16 cng_energy_ivas_fx( return enr; } - +#ifndef FIX_2485_HARMONIZE_perform_noise_estimation_enc void perform_noise_estimation_enc_ivas_fx( Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, @@ -2476,6 +2478,257 @@ void perform_noise_estimation_enc_ivas_fx( return; } +#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/ + +#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc +void perform_noise_estimation_enc_fx( + Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ + Word16 band_energies_exp, + Word32 *enerBuffer, /* enerBuffer_exp */ + Word16 enerBuffer_exp, + HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + int element_mode /* i : is element EVS or IVAS */ +) +{ + if ( element_mode == 0 ) + { + (void) input_Fs; + (void) hCPE; + } + + Word16 i, j, s, s1, s2; + Word16 numBands; + Word16 nFFTpart = hFdCngEnc->hFdCngCom->nFFTpart; /* Q0 */ + move16(); + Word16 numCoreBands = hFdCngEnc->hFdCngCom->numCoreBands; /* Q0 */ + move16(); + Word16 regularStopBand = hFdCngEnc->hFdCngCom->regularStopBand; + move16(); + Word16 numSlots = hFdCngEnc->hFdCngCom->numSlots; /* Q0 */ + move16(); + Word16 nCLDFBpart = hFdCngEnc->hFdCngCom->nCLDFBpart; /* Q0 */ + move16(); + assert( numSlots == 16 ); + Word32 *periodog = hFdCngEnc->hFdCngCom->periodog; /* exp(peridog_exp) */ + Word32 *ptr_per_fx = periodog; + Word32 *msPeriodog_fx = hFdCngEnc->msPeriodog_fx; + Word32 tmp; + + /* preemphasis compensation and grouping of per bin energies into msPeriodog */ + FOR( i = 0; i < nFFTpart; i++ ) + { + tmp = L_add( L_shr( band_energies[i], 1 ), L_shr( band_energies[i + NB_BANDS], 1 ) ); /* exp(band_energies_exp) */ + msPeriodog_fx[i] = Mpy_32_16_1( tmp, preemphCompensation_fx[i] ); /* exp(band_energies_exp + 4) */ + move32(); + } + + /* exponent for fft part of msPeriodog */ + hFdCngEnc->msPeriodog_fx_exp_fft = add( band_energies_exp, PREEMPH_COMPENSATION_EXP ); + move16(); + + numBands = sub( regularStopBand, numCoreBands ); /* Q0 */ + + /* Adjust to the desired time resolution by averaging the periodograms over the CLDFB time slots */ + IF( element_mode > 0 ) /*IVAS: more precission*/ + { + Word16 max_exp = -31; + move16(); + Word16 periodog_exp[PERIODOGLEN]; + Word64 periodog_64; + Word32 scaleEB_fx = 0; + move32(); + i = 0; + move16(); + + test(); + IF( hCPE != NULL && hCPE->hStereoDft != NULL ) + { + SWITCH( input_Fs ) + { + case 8000: + scaleEB_fx = 251648; // Q35 + move32(); + BREAK; + case 16000: + scaleEB_fx = 62912; // Q35 + move32(); + BREAK; + case 32000: + scaleEB_fx = 15728; // Q35 + move32(); + BREAK; + case 48000: + scaleEB_fx = 6991; // Q35 + move32(); + BREAK; + default: + assert( 0 && "invalid sample rate" ); + } + } + ELSE + { + Word32 numSlots_inv_fx = 1073741824; // Q34 of .0625 + move32(); + scaleEB_fx = Mpy_32_32( numSlots_inv_fx, L_deposit_l( hFdCngEnc->hFdCngCom->scalingFactor ) ); // Q34 + Q30 - Q31 = Q33 + scaleEB_fx = L_shl( scaleEB_fx, 2 ); // Q35 + } + + FOR( j = numCoreBands; j < regularStopBand; j++ ) + { + periodog_64 = W_mult_32_32( enerBuffer[j], scaleEB_fx ); + Word16 scale = W_norm( periodog_64 ); + *ptr_per_fx = W_extract_h( W_shl( periodog_64, scale ) ); + move32(); + periodog_exp[i] = sub( Q31, add( add( sub( Q31, enerBuffer_exp ), 35 - 31 ), scale ) ); + move16(); + if ( *ptr_per_fx ) + { + max_exp = s_max( max_exp, periodog_exp[i] ); + } + ptr_per_fx++; + i++; + } + /* exponent for cldfb part of msPeriodog */ + // hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); + + FOR( i = 0; i < numBands; i++ ) + { + periodog[i] = L_shr( periodog[i], sub( max_exp, periodog_exp[i] ) ); + move16(); + } + hFdCngEnc->hFdCngCom->exp_cldfb_periodog = max_exp; + move16(); + } + ELSE /*EVS_MONO*/ + { + IF( numBands > 0 ) + { + /* Adjust to the desired time resolution by averaging the periodograms over the CLDFB time slots */ + FOR( j = numCoreBands; j < regularStopBand; j++ ) + { + *ptr_per_fx = Mpy_32_16_1( enerBuffer[j], hFdCngEnc->hFdCngCom->scalingFactor ); /* exp(enerBuffer_exp) */ + move32(); + + ptr_per_fx++; + } + + /* exponent for cldfb part of msPeriodog */ + hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); + + + } + } + + IF( numBands > 0 ) + { + ///* Adjust CLDFB filterbank to the desired frequency resolution by averaging over spectral partitions for SID transmission */ + bandcombinepow( + periodog, + hFdCngEnc->hFdCngCom->exp_cldfb_periodog, + numBands, + hFdCngEnc->hFdCngCom->CLDFBpart, + nCLDFBpart, + hFdCngEnc->hFdCngCom->CLDFBpsize_inv, + &msPeriodog_fx[nFFTpart], + &hFdCngEnc->msPeriodog_fx_exp_cldfb ); + + ///* find common exponent for fft part and cldfb part of msperiodog */ + s1 = L_norm_arr( msPeriodog_fx, nFFTpart ); + s2 = L_norm_arr( &msPeriodog_fx[nFFTpart], nCLDFBpart ); + + s = s_max( sub( hFdCngEnc->msPeriodog_fx_exp_fft, s1 ), sub( hFdCngEnc->msPeriodog_fx_exp_cldfb, s2 ) ); + s1 = sub( s, hFdCngEnc->msPeriodog_fx_exp_fft ); + s2 = sub( s, hFdCngEnc->msPeriodog_fx_exp_cldfb ); + + hFdCngEnc->msPeriodog_fx_exp_fft = s; + move16(); + hFdCngEnc->msPeriodog_fx_exp_cldfb = s; + move16(); + + FOR( i = 0; i < nFFTpart; i++ ) + { + msPeriodog_fx[i] = L_shr( msPeriodog_fx[i], s1 ); // hFdCngEnc->msPeriodog_fx_exp_fft + move32(); + } + + FOR( i = 0; i < nCLDFBpart; i++ ) + { + msPeriodog_fx[nFFTpart + i] = L_shr( msPeriodog_fx[nFFTpart + i], s2 ); /* hFdCngEnc->msPeriodog_fx_exp_fft */ + move32(); + } + } + /* exponent for entire msPeriodog vector */ + hFdCngEnc->msPeriodog_fx_exp = hFdCngEnc->msPeriodog_fx_exp_fft; + move16(); + + /* Compress MS inputs */ + compress_range( msPeriodog_fx, hFdCngEnc->msPeriodog_fx_exp, hFdCngEnc->msLogPeriodog_fx, hFdCngEnc->hFdCngCom->npart ); + + /* Call the minimum statistics routine for noise estimation */ + IF( element_mode > 0 ) + { + minimum_statistics_fx( + hFdCngEnc->hFdCngCom->npart, + nFFTpart, + hFdCngEnc->hFdCngCom->psize_norm, + hFdCngEnc->msLogPeriodog_fx, + hFdCngEnc->msNoiseFloor_32fx, /*32bit*/ + hFdCngEnc->msLogNoiseEst_32fx, /*32bit*/ + 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_fx( hFdCngEnc->msLogNoiseEst_32fx, hFdCngEnc->msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart ); + } + ELSE + { + minimum_statistics( + hFdCngEnc->hFdCngCom->npart, + nFFTpart, + hFdCngEnc->hFdCngCom->psize_norm, + hFdCngEnc->msLogPeriodog_fx, + hFdCngEnc->msNoiseFloor_fx, /*16bit*/ + hFdCngEnc->msLogNoiseEst_fx,/*16bit*/ + 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 ); + + /* Expand MS outputs */ + expand_range( hFdCngEnc->msLogNoiseEst_fx, hFdCngEnc->msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart ); + } + + return; +} +#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/ /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 0afc640bf..796303bcc 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -860,7 +860,11 @@ void pre_proc_front_ivas_fx( test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) && lr_vad_enabled && band_energies_LR_fx != NULL ) { +#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc + perform_noise_estimation_enc_fx( band_energies_LR_fx, sub( Q31, band_energies_LR_fx_q ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE, st->element_mode ); +#else perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, sub( Q31, band_energies_LR_fx_q ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); +#endif } ELSE { @@ -871,8 +875,11 @@ void pre_proc_front_ivas_fx( st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = sub( st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, norm ); move16(); } - +#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc + perform_noise_estimation_enc_fx( band_energies_fx, sub( Q31, q_band_energies ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE, st->element_mode ); +#else perform_noise_estimation_enc_ivas_fx( band_energies_fx, sub( Q31, q_band_energies ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); +#endif } } } diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 0f0cbddff..ee9c46094 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -323,7 +323,11 @@ void pre_proc_fx( resetFdCngEnc_fx( st ); +#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc + perform_noise_estimation_enc_fx( st->band_energies, st->band_energies_exp, enerBuffer, enerBuffer_exp, st->hFdCngEnc, 0, NULL, EVS_MONO ); +#else perform_noise_estimation_enc_fx( st->band_energies, st->band_energies_exp, enerBuffer, enerBuffer_exp, st->hFdCngEnc ); +#endif /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 2b644e164..397f91215 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1667,6 +1667,18 @@ void configureFdCngEnc_fx( #endif /* Perform noise estimation */ +#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc +void perform_noise_estimation_enc_fx( + Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ + Word16 band_energies_exp, + Word32 *enerBuffer, /* enerBuffer_exp */ + Word16 enerBuffer_exp, + HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + int element_mode /* i : is element EVS or IVAS */ +); +#else void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN exp_band_energies*/ Word16 exp_band_energies, @@ -1684,6 +1696,7 @@ void perform_noise_estimation_enc_ivas_fx( const Word32 input_Fs, /* i : input sampling rate Q0*/ CPE_ENC_HANDLE hCPE /* i : CPE encoder structure */ ); +#endif /* Adjust the noise estimator at the beginning of each CNG phase (encoder-side) */ Word16 AdjustFirstSID_fx( -- GitLab From 56c985d0b016074ddb8c1e815ecb1663470e1d80 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 18 Mar 2026 15:24:24 +0100 Subject: [PATCH 02/21] clang patch --- lib_enc/fd_cng_enc_fx.c | 24 +++++++++++------------- lib_enc/prot_fx_enc.h | 12 ++++++------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 9797f9282..096111473 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2482,14 +2482,14 @@ void perform_noise_estimation_enc_ivas_fx( #ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc void perform_noise_estimation_enc_fx( - Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ + Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, - Word32 *enerBuffer, /* enerBuffer_exp */ + Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, - HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ - const Word32 input_Fs, /* i : input sampling rate Q0*/ - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - int element_mode /* i : is element EVS or IVAS */ + HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + int element_mode /* i : is element EVS or IVAS */ ) { if ( element_mode == 0 ) @@ -2601,7 +2601,7 @@ void perform_noise_estimation_enc_fx( hFdCngEnc->hFdCngCom->exp_cldfb_periodog = max_exp; move16(); } - ELSE /*EVS_MONO*/ + ELSE /*EVS_MONO*/ { IF( numBands > 0 ) { @@ -2616,8 +2616,6 @@ void perform_noise_estimation_enc_fx( /* exponent for cldfb part of msPeriodog */ hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); - - } } @@ -2674,8 +2672,8 @@ void perform_noise_estimation_enc_fx( nFFTpart, hFdCngEnc->hFdCngCom->psize_norm, hFdCngEnc->msLogPeriodog_fx, - hFdCngEnc->msNoiseFloor_32fx, /*32bit*/ - hFdCngEnc->msLogNoiseEst_32fx, /*32bit*/ + hFdCngEnc->msNoiseFloor_32fx, /*32bit*/ + hFdCngEnc->msLogNoiseEst_32fx, /*32bit*/ hFdCngEnc->msAlpha_fx, hFdCngEnc->msPsd_fx, hFdCngEnc->msPsdFirstMoment_fx, @@ -2704,8 +2702,8 @@ void perform_noise_estimation_enc_fx( nFFTpart, hFdCngEnc->hFdCngCom->psize_norm, hFdCngEnc->msLogPeriodog_fx, - hFdCngEnc->msNoiseFloor_fx, /*16bit*/ - hFdCngEnc->msLogNoiseEst_fx,/*16bit*/ + hFdCngEnc->msNoiseFloor_fx, /*16bit*/ + hFdCngEnc->msLogNoiseEst_fx, /*16bit*/ hFdCngEnc->msAlpha_fx, hFdCngEnc->msPsd_fx, hFdCngEnc->msPsdFirstMoment_fx, diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 397f91215..8bea87736 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1669,14 +1669,14 @@ void configureFdCngEnc_fx( /* Perform noise estimation */ #ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc void perform_noise_estimation_enc_fx( - Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ + Word32 *band_energies, /* i : energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, - Word32 *enerBuffer, /* enerBuffer_exp */ + Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, - HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ - const Word32 input_Fs, /* i : input sampling rate Q0*/ - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - int element_mode /* i : is element EVS or IVAS */ + HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + int element_mode /* i : is element EVS or IVAS */ ); #else void perform_noise_estimation_enc_fx( -- GitLab From 5218830a0a5fc473bfef4029b214a79a61ee1ff8 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 18 Mar 2026 15:16:56 +0000 Subject: [PATCH 03/21] just trigger last pipelines --- lib_enc/fd_cng_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 096111473..754c4a22f 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2726,7 +2726,7 @@ void perform_noise_estimation_enc_fx( return; } -#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/ +#endif /*-------------------------------------------------------------------* -- GitLab From 90d6982543ce49fbf12fc1679b9f401a0fb60fe9 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 06:43:57 +0100 Subject: [PATCH 04/21] macro FIX_2485_HARMONIZE_minimum_statistics: harmonize minimum_statistics, inactive added old minimum_statistics_fx to #else path of issues' macro FIX_2485_HARMONIZE_minimum_statistics --- lib_com/fd_cng_com_fx.c | 810 ++++++++++++++++++++++++++++++++++++++++ lib_com/options.h | 1 + 2 files changed, 811 insertions(+) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 3dfe624dc..d34daf28b 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -487,6 +487,7 @@ void expand_range_var_exp( return; } +#ifndef FIX_2485_HARMONIZE_minimum_statistics /*------------------------------------------------------------------- * minimum_statistics() * @@ -1691,6 +1692,815 @@ void minimum_statistics_fx( assert( msNoiseEst[j] >= 0 /*0.0 Q15*/ ); } } +#else + +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 Q9*/ + Word16 *msPeriodog, /* i : Periodogram (energies) */ + Word32 *msNoiseFloor_buffer, /* i/o: Noise floors (energies) Q25*/ + Word32 *msNoiseEst_buffer, /* 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) */ + Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ + Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ + Word32 *msBminWin, /* o : Bias correction factors */ + Word32 *msBminSubWin, /* o : Bias correction factors */ + Word32 *msCurrentMin, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ + Word16 *msLocalMinFlag, /* i : Binary flag */ + Word16 *msNewMinFlag, /* i : Binary flag */ + Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ + Word16 *msPeriodogBufPtr, /* i/o: Counter */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 enc_dec, /* i : encoder/decoder indicator */ + const Word16 element_mode /* i : IVAS element mode type */ +) +{ + Word16 i, j, k, s, s1, s2, s3; + Word16 len2; + Word16 current_len; + Word16 start, stop, cnt; + Word16 totsize; + Word16 inv_totsize; + + Word32 tmp, tmp0, tmp1; + Word32 scalar, scalar2, scalar3; + Word32 snr; + Word32 msAlphaHatMin2; + Word32 BminCorr; + Word32 QeqInvAv; + Word32 *ptr; + Word32 *msPsdSum; + Word32 *msPeriodogSum; + + Word16 tmp16, tmp16_1; + Word16 beta; + Word16 slope; + Word16 QeqInv; + Word16 scalar16; + Word16 scalar216; + Word16 scalar316; + Word16 msM_win; + Word16 msM_subwin; + Word16 msAlphaCorAlpha; + Word16 msAlphaCorAlpha2; + Word16 msPeriodogSum16; + Word16 msNoiseFloor16_scalar; + +#ifdef FIX_2485_HARMONIZE_minimum_statistics + Word32 *msNoiseFloor_buffer32 = (Word32 *) msNoiseFloor_buffer; + Word16 *msNoiseFloor_buffer16 = (Word16 *) msNoiseFloor_buffer; + Word32 *msNoiseEst_buffer32 = (Word32 *) msNoiseEst_buffer; + Word16 *msNoiseEst_buffer16 = (Word16 *) msNoiseEst_buffer; + + + IF( element_mode == 0 ) + { + (void) enc_dec; + (void) hFdCngCom; + } +#endif + + len2 = i_mult( MSNUMSUBFR, len ); + + msM_win = hFdCngCom->msM_win; + move16(); + msM_subwin = hFdCngCom->msM_subwin; + move16(); + + msAlphaCorAlpha = MSALPHACORALPHA; + move16(); + msAlphaCorAlpha2 = MSALPHACORALPHA2; + move16(); + + msPsdSum = hFdCngCom->msPsdSum; + msPeriodogSum = hFdCngCom->msPeriodogSum; + + /* No minimum statistics at initialization */ + IF( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) + { +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msNoiseFloor_buffer16, len ); /* 6Q9 */ + Copy( msPeriodog, msNoiseEst_buffer16, len ); /* 6Q9 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ + } + ELSE + { + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseFloor_buffer32, len, Q16 ); /* Q25 */ + Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseEst_buffer32, len, Q16 ); /* Q25 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ + } +#else + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseFloor_buffer, len, Q16 ); /* Q25 */ + Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseEst_buffer, len, Q16 ); /* Q25 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ +#endif + + set32_fx( msPsdSecondMoment, 0l /*0.0 Q31*/, len ); + msPeriodogSum[0] = dotp_s_fx( msPeriodog, psize, lenFFT, CNG_HS ); + move32(); + msPsdSum[0] = msPeriodogSum[0]; /* 16Q15 */ + move32(); + + IF( LT_16( lenFFT, len ) ) + { + msPeriodogSum[1] = dotp_s_fx( msPeriodog + lenFFT, psize + lenFFT, sub( len, lenFFT ), CNG_HS ); + move32(); + msPsdSum[1] = msPeriodogSum[1]; /* 16Q15 */ + move32(); + } + + /* Increment frame counter at initialization */ + /* Some frames are sometimes zero at initialization => ignore them */ + IF( LT_16( msPeriodog[0], hFdCngCom->init_old ) ) + { + set32_fx( msCurrentMinOut, 2147483647l /*1.0 Q31*/, len ); /* 16Q15 */ + set32_fx( msCurrentMin, 2147483647l /*1.0 Q31*/, len ); /* 16Q15 */ + set32_fx( msMinBuf, 2147483647l /*1.0 Q31*/, len2 ); /* 16Q15 */ + set32_fx( msCurrentMinSubWindow, 2147483647l /*1.0 Q31*/, len ); /* 16Q15 */ + + hFdCngCom->msFrCnt_init_counter = add( hFdCngCom->msFrCnt_init_counter, 1 ); + move16(); + } + hFdCngCom->init_old = msPeriodog[0]; /* 6Q9 */ + move16(); + } + ELSE + { + /* Consider the FFT and CLDFB bands separately + - first iteration for FFT bins, + - second one for CLDFB bands in SWB mode */ + cnt = 0; + move16(); + start = 0; + move16(); + stop = lenFFT; + move16(); + totsize = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + WHILE( GT_16( stop, start ) ) + { + current_len = sub( stop, start ); + + /* Compute smoothed correction factor for PSD smoothing */ + + /* msPeriodogSum[cnt] with format 16Q15 */ + msPeriodogSum[cnt] = dotp_s_fx( msPeriodog + start, psize + start, current_len, CNG_HS ); + move32(); + + IF( msPeriodogSum[cnt] == 0 ) + { + hFdCngCom->msAlphaCor[cnt] = Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ); + move32(); + } + ELSE + { + /* calculate scalar with normalized msPeriodogSum[cnt], exponent -2*s1 */ + s1 = norm_l( msPeriodogSum[cnt] ); +#ifdef FIX_2485_HARMONIZE_minimum_statistics + msPeriodogSum16 = round_fx_sat( L_shl_sat( msPeriodogSum[cnt], s1 ) ); +#else + msPeriodogSum16 = round_fx_sat( L_shl( msPeriodogSum[cnt], s1 ) ); +#endif + scalar = L_mult( msPeriodogSum16, msPeriodogSum16 ); + + /* calculate difference, both elements in 16Q15 format, use absolute value + to avoid -1.0 x -1.0 multiplications later */ + scalar2 = L_abs( L_sub( msPsdSum[cnt], msPeriodogSum[cnt] ) ); + + s2 = WORD32_BITS - 1; + move16(); + if ( scalar2 != 0 ) + { + /* use absolute value to avoid -1.0 x -1.0 multiplications */ + s2 = norm_l( scalar2 ); + } + scalar216 = round_fx_sat( L_shl( scalar2, s2 ) ); + scalar2 = L_mult( scalar216, scalar216 ); + + /* find common exponent */ + tmp16_1 = sub( s1, s2 ); + tmp16 = s_min( shl( abs_s( tmp16_1 ), 1 ), WORD32_BITS - 1 ); + if ( tmp16_1 < 0 ) + { + scalar2 = L_shr( scalar2, tmp16 ); + } + if ( tmp16_1 > 0 ) + { + scalar = L_shr( scalar, tmp16 ); + } + + + /* add scalar and scalar2, avoid overflows */ + scalar = L_shr( scalar, 1 ); + scalar2 = L_shr( scalar2, 1 ); + scalar3 = L_add( scalar, scalar2 ); + + /* calculate division */ + scalar16 = BASOP_Util_Divide3232_uu_1616_Scale( scalar, scalar3, &s3 ); + s3 = s_max( s3, -( WORD16_BITS - 1 ) ); + scalar16 = shl( scalar16, s3 ); + scalar16 = s_max( scalar16, MSALPHACORMAX ); + +#ifdef FIX_2485_HARMONIZE_minimum_statistics + /*EVS: + hFdCngCom->msAlphaCor[cnt] = L_add( Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ), + L_mult( scalar16, msAlphaCorAlpha2 ) ); + */ +#endif + hFdCngCom->msAlphaCor[cnt] = Madd_32_16( L_mult( scalar16, msAlphaCorAlpha2 ), hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ); + move32(); + + } + + /* Compute SNR */ + + /* msPeriodogSum[cnt] with format 16Q15 */ + Word16 msNoiseFloor16tmp[NPART_SHAPING]; +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + snr = dotp_s_fx( msNoiseFloor_buffer16 + start, psize + start, current_len, CNG_HS ); + } + ELSE + { + IF( enc_dec == ENC ) + { + Copy_Scale_sig32_16( msNoiseFloor_buffer32, msNoiseFloor16tmp, NPART, 0 ); + } + ELSE + { + Copy_Scale_sig32_16( msNoiseFloor_buffer32, msNoiseFloor16tmp, NPART_SHAPING, 0 ); + } + snr = dotp_s_fx( &msNoiseFloor16tmp[start], psize + start, current_len, CNG_HS ); + } +#else + IF( enc_dec == ENC ) + { + Copy_Scale_sig32_16( msNoiseFloor_buffer, msNoiseFloor16tmp, NPART, 0 ); + } + ELSE + { + Copy_Scale_sig32_16( msNoiseFloor_buffer, msNoiseFloor16tmp, NPART_SHAPING, 0 ); + } + snr = dotp_s_fx( &msNoiseFloor16tmp[start], psize + start, current_len, CNG_HS ); +#endif + + IF( GT_32( L_shr( Mpy_32_16_1( msPsdSum[cnt], 18431 /*0.56246299817 Q15*/ ), 13 ), snr ) ) + { + tmp0 = BASOP_Util_Log2( msPsdSum[cnt] ); + tmp1 = BASOP_Util_Log2( snr ); + tmp1 = L_sub( tmp0, tmp1 ); + tmp1 = Mpy_32_16_1( tmp1, MSSNREXP ); + msAlphaHatMin2 = BASOP_Util_InvLog2( tmp1 ); + } + ELSE + { + msAlphaHatMin2 = MSALPHAHATMIN; + move32(); + } + scalar = Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], MSALPHAMAX ); + + FOR( j = start; j < stop; j++ ) + { + /* Compute optimal smoothing parameter for PSD estimation */ + test(); +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( ( scalar == 0 ) || ( element_mode == 0 ? msNoiseFloor_buffer16[j] : msNoiseFloor_buffer32[j] == 0 ) ) +#else + IF( ( scalar == 0 ) || ( msNoiseFloor_buffer[j] == 0 ) ) +#endif + { + msAlpha[j] = msAlphaHatMin2; + move32(); + } + ELSE + { + /* calculate scalar2 with normalized msNoiseFloor[j], exponent -2*s1 */ + s1 = WORD16_BITS - 1; + move16(); +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + if ( msNoiseFloor_buffer16[j] != 0 ) + { + s1 = norm_s( msNoiseFloor_buffer16[j] ); + } + msNoiseFloor16_scalar = shl( msNoiseFloor_buffer16[j], s1 ); + scalar2 = L_mult( msNoiseFloor16_scalar, msNoiseFloor16_scalar ); + + /* 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_buffer16[j] ) ); + } + ELSE + { + if ( msNoiseFloor16tmp[j] != 0 ) + { + s1 = norm_s( msNoiseFloor16tmp[j] ); + } + msNoiseFloor16_scalar = shl( msNoiseFloor16tmp[j], s1 ); + scalar2 = L_mult( msNoiseFloor16_scalar, msNoiseFloor16_scalar ); + + /* 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], msNoiseFloor16tmp[j] ) ); + } +#else + if ( msNoiseFloor16tmp[j] != 0 ) + { + s1 = norm_s( msNoiseFloor16tmp[j] ); + } + msNoiseFloor16_scalar = shl( msNoiseFloor16tmp[j], s1 ); + scalar2 = L_mult( msNoiseFloor16_scalar, msNoiseFloor16_scalar ); + + /* 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], msNoiseFloor16tmp[j] ) ); +#endif + s2 = WORD16_BITS - 1; + move16(); + if ( scalar316 != 0 ) + { + /* use absolute value to avoid -1.0 x -1.0 multiplications */ + s2 = norm_s( scalar316 ); + } + scalar316 = shl( scalar316, s2 ); + scalar3 = L_mult( scalar316, scalar316 ); + + /* find common exponent */ + tmp16_1 = sub( s1, s2 ); + tmp16 = s_min( shl( abs_s( tmp16_1 ), 1 ), WORD32_BITS - 1 ); + if ( tmp16_1 < 0 ) + { + scalar3 = L_shr( scalar3, tmp16 ); + } + if ( tmp16_1 > 0 ) + { + scalar2 = L_shr( scalar2, tmp16 ); + } + + /* add scalar2 and scalar3, avoid overflows */ + scalar2 = L_shr( scalar2, 1 ); + scalar3 = L_shr( scalar3, 1 ); + scalar3 = L_add( scalar2, scalar3 ); + + /* calculate division */ + tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( scalar2, scalar3, &s3 ); + scalar2 = Mpy_32_16_1( scalar, tmp16 ); + s3 = s_max( s3, -( WORD32_BITS - 1 ) ); + scalar2 = L_shl( scalar2, s3 ); + msAlpha[j] = L_max( scalar2, msAlphaHatMin2 ); + move32(); + } + + /* Compute the PSD (smoothed periodogram) in each band */ +#ifdef FIX_2485_HARMONIZE_minimum_statistics + /*EVS: + msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), + Mpy_32_16_1( L_sub( 2147483647l, msAlpha[j] ), msPeriodog[j] ) ) ); + */ +#endif + msPsd[j] = round_fx( Madd_32_16( Mpy_32_16_1( msAlpha[j], msPsd[j] ), L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ); + + move16(); + } + msPsdSum[cnt] = dotp_s_fx( msPsd + start, psize + start, current_len, CNG_HS ); + move32(); + + QeqInvAv = 0l /*0.0 Q31*/; + move32(); + + /* scalar: 7Q24 format */ + tmp = 1191182336l /*(float)(MSNUMSUBFR*MSSUBFRLEN)-1.0 Q24*/; + move32(); + scalar = L_sub( tmp, L_mult( round_fx( tmp ), msM_win ) ); + + /* scalar2: 4Q27 format */ + tmp = 1476395008l /*(float)MSSUBFRLEN-1.0 Q27*/; + move32(); + scalar2 = L_sub( tmp, L_mult( round_fx( tmp ), msM_subwin ) ); + + FOR( j = start; j < stop; j++ ) + { + /* Compute variance of PSD */ + tmp = L_min( msAlpha[j], MSBETAMAX_SQRT ); + + s1 = WORD32_BITS - 1; + move16(); + if ( tmp != 0 ) + { + s1 = norm_l( tmp ); + } + s2 = shl( s1, 1 ); + + s2 = s_min( s2, WORD32_BITS - 1 ); + + /* beta: scaled by s2 */ + tmp16 = round_fx_sat( L_shl( tmp, s1 ) ); + beta = mult_r( tmp16, tmp16 ); + + /* scalar3: scaled by s3 */ + scalar3 = L_sub( L_deposit_l( msPsd[j] ), L_deposit_l( msPsdFirstMoment[j] ) ); + s3 = norm_l( scalar3 ); + scalar3 = L_shl( scalar3, s3 ); + + /* msPsdFirstMoment: 6Q9 */ + tmp = L_msu( L_mult( beta, msPsdFirstMoment[j] ), beta, msPsd[j] ); + msPsdFirstMoment[j] = add( round_fx( L_shr( tmp, s2 ) ), msPsd[j] ); + move16(); + + /* msPsdSecondMoment: 12Q19 */ + tmp0 = L_shr( Mpy_32_16_r( msPsdSecondMoment[j], beta ), s2 ); + tmp1 = Mpy_32_32( scalar3, scalar3 ); + tmp1 = L_shr( L_sub( tmp1, L_shr( Mpy_32_16_r( tmp1, beta ), s2 ) ), sub( shl( s3, 1 ), 32 ) ); + msPsdSecondMoment[j] = L_add( tmp0, tmp1 ); + move32(); + + /* Compute inverse of amount of degrees of freedom */ + QeqInv = MSQEQINVMAX; + move16(); +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( ( element_mode == 0 ? msNoiseFloor_buffer16[j] : msNoiseFloor_buffer32[j] ) != 0 ) +#else + IF( msNoiseFloor_buffer[j] != 0 /*0.0 Q15*/ ) +#endif + { +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + tmp = L_mult( msNoiseFloor_buffer16[j], msNoiseFloor_buffer16[j] ); + } + ELSE + { + tmp = Mpy_32_32( msNoiseFloor_buffer32[j], msNoiseFloor_buffer32[j] ); + } +#else + tmp = Mpy_32_32( msNoiseFloor_buffer[j], msNoiseFloor_buffer[j] ); +#endif + 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 ) ); + if ( s < 0 ) + { + QeqInv = shl( tmp16, s ); + } + QeqInv = s_min( QeqInv, MSQEQINVMAX ); + } + QeqInvAv = L_add( QeqInvAv, L_mult( QeqInv, psize[j] ) ); + + /* Compute bias correction Bmin */ + tmp0 = Mpy_32_16_1( scalar, QeqInv ); +#ifdef FIX_2485_HARMONIZE_minimum_statistics +/*EVS: + tmp1 = L_sub( 1073741824l, L_mult( msM_win, QeqInv ) ); + */ +#endif + tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_win, QeqInv ); + tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); + msBminWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), add( s, 7 - 4 ) ) ); + move32(); + + tmp0 = Mpy_32_16_1( scalar2, QeqInv ); + tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_subwin, QeqInv ); +#ifdef FIX_2485_HARMONIZE_minimum_statistics +/*EVS: + tmp1 = L_sub( 1073741824l, L_mult( msM_subwin, QeqInv ) ); + */ +#endif + tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); + msBminSubWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), s ) ); + move32(); + } + + inv_totsize = BASOP_Util_Divide3232_uu_1616_Scale( 1, totsize, &s ); + QeqInvAv = Mpy_32_16_1( QeqInvAv, inv_totsize ); + QeqInvAv = L_shl( QeqInvAv, s ); + hFdCngCom->msQeqInvAv[cnt] = QeqInvAv; + move32(); + + /* New minimum? */ + + /* exponent QeqInvAv: CNG_S, exponent MSAV: (4>>1) */ + s = CNG_S + 2 * MSAV_EXP; + move16(); + BminCorr = Mpy_32_16_1( Sqrt32( QeqInvAv, &s ), MSAV ); + BminCorr = L_shl( BminCorr, sub( s, 1 ) ); + + /* exponent BminCorr: 1 */ + BminCorr = L_add( BminCorr, 1073741824l /*0.5 Q31*/ ); + + FOR( j = start; j < stop; j++ ) + { + /* exponent scalar: CNG_S+1 */ + scalar = Mpy_32_16_1( BminCorr, msPsd[j] ); + + /* exponent scalar2: CNG_S+1+4 */ + scalar2 = Mpy_32_32( scalar, msBminWin[j] ); + + msNewMinFlag[j] = 0; + move16(); + IF( LT_32( scalar2, msCurrentMin[j] ) /*0.0 Q31*/ ) + { + msNewMinFlag[j] = 1; + move16(); + /* exponent msCurrentMin[j]: CNG_S+1+4 */ + msCurrentMin[j] = scalar2; + move32(); + /* exponent msCurrentMinSubWindow[j]: CNG_S */ + BASOP_SATURATE_WARNING_OFF_EVS; + msCurrentMinSubWindow[j] = L_shl_sat( Mpy_32_32( scalar, msBminSubWin[j] ), 5 ); + move32(); + BASOP_SATURATE_WARNING_ON_EVS; + } + } + + /* This is used later to identify local minima */ + IF( GE_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) + { + FOR( i = 0; i < 3; i++ ) + { + IF( LT_32( hFdCngCom->msQeqInvAv[cnt], L_shr( L_deposit_h( msQeqInvAv_thresh[i] ), CNG_S ) ) /*0.0 Q31*/ ) + { + BREAK; + } + } + /* format 1Q30 */ + hFdCngCom->msSlope[cnt] = msNoiseSlopeMax[i]; + move32(); + } + + /* Consider the FFT and CLDFB bands separately */ + start = stop; + move16(); + stop = len; + move16(); + totsize = sub( hFdCngCom->stopBand, hFdCngCom->stopFFTbin ); + cnt = add( cnt, 1 ); + } /*while (stop > start)*/ + + /* Update minimum between sub windows */ + test(); + IF( GT_16( hFdCngCom->msFrCnt, 1 ) && LT_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) + { + FOR( j = 0; j < len; j++ ) + { + if ( msNewMinFlag[j] > 0 ) + { + msLocalMinFlag[j] = 1; + move16(); + } + if ( LT_32( msCurrentMinSubWindow[j], msCurrentMinOut[j] ) /*0.0 Q31*/ ) + { + /* msCurrentMinOut[j] scaled with CNG_S */ + msCurrentMinOut[j] = msCurrentMinSubWindow[j]; + move32(); + } + } + /* Get the current noise floor */ +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + Copy_Scale_sig_32_16( msCurrentMinOut, msNoiseFloor_buffer16, len, -16 ); + } + ELSE + { + Copy32( msCurrentMinOut, msNoiseFloor_buffer32, len ); + } +#else + Copy32( msCurrentMinOut, msNoiseFloor_buffer, len ); +#endif + } + ELSE /* sub window complete */ + { + IF( GE_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) + { + /* Collect buffers */ + Copy32( msCurrentMinSubWindow, msMinBuf + len * hFdCngCom->msMinBufferPtr, len ); + + /* Compute minimum among all buffers */ + Copy32( msMinBuf, msCurrentMinOut, len ); + ptr = msMinBuf + len; + FOR( i = 1; i < MSNUMSUBFR; i++ ) + { + FOR( j = 0; j < len; j++ ) + { + if ( LT_32( *ptr, msCurrentMinOut[j] ) /*0.0 Q31*/ ) + { + msCurrentMinOut[j] = *ptr; + move32(); + } + ptr++; + } + } + + /* Take over local minima */ + slope = hFdCngCom->msSlope[0]; + move16(); + FOR( j = 0; j < len; j++ ) + { + if ( EQ_16( j, lenFFT ) ) + { + slope = hFdCngCom->msSlope[1]; + move16(); + } + test(); + test(); + test(); + IF( ( msLocalMinFlag[j] != 0 ) && ( msNewMinFlag[j] == 0 ) && ( LT_32( L_shr( msCurrentMinSubWindow[j], 1 ), Mpy_32_16_1( msCurrentMinOut[j], slope ) ) /*0.0 Q31*/ ) && ( GT_32( msCurrentMinSubWindow[j], msCurrentMinOut[j] ) /*0.0 Q31*/ ) ) + { + msCurrentMinOut[j] = msCurrentMinSubWindow[j]; + move32(); + i = j; + move16(); + FOR( k = 0; k < MSNUMSUBFR; k++ ) + { + msMinBuf[i] = msCurrentMinOut[j]; + move32(); + i = add( i, len ); + } + } + } + + /* Reset */ + set16_fx( msLocalMinFlag, 0, len ); + set32_fx( msCurrentMin, 2147483647l /*1.0 Q31*/, len ); + +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + Copy_Scale_sig_32_16( msCurrentMinOut, msNoiseFloor_buffer16, len, -16 ); + } + ELSE + { + Copy32( msCurrentMinOut, msNoiseFloor_buffer32, len ); + } +#else + Copy32( msCurrentMinOut, msNoiseFloor_buffer, len ); +#endif + } + } + + + /* Detect sudden offsets based on the FFT bins (core bandwidth) */ + IF( GT_32( Mpy_32_16_1( msPsdSum[0], 655 /*0.02 Q15*/ ), msPeriodogSum[0] ) /*0.0 Q31*/ ) + { + IF( hFdCngCom->offsetflag > 0 ) + { + Copy( msPeriodog, msPsd, len ); + FOR( j = 0; j < len; j++ ) + { + msCurrentMinOut[j] = L_deposit_h( msPeriodog[j] ); + move32(); + } + set32_fx( hFdCngCom->msAlphaCor, 2147483647l /*1.0 Q31*/, cnt ); + set32_fx( msAlpha, 0l /*0.0 Q31*/, len ); + Copy( msPeriodog, msPsdFirstMoment, len ); + set32_fx( msPsdSecondMoment, 0l /*0.0 Q31*/, len ); + + msPsdSum[0] = dotp_s_fx( msPeriodog, psize, lenFFT, CNG_HS ); + move32(); + IF( LT_16( lenFFT, len ) ) + { + msPsdSum[1] = dotp_s_fx( msPeriodog + lenFFT, psize + lenFFT, sub( len, lenFFT ), CNG_HS ); + move32(); + } + } + hFdCngCom->offsetflag = 1; + move16(); + } + ELSE + { + hFdCngCom->offsetflag = 0; + move16(); + } + + + /* Increment frame counter */ + IF( EQ_16( hFdCngCom->msFrCnt, MSSUBFRLEN ) ) + { + hFdCngCom->msFrCnt = 1; + move16(); + hFdCngCom->msMinBufferPtr = add( hFdCngCom->msMinBufferPtr, 1 ); + move16(); + if ( EQ_16( hFdCngCom->msMinBufferPtr, MSNUMSUBFR ) ) + { + hFdCngCom->msMinBufferPtr = 0; + move16(); + } + } + ELSE + { + hFdCngCom->msFrCnt = add( hFdCngCom->msFrCnt, 1 ); + move16(); + } + Word64 tmp64; + /* Smooth noise estimate during CNG phases */ +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + FOR( j = 0; j < len; j++ ) + { + msNoiseEst_buffer16[j] = round_fx( L_mac( L_mult( 31130 /*0.95 Q15*/, msNoiseEst_buffer16[j] ), 1638 /*0.05 Q15*/, msNoiseFloor_buffer16[j] ) ); + move16(); + } + } + ELSE + { + Word64 tmp64; + FOR( j = 0; j < len; j++ ) + { + tmp64 = W_add( W_mult_32_16( msNoiseEst_buffer32[j], 31130 /*0.95 Q15*/ ), W_mult_32_16( msNoiseFloor_buffer32[j], 1638 /*0.05 Q15*/ ) ); + msNoiseEst_buffer32[j] = W_extract_h( W_shl( tmp64, 16 ) ); // Q25 + move32(); + } + } +#else + Word64 tmp64; + FOR( j = 0; j < len; j++ ) + { + tmp64 = W_add( W_mult_32_16( msNoiseEst_buffer[j], 31130 /*0.95 Q15*/ ), W_mult_32_16( msNoiseFloor_buffer[j], 1638 /*0.05 Q15*/ ) ); + msNoiseEst_buffer[j] = W_extract_h( W_shl( tmp64, 16 ) ); // Q25 + move32(); + } +#endif + } + +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode > 0 ) + { + IF( EQ_16( enc_dec, DEC ) && EQ_16( element_mode, IVAS_CPE_TD ) ) + { + // v_multc(msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING); + v_multc_att32( msNoiseEst_buffer32, 23142, msNoiseEst_buffer32, NPART_SHAPING ); + } + } +#else + IF( EQ_16( enc_dec, DEC ) && EQ_16( element_mode, IVAS_CPE_TD ) ) + { + // v_multc(msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING); + v_multc_att32( msNoiseEst_buffer, 23142, msNoiseEst_buffer, NPART_SHAPING ); + } +#endif + /* Collect buffers */ + Copy( msPeriodog, msPeriodogBuf + len * ( *msPeriodogBufPtr ), len ); + + *msPeriodogBufPtr = add( *msPeriodogBufPtr, 1 ); + move16(); + if ( EQ_16( *msPeriodogBufPtr, MSBUFLEN ) ) + { + ( *msPeriodogBufPtr ) = 0; + move16(); + } + + /* Upper limit the noise floors with the averaged input energy */ + FOR( j = 0; j < len; j++ ) + { + scalar = L_mult( msPeriodogBuf[j], 6554 /*1.0/MSBUFLEN Q15*/ ); + + FOR( i = j + len; i < MSBUFLEN * len; i += len ) + { + scalar = L_mac( scalar, msPeriodogBuf[i], 6554 /*1.0/MSBUFLEN Q15*/ ); + } +#ifdef FIX_2485_HARMONIZE_minimum_statistics + IF( element_mode == 0 ) + { + scalar16 = round_fx( scalar ); + if ( GT_16( msNoiseEst_buffer16[j], scalar16 ) /*0.0 Q15*/ ) + { + msNoiseEst_buffer16[j] = scalar16; + move16(); + } + } + ELSE + { + if ( GT_32( msNoiseEst_buffer32[j], scalar ) /*0.0 Q15*/ ) + { + msNoiseEst_buffer32[j] = scalar; + move32(); + } + } +#else + if ( GT_32( msNoiseEst_buffer[j], scalar ) /*0.0 Q15*/ ) + { + msNoiseEst_buffer[j] = scalar; + move32(); + } +#endif + assert( ( element_mode == 0 ? ( msNoiseEst_buffer16[j] ) : ( msNoiseEst_buffer32[j] ) ) >= 0 /*0.0 Q15*/ ); + } +} + +#endif /*FIX_2485_HARMONIZE_minimum_statistics*/ + /*------------------------------------------------------------------- * apply_scale() * diff --git a/lib_com/options.h b/lib_com/options.h index 8d309d1d3..1b6a7a724 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -100,6 +100,7 @@ #define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ #define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ +#define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ /* #################### End BE switches ################################## */ -- GitLab From 478bb44214a32ba6401b1010187624d2e9892922 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 08:11:42 +0100 Subject: [PATCH 05/21] clang patch --- lib_com/fd_cng_com_fx.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index d34daf28b..1004e0ae9 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1786,23 +1786,23 @@ void minimum_statistics_fx( #ifdef FIX_2485_HARMONIZE_minimum_statistics IF( element_mode == 0 ) { - Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ Copy( msPeriodog, msNoiseFloor_buffer16, len ); /* 6Q9 */ Copy( msPeriodog, msNoiseEst_buffer16, len ); /* 6Q9 */ - Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ } ELSE { - Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseFloor_buffer32, len, Q16 ); /* Q25 */ Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseEst_buffer32, len, Q16 ); /* Q25 */ - Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ } #else - Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseFloor_buffer, len, Q16 ); /* Q25 */ Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseEst_buffer, len, Q16 ); /* Q25 */ - Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ #endif set32_fx( msPsdSecondMoment, 0l /*0.0 Q31*/, len ); @@ -1918,7 +1918,6 @@ void minimum_statistics_fx( #endif hFdCngCom->msAlphaCor[cnt] = Madd_32_16( L_mult( scalar16, msAlphaCorAlpha2 ), hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ); move32(); - } /* Compute SNR */ @@ -2064,12 +2063,12 @@ void minimum_statistics_fx( /* Compute the PSD (smoothed periodogram) in each band */ #ifdef FIX_2485_HARMONIZE_minimum_statistics - /*EVS: + /*EVS: msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), Mpy_32_16_1( L_sub( 2147483647l, msAlpha[j] ), msPeriodog[j] ) ) ); */ #endif - msPsd[j] = round_fx( Madd_32_16( Mpy_32_16_1( msAlpha[j], msPsd[j] ), L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ); + msPsd[j] = round_fx( Madd_32_16( Mpy_32_16_1( msAlpha[j], msPsd[j] ), L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ); move16(); } -- GitLab From 7dbedc02e13638da1cc5a5c8d70b5265b68e8375 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 09:21:25 +0100 Subject: [PATCH 06/21] FIX_2485_HARMONIZE_minimum_statistics: some more fixes --- lib_com/fd_cng_com_fx.c | 50 ++++++++++++++++++++--------------------- lib_com/prot_fx.h | 28 +++++++++++++++++++++++ lib_dec/fd_cng_dec_fx.c | 27 ++++++++++++++++++++++ lib_enc/fd_cng_enc_fx.c | 41 ++++++++++++++++++++++++++++++++- 4 files changed, 120 insertions(+), 26 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 10d227a21..2c3a212e5 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1692,29 +1692,29 @@ void minimum_statistics_fx( #else 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 Q9*/ - Word16 *msPeriodog, /* i : Periodogram (energies) */ - Word32 *msNoiseFloor_buffer, /* i/o: Noise floors (energies) Q25*/ - Word32 *msNoiseEst_buffer, /* 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) */ - Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ - Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ - Word32 *msBminWin, /* o : Bias correction factors */ - Word32 *msBminSubWin, /* o : Bias correction factors */ - Word32 *msCurrentMin, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ - Word16 *msLocalMinFlag, /* i : Binary flag */ - Word16 *msNewMinFlag, /* i : Binary flag */ - Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ - Word16 *msPeriodogBufPtr, /* i/o: Counter */ - HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 enc_dec, /* i : encoder/decoder indicator */ - const Word16 element_mode /* i : IVAS element mode type */ + Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ + Word16 lenFFT, /* i : Number of FFT partitions */ + Word16 *psize, /* i : Partition sizes, fractional Q9*/ + Word16 *msPeriodog, /* i : Periodogram (energies) */ + void *msNoiseFloor_buffer, /* i/o: Noise floors (energies) Q25*/ + void *msNoiseEst_buffer, /* 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) */ + Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ + Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ + Word32 *msBminWin, /* o : Bias correction factors */ + Word32 *msBminSubWin, /* o : Bias correction factors */ + Word32 *msCurrentMin, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ + Word16 *msLocalMinFlag, /* i : Binary flag */ + Word16 *msNewMinFlag, /* i : Binary flag */ + Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ + Word16 *msPeriodogBufPtr, /* i/o: Counter */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 enc_dec, /* i : encoder/decoder indicator */ + const Word16 element_mode /* i : IVAS element mode type */ ) { Word16 i, j, k, s, s1, s2, s3; @@ -2398,8 +2398,8 @@ void minimum_statistics_fx( hFdCngCom->msFrCnt = add( hFdCngCom->msFrCnt, 1 ); move16(); } - Word64 tmp64; - /* Smooth noise estimate during CNG phases */ + + /* Smooth noise estimate during CNG phases */ #ifdef FIX_2485_HARMONIZE_minimum_statistics IF( element_mode == 0 ) { diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index de383d0a7..7226c181f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4585,6 +4585,33 @@ void expand_range_var_exp( Word16 *out_exp, const Word16 len ); +#ifdef FIX_2485_HARMONIZE_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 Q9*/ + Word16 *msPeriodog, /* i : Periodogram (energies) */ + void *msNoiseFloor_buffer, /* i/o: Noise floors (energies) Q25*/ + void *msNoiseEst_buffer, /* 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) */ + Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ + Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ + Word32 *msBminWin, /* o : Bias correction factors */ + Word32 *msBminSubWin, /* o : Bias correction factors */ + Word32 *msCurrentMin, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ + Word16 *msLocalMinFlag, /* i : Binary flag */ + Word16 *msNewMinFlag, /* i : Binary flag */ + Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ + Word16 *msPeriodogBufPtr, /* i/o: Counter */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 enc_dec, /* i : encoder/decoder indicator */ + const Word16 element_mode /* i : IVAS element mode type */ + ); +#else void minimum_statistics( Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ Word16 lenFFT, /* i : Number of FFT partitions */ @@ -4634,6 +4661,7 @@ void minimum_statistics_fx( const Word16 enc_dec, /* i : encoder/decoder indicator */ const Word16 element_mode /* i : IVAS element mode type */ ); +#endif /* Apply bitrate-dependant scale */ void apply_scale( diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 97f53dfb6..eb52090bf 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1280,6 +1280,32 @@ void perform_noise_estimation_dec_fx( compress_range( hFdCngDec->msPeriodog, hFdCngDec->msPeriodog_exp, hFdCngDec->msLogPeriodog, npart ); /* Call the minimum statistics routine for noise estimation */ +#ifdef FIX_2485_HARMONIZE_minimum_statistics + minimum_statistics_fx( + npart, + nFFTpart, + psize_norm, + hFdCngDec->msLogPeriodog, + hFdCngDec->msNoiseFloor, + hFdCngDec->msLogNoiseEst, + hFdCngDec->msAlpha, + hFdCngDec->msPsd, + hFdCngDec->msPsdFirstMoment, + hFdCngDec->msPsdSecondMoment, + hFdCngDec->msMinBuf, + hFdCngDec->msBminWin, + hFdCngDec->msBminSubWin, + hFdCngDec->msCurrentMin, + hFdCngDec->msCurrentMinOut, + hFdCngDec->msCurrentMinSubWindow, + hFdCngDec->msLocalMinFlag, + hFdCngDec->msNewMinFlag, + hFdCngDec->msPeriodogBuf, + &( hFdCngDec->msPeriodogBufPtr ), + hFdCngDec->hFdCngCom, + 0, + 0 ); +#else minimum_statistics( npart, nFFTpart, @@ -1302,6 +1328,7 @@ void perform_noise_estimation_dec_fx( hFdCngDec->msPeriodogBuf, &( hFdCngDec->msPeriodogBufPtr ), hFdCngDec->hFdCngCom ); +#endif /* Expand MS outputs */ expand_range( hFdCngDec->msLogNoiseEst, hFdCngDec->msNoiseEst, &hFdCngDec->msNoiseEst_exp, npart ); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 754c4a22f..064733735 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2665,6 +2665,44 @@ void perform_noise_estimation_enc_fx( compress_range( msPeriodog_fx, hFdCngEnc->msPeriodog_fx_exp, hFdCngEnc->msLogPeriodog_fx, hFdCngEnc->hFdCngCom->npart ); /* Call the minimum statistics routine for noise estimation */ +#ifdef FIX_2485_HARMONIZE_minimum_statistics + minimum_statistics_fx( + hFdCngEnc->hFdCngCom->npart, + nFFTpart, + hFdCngEnc->hFdCngCom->psize_norm, + hFdCngEnc->msLogPeriodog_fx, + ( element_mode == 0 ) ? ( (void *) hFdCngEnc->msNoiseFloor_fx ) : ( (void *) hFdCngEnc->msNoiseFloor_32fx ), + ( element_mode == 0 ) ? ( (void *) hFdCngEnc->msLogNoiseEst_fx ) : ( (void *) hFdCngEnc->msLogNoiseEst_32fx ), + 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, + ( element_mode == 0 ) ? ( 0 ) : ( ENC ), + ( element_mode == 0 ) ? ( 0 ) : ( ( hCPE == NULL ) ? 0 : hCPE->element_mode ) + ); + + + /* Expand MS outputs */ + IF( element_mode > 0 ) + { + expand_range_fx( hFdCngEnc->msLogNoiseEst_32fx, hFdCngEnc->msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart ); + } + ELSE + { + expand_range( hFdCngEnc->msLogNoiseEst_fx, hFdCngEnc->msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart ); + } +#else IF( element_mode > 0 ) { minimum_statistics_fx( @@ -2723,10 +2761,11 @@ void perform_noise_estimation_enc_fx( /* Expand MS outputs */ expand_range( hFdCngEnc->msLogNoiseEst_fx, hFdCngEnc->msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart ); } +#endif /*FIX_2485_HARMONIZE_minimum_statistics*/ return; } -#endif +#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/ /*-------------------------------------------------------------------* -- GitLab From aaf7a501b93df38b7c088e3050957a8dc88f6880 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 09:38:13 +0100 Subject: [PATCH 07/21] clang patch --- lib_com/fd_cng_com_fx.c | 48 ++++++++++++++++++++--------------------- lib_com/prot_fx.h | 4 ++-- lib_enc/fd_cng_enc_fx.c | 5 ++--- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 2c3a212e5..2fff71dcc 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1692,29 +1692,29 @@ void minimum_statistics_fx( #else 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 Q9*/ - Word16 *msPeriodog, /* i : Periodogram (energies) */ - void *msNoiseFloor_buffer, /* i/o: Noise floors (energies) Q25*/ - void *msNoiseEst_buffer, /* 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) */ - Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ - Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ - Word32 *msBminWin, /* o : Bias correction factors */ - Word32 *msBminSubWin, /* o : Bias correction factors */ - Word32 *msCurrentMin, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ - Word16 *msLocalMinFlag, /* i : Binary flag */ - Word16 *msNewMinFlag, /* i : Binary flag */ - Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ - Word16 *msPeriodogBufPtr, /* i/o: Counter */ - HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 enc_dec, /* i : encoder/decoder indicator */ - const Word16 element_mode /* i : IVAS element mode type */ + Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ + Word16 lenFFT, /* i : Number of FFT partitions */ + Word16 *psize, /* i : Partition sizes, fractional Q9*/ + Word16 *msPeriodog, /* i : Periodogram (energies) */ + void *msNoiseFloor_buffer, /* i/o: Noise floors (energies) Q25*/ + void *msNoiseEst_buffer, /* 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) */ + Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ + Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ + Word32 *msBminWin, /* o : Bias correction factors */ + Word32 *msBminSubWin, /* o : Bias correction factors */ + Word32 *msCurrentMin, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ + Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ + Word16 *msLocalMinFlag, /* i : Binary flag */ + Word16 *msNewMinFlag, /* i : Binary flag */ + Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ + Word16 *msPeriodogBufPtr, /* i/o: Counter */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 enc_dec, /* i : encoder/decoder indicator */ + const Word16 element_mode /* i : IVAS element mode type */ ) { Word16 i, j, k, s, s1, s2, s3; @@ -2399,7 +2399,7 @@ void minimum_statistics_fx( move16(); } - /* Smooth noise estimate during CNG phases */ + /* Smooth noise estimate during CNG phases */ #ifdef FIX_2485_HARMONIZE_minimum_statistics IF( element_mode == 0 ) { diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 7226c181f..9b6df5a8f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4587,7 +4587,7 @@ void expand_range_var_exp( #ifdef FIX_2485_HARMONIZE_minimum_statistics void minimum_statistics_fx( - Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ + Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ Word16 lenFFT, /* i : Number of FFT partitions */ Word16 *psize, /* i : Partition sizes, fractional Q9*/ Word16 *msPeriodog, /* i : Periodogram (energies) */ @@ -4610,7 +4610,7 @@ void minimum_statistics_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 enc_dec, /* i : encoder/decoder indicator */ const Word16 element_mode /* i : IVAS element mode type */ - ); +); #else void minimum_statistics( Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 064733735..e20a632e1 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2689,10 +2689,9 @@ void perform_noise_estimation_enc_fx( &( hFdCngEnc->msPeriodogBufPtr ), hFdCngEnc->hFdCngCom, ( element_mode == 0 ) ? ( 0 ) : ( ENC ), - ( element_mode == 0 ) ? ( 0 ) : ( ( hCPE == NULL ) ? 0 : hCPE->element_mode ) - ); + ( element_mode == 0 ) ? ( 0 ) : ( ( hCPE == NULL ) ? 0 : hCPE->element_mode ) ); + - /* Expand MS outputs */ IF( element_mode > 0 ) { -- GitLab From 30e0e6d076e69b72919bb2426a7b0e9721017084 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 09:54:16 +0100 Subject: [PATCH 08/21] macro FIX_2485_HARMONIZE_minimum_statistics_EVSmode : use old evs code in some minor places --- lib_com/fd_cng_com_fx.c | 29 +++++++++++++---------------- lib_com/options.h | 1 + 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 2fff71dcc..44bee9b70 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1907,13 +1907,13 @@ void minimum_statistics_fx( scalar16 = shl( scalar16, s3 ); scalar16 = s_max( scalar16, MSALPHACORMAX ); -#ifdef FIX_2485_HARMONIZE_minimum_statistics - /*EVS: +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) hFdCngCom->msAlphaCor[cnt] = L_add( Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ), L_mult( scalar16, msAlphaCorAlpha2 ) ); - */ -#endif +#else hFdCngCom->msAlphaCor[cnt] = Madd_32_16( L_mult( scalar16, msAlphaCorAlpha2 ), hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ); +#endif + move32(); } @@ -2059,13 +2059,12 @@ void minimum_statistics_fx( } /* Compute the PSD (smoothed periodogram) in each band */ -#ifdef FIX_2485_HARMONIZE_minimum_statistics - /*EVS: +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), Mpy_32_16_1( L_sub( 2147483647l, msAlpha[j] ), msPeriodog[j] ) ) ); - */ -#endif +#else msPsd[j] = round_fx( Madd_32_16( Mpy_32_16_1( msAlpha[j], msPsd[j] ), L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ); +#endif move16(); } @@ -2155,24 +2154,22 @@ void minimum_statistics_fx( /* Compute bias correction Bmin */ tmp0 = Mpy_32_16_1( scalar, QeqInv ); -#ifdef FIX_2485_HARMONIZE_minimum_statistics -/*EVS: +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) tmp1 = L_sub( 1073741824l, L_mult( msM_win, QeqInv ) ); - */ -#endif +#else tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_win, QeqInv ); +#endif tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); msBminWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), add( s, 7 - 4 ) ) ); move32(); tmp0 = Mpy_32_16_1( scalar2, QeqInv ); tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_subwin, QeqInv ); -#ifdef FIX_2485_HARMONIZE_minimum_statistics -/*EVS: +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) tmp1 = L_sub( 1073741824l, L_mult( msM_subwin, QeqInv ) ); - */ -#endif +#else tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); +#endif msBminSubWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), s ) ); move32(); } diff --git a/lib_com/options.h b/lib_com/options.h index 0f1512191..615e4935e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,6 +91,7 @@ #define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ #define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ +#define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code*/ #define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ #define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ -- GitLab From f9a5c270b3907ce3eb868797eabb85d86020031b Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 09:57:32 +0100 Subject: [PATCH 09/21] clang patch --- lib_com/fd_cng_com_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 44bee9b70..124676a7e 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1913,7 +1913,7 @@ void minimum_statistics_fx( #else hFdCngCom->msAlphaCor[cnt] = Madd_32_16( L_mult( scalar16, msAlphaCorAlpha2 ), hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ); #endif - + move32(); } -- GitLab From 676884a3fe4141f383d8c31211eec8f4db8c3a39 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 10:31:15 +0100 Subject: [PATCH 10/21] fix bug and insert check for asserts --- lib_com/fd_cng_com_fx.c | 10 ++++++---- lib_com/options.h | 1 + lib_dec/fd_cng_dec_fx.c | 3 +++ lib_enc/fd_cng_enc_fx.c | 3 +++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 124676a7e..6a3da1ce1 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1970,7 +1970,7 @@ void minimum_statistics_fx( /* Compute optimal smoothing parameter for PSD estimation */ test(); #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( ( scalar == 0 ) || ( element_mode == 0 ? msNoiseFloor_buffer16[j] : msNoiseFloor_buffer32[j] == 0 ) ) + IF( ( scalar == 0 ) || ( ( element_mode == 0 ? msNoiseFloor_buffer16[j] : msNoiseFloor_buffer32[j] ) == 0 ) ) #else IF( ( scalar == 0 ) || ( msNoiseFloor_buffer[j] == 0 ) ) #endif @@ -2164,12 +2164,12 @@ void minimum_statistics_fx( move32(); tmp0 = Mpy_32_16_1( scalar2, QeqInv ); - tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_subwin, QeqInv ); #if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) - tmp1 = L_sub( 1073741824l, L_mult( msM_subwin, QeqInv ) ); + tmp1 = L_sub( 1073741824l /*0.5 Q31*/, L_mult( msM_subwin, QeqInv ) ); #else - tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); + tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_subwin, QeqInv ); #endif + tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); msBminSubWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), s ) ); move32(); } @@ -2327,6 +2327,7 @@ void minimum_statistics_fx( set16_fx( msLocalMinFlag, 0, len ); set32_fx( msCurrentMin, 2147483647l /*1.0 Q31*/, len ); + /* Get the current noise floor */ #ifdef FIX_2485_HARMONIZE_minimum_statistics IF( element_mode == 0 ) { @@ -2494,6 +2495,7 @@ void minimum_statistics_fx( #endif /*FIX_2485_HARMONIZE_minimum_statistics*/ + /*------------------------------------------------------------------- * apply_scale() * diff --git a/lib_com/options.h b/lib_com/options.h index 615e4935e..d7a88247c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -92,6 +92,7 @@ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ #define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ #define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code*/ +#define FIX_2485_HARMONIZE_minimum_statistics_CHECK1 /*Check wheter EVS mode can be entered being in IVAS mode*/ #define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ #define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index eb52090bf..50786b18b 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2104,6 +2104,9 @@ void perform_noise_estimation_dec_ivas_fx( compress_range( hFdCngDec->msPeriodog, hFdCngDec->msPeriodog_exp, hFdCngDec->msLogPeriodog, npart ); /* Call the minimum statistics routine for noise estimation */ +#ifdef FIX_2485_HARMONIZE_minimum_statistics_CHECK1 + assert( element_mode != 0); +#endif minimum_statistics_fx( npart, nFFTpart, diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index e20a632e1..d444b6e6c 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2666,6 +2666,9 @@ void perform_noise_estimation_enc_fx( /* Call the minimum statistics routine for noise estimation */ #ifdef FIX_2485_HARMONIZE_minimum_statistics +#ifdef FIX_2485_HARMONIZE_minimum_statistics_CHECK1 + assert( element_mode == hCPE->element_mode ); +#endif minimum_statistics_fx( hFdCngEnc->hFdCngCom->npart, nFFTpart, -- GitLab From c063c3504732110986b4afa3af07c2aaff99de04 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 10:33:20 +0100 Subject: [PATCH 11/21] clang patch --- lib_dec/fd_cng_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 50786b18b..bc136261b 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2105,7 +2105,7 @@ void perform_noise_estimation_dec_ivas_fx( /* Call the minimum statistics routine for noise estimation */ #ifdef FIX_2485_HARMONIZE_minimum_statistics_CHECK1 - assert( element_mode != 0); + assert( element_mode != 0 ); #endif minimum_statistics_fx( npart, -- GitLab From 96b0d72e7f91366501c9e3f14405824d0d883e41 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 12:11:09 +0100 Subject: [PATCH 12/21] some bugfixes in FIX_2485_HARMONIZE_minimum_statistics --- lib_com/fd_cng_com_fx.c | 33 ++++++++++++++++++++------------- lib_com/options.h | 4 +--- lib_com/prot_fx.h | 3 ++- lib_dec/fd_cng_dec_fx.c | 14 +++++++++----- lib_enc/fd_cng_enc_fx.c | 8 +++----- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 6a3da1ce1..cf3943e0c 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1714,7 +1714,8 @@ void minimum_statistics_fx( Word16 *msPeriodogBufPtr, /* i/o: Counter */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 enc_dec, /* i : encoder/decoder indicator */ - const Word16 element_mode /* i : IVAS element mode type */ + const Word16 element_mode, /* i : IVAS element mode type */ + const Word16 isIVAS ) { Word16 i, j, k, s, s1, s2, s3; @@ -1781,7 +1782,7 @@ void minimum_statistics_fx( IF( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { Copy( msPeriodog, msPsd, len ); /* 6Q9 */ Copy( msPeriodog, msNoiseFloor_buffer16, len ); /* 6Q9 */ @@ -1922,7 +1923,7 @@ void minimum_statistics_fx( /* msPeriodogSum[cnt] with format 16Q15 */ Word16 msNoiseFloor16tmp[NPART_SHAPING]; #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { snr = dotp_s_fx( msNoiseFloor_buffer16 + start, psize + start, current_len, CNG_HS ); } @@ -1970,7 +1971,10 @@ void minimum_statistics_fx( /* Compute optimal smoothing parameter for PSD estimation */ test(); #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( ( scalar == 0 ) || ( ( element_mode == 0 ? msNoiseFloor_buffer16[j] : msNoiseFloor_buffer32[j] ) == 0 ) ) + test(); + test(); + test(); + IF( ( scalar == 0 ) || ( ( isIVAS == 0 ) ? ( msNoiseFloor_buffer16[j] == 0 ) : ( msNoiseFloor_buffer32[j] == 0 ) ) ) #else IF( ( scalar == 0 ) || ( msNoiseFloor_buffer[j] == 0 ) ) #endif @@ -1984,7 +1988,7 @@ void minimum_statistics_fx( s1 = WORD16_BITS - 1; move16(); #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { if ( msNoiseFloor_buffer16[j] != 0 ) { @@ -2124,13 +2128,15 @@ void minimum_statistics_fx( QeqInv = MSQEQINVMAX; move16(); #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( ( element_mode == 0 ? msNoiseFloor_buffer16[j] : msNoiseFloor_buffer32[j] ) != 0 ) + test(); + test(); + IF( ( isIVAS == 0 ) ? ( msNoiseFloor_buffer16[j] != 0 ) : ( msNoiseFloor_buffer32[j] != 0 ) ) #else IF( msNoiseFloor_buffer[j] != 0 /*0.0 Q15*/ ) #endif { #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { tmp = L_mult( msNoiseFloor_buffer16[j], msNoiseFloor_buffer16[j] ); } @@ -2260,7 +2266,7 @@ void minimum_statistics_fx( } /* Get the current noise floor */ #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { Copy_Scale_sig_32_16( msCurrentMinOut, msNoiseFloor_buffer16, len, -16 ); } @@ -2329,7 +2335,7 @@ void minimum_statistics_fx( /* Get the current noise floor */ #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { Copy_Scale_sig_32_16( msCurrentMinOut, msNoiseFloor_buffer16, len, -16 ); } @@ -2399,7 +2405,7 @@ void minimum_statistics_fx( /* Smooth noise estimate during CNG phases */ #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { FOR( j = 0; j < len; j++ ) { @@ -2429,7 +2435,7 @@ void minimum_statistics_fx( } #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode > 0 ) + IF( isIVAS > 0 ) { IF( EQ_16( enc_dec, DEC ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { @@ -2465,7 +2471,7 @@ void minimum_statistics_fx( scalar = L_mac( scalar, msPeriodogBuf[i], 6554 /*1.0/MSBUFLEN Q15*/ ); } #ifdef FIX_2485_HARMONIZE_minimum_statistics - IF( element_mode == 0 ) + IF( isIVAS == 0 ) { scalar16 = round_fx( scalar ); if ( GT_16( msNoiseEst_buffer16[j], scalar16 ) /*0.0 Q15*/ ) @@ -2482,14 +2488,15 @@ void minimum_statistics_fx( move32(); } } + assert( ( ( isIVAS == 0 ) ? ( msNoiseEst_buffer16[j] >= 0 ) : ( msNoiseEst_buffer32[j] >= 0 ) ) ); #else if ( GT_32( msNoiseEst_buffer[j], scalar ) /*0.0 Q15*/ ) { msNoiseEst_buffer[j] = scalar; move32(); } + assert( msNoiseEst[j] >= 0 ); #endif - assert( ( element_mode == 0 ? ( msNoiseEst_buffer16[j] ) : ( msNoiseEst_buffer32[j] ) ) >= 0 /*0.0 Q15*/ ); } } diff --git a/lib_com/options.h b/lib_com/options.h index d7a88247c..467af28a1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -92,9 +92,7 @@ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ #define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ #define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code*/ -#define FIX_2485_HARMONIZE_minimum_statistics_CHECK1 /*Check wheter EVS mode can be entered being in IVAS mode*/ -#define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ -#define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ + /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 9b6df5a8f..14e636f47 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4609,7 +4609,8 @@ void minimum_statistics_fx( Word16 *msPeriodogBufPtr, /* i/o: Counter */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 enc_dec, /* i : encoder/decoder indicator */ - const Word16 element_mode /* i : IVAS element mode type */ + const Word16 element_mode, /* i : IVAS element mode type */ + const Word16 isIVAS ); #else void minimum_statistics( diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index bc136261b..05d33b4d6 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1304,7 +1304,9 @@ void perform_noise_estimation_dec_fx( &( hFdCngDec->msPeriodogBufPtr ), hFdCngDec->hFdCngCom, 0, - 0 ); + 0, + 0 + ); #else minimum_statistics( npart, @@ -2104,9 +2106,6 @@ void perform_noise_estimation_dec_ivas_fx( compress_range( hFdCngDec->msPeriodog, hFdCngDec->msPeriodog_exp, hFdCngDec->msLogPeriodog, npart ); /* Call the minimum statistics routine for noise estimation */ -#ifdef FIX_2485_HARMONIZE_minimum_statistics_CHECK1 - assert( element_mode != 0 ); -#endif minimum_statistics_fx( npart, nFFTpart, @@ -2129,7 +2128,12 @@ void perform_noise_estimation_dec_ivas_fx( hFdCngDec->msPeriodogBuf, &( hFdCngDec->msPeriodogBufPtr ), hFdCngDec->hFdCngCom, - DEC, element_mode ); + DEC, element_mode +#ifdef FIX_2485_HARMONIZE_minimum_statistics + , + 0 +#endif + ); FOR( i = 0; i < hFdCngDec->npart_shaping; i++ ) { diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index d444b6e6c..d8551a6c6 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2666,9 +2666,6 @@ void perform_noise_estimation_enc_fx( /* Call the minimum statistics routine for noise estimation */ #ifdef FIX_2485_HARMONIZE_minimum_statistics -#ifdef FIX_2485_HARMONIZE_minimum_statistics_CHECK1 - assert( element_mode == hCPE->element_mode ); -#endif minimum_statistics_fx( hFdCngEnc->hFdCngCom->npart, nFFTpart, @@ -2691,8 +2688,9 @@ void perform_noise_estimation_enc_fx( hFdCngEnc->msPeriodogBuf_fx, &( hFdCngEnc->msPeriodogBufPtr ), hFdCngEnc->hFdCngCom, - ( element_mode == 0 ) ? ( 0 ) : ( ENC ), - ( element_mode == 0 ) ? ( 0 ) : ( ( hCPE == NULL ) ? 0 : hCPE->element_mode ) ); + ENC, + ( hCPE == NULL ) ? 0 : hCPE->element_mode, + element_mode ); /* Expand MS outputs */ -- GitLab From f03df8a62a8e6601721094186b4bd8aad5e2cb8e Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 12:15:23 +0100 Subject: [PATCH 13/21] clang patch --- lib_com/fd_cng_com_fx.c | 3 +-- lib_com/prot_fx.h | 3 +-- lib_dec/fd_cng_dec_fx.c | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index cf3943e0c..b5b315285 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1715,8 +1715,7 @@ void minimum_statistics_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 enc_dec, /* i : encoder/decoder indicator */ const Word16 element_mode, /* i : IVAS element mode type */ - const Word16 isIVAS -) + const Word16 isIVAS ) { Word16 i, j, k, s, s1, s2, s3; Word16 len2; diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 14e636f47..b2a2d80ac 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4610,8 +4610,7 @@ void minimum_statistics_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 enc_dec, /* i : encoder/decoder indicator */ const Word16 element_mode, /* i : IVAS element mode type */ - const Word16 isIVAS -); + const Word16 isIVAS ); #else void minimum_statistics( Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 05d33b4d6..bcc1b7ee9 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1305,8 +1305,7 @@ void perform_noise_estimation_dec_fx( hFdCngDec->hFdCngCom, 0, 0, - 0 - ); + 0 ); #else minimum_statistics( npart, @@ -2129,7 +2128,7 @@ void perform_noise_estimation_dec_ivas_fx( &( hFdCngDec->msPeriodogBufPtr ), hFdCngDec->hFdCngCom, DEC, element_mode -#ifdef FIX_2485_HARMONIZE_minimum_statistics +#ifdef FIX_2485_HARMONIZE_minimum_statistics , 0 #endif -- GitLab From 0ee08479c6722e01bdd4a5732c96060992a3837c Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 13:33:07 +0100 Subject: [PATCH 14/21] fix isIVAS flag --- lib_dec/fd_cng_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index bcc1b7ee9..bf2668e9f 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2130,7 +2130,7 @@ void perform_noise_estimation_dec_ivas_fx( DEC, element_mode #ifdef FIX_2485_HARMONIZE_minimum_statistics , - 0 + 1 #endif ); -- GitLab From 3014b3439b36a6aaadb60d6aaad2f52943578445 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 19 Mar 2026 14:06:05 +0100 Subject: [PATCH 15/21] check EVS BEness --- lib_com/fd_cng_com_fx.c | 4 ++-- lib_enc/fd_cng_enc_fx.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index b5b315285..28db59220 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -2159,7 +2159,7 @@ void minimum_statistics_fx( /* Compute bias correction Bmin */ tmp0 = Mpy_32_16_1( scalar, QeqInv ); -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) tmp1 = L_sub( 1073741824l, L_mult( msM_win, QeqInv ) ); #else tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_win, QeqInv ); @@ -2169,7 +2169,7 @@ void minimum_statistics_fx( move32(); tmp0 = Mpy_32_16_1( scalar2, QeqInv ); -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) tmp1 = L_sub( 1073741824l /*0.5 Q31*/, L_mult( msM_subwin, QeqInv ) ); #else tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_subwin, QeqInv ); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index d8551a6c6..855a27288 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2590,9 +2590,8 @@ void perform_noise_estimation_enc_fx( ptr_per_fx++; i++; } - /* exponent for cldfb part of msPeriodog */ - // hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); + /* exponent for cldfb part of msPeriodog */ FOR( i = 0; i < numBands; i++ ) { periodog[i] = L_shr( periodog[i], sub( max_exp, periodog_exp[i] ) ); -- GitLab From ab5bdd07584896f122ce2e7bb624e53fff3a7642 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Mon, 23 Mar 2026 07:38:27 +0100 Subject: [PATCH 16/21] small cleanups --- lib_com/fd_cng_com_fx.c | 15 +++------------ lib_com/options.h | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 28db59220..09762a307 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1781,19 +1781,18 @@ void minimum_statistics_fx( IF( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { #ifdef FIX_2485_HARMONIZE_minimum_statistics + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ IF( isIVAS == 0 ) { - Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msNoiseFloor_buffer16, len ); /* 6Q9 */ Copy( msPeriodog, msNoiseEst_buffer16, len ); /* 6Q9 */ - Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ } ELSE { - Copy( msPeriodog, msPsd, len ); /* 6Q9 */ Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseFloor_buffer32, len, Q16 ); /* Q25 */ Copy_Scale_sig_16_32_no_sat( msPeriodog, msNoiseEst_buffer32, len, Q16 ); /* Q25 */ - Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ } #else Copy( msPeriodog, msPsd, len ); /* 6Q9 */ @@ -2159,21 +2158,13 @@ void minimum_statistics_fx( /* Compute bias correction Bmin */ tmp0 = Mpy_32_16_1( scalar, QeqInv ); -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) - tmp1 = L_sub( 1073741824l, L_mult( msM_win, QeqInv ) ); -#else tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_win, QeqInv ); -#endif tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); msBminWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), add( s, 7 - 4 ) ) ); move32(); tmp0 = Mpy_32_16_1( scalar2, QeqInv ); -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) - tmp1 = L_sub( 1073741824l /*0.5 Q31*/, L_mult( msM_subwin, QeqInv ) ); -#else tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_subwin, QeqInv ); -#endif tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); msBminSubWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), s ) ); move32(); diff --git a/lib_com/options.h b/lib_com/options.h index 467af28a1..589d59a29 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,7 +91,7 @@ #define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ #define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ -#define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code*/ +#define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code, ensures EVS-BEness */ -- GitLab From 608d13404be7d057efb3ab5b5727cfdf0307ceb5 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Mon, 23 Mar 2026 07:50:35 +0100 Subject: [PATCH 17/21] clang patch --- lib_com/fd_cng_com_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 09762a307..74e4ade79 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1781,7 +1781,7 @@ void minimum_statistics_fx( IF( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { #ifdef FIX_2485_HARMONIZE_minimum_statistics - Copy( msPeriodog, msPsd, len ); /* 6Q9 */ + Copy( msPeriodog, msPsd, len ); /* 6Q9 */ Copy( msPeriodog, msPsdFirstMoment, len ); /* 6Q9 */ IF( isIVAS == 0 ) { -- GitLab From e5ab5d37b041836297e2cf356cc03ca05c6e24e8 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Mon, 23 Mar 2026 08:36:52 +0100 Subject: [PATCH 18/21] check lowprecission for perform_noise_estimation_enc --- lib_com/options.h | 1 + lib_enc/fd_cng_enc_fx.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 933f46f0b..8c6993c55 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -93,6 +93,7 @@ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ #define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ #define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code, ensures EVS-BEness */ +#define FIX_2485_CHECKLOWPRECISSION diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 855a27288..87d29ef74 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2492,6 +2492,10 @@ void perform_noise_estimation_enc_fx( int element_mode /* i : is element EVS or IVAS */ ) { +#ifdef FIX_2485_CHECKLOWPRECISSION + element_mode = 0; + move32(); +#endif if ( element_mode == 0 ) { (void) input_Fs; -- GitLab From cc027f34a4719e652320d1f6f5596ae8ff84d021 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 24 Mar 2026 11:54:28 +0100 Subject: [PATCH 19/21] delete checklowrecision code --- lib_com/options.h | 1 - lib_enc/fd_cng_enc_fx.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8c6993c55..933f46f0b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -93,7 +93,6 @@ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ #define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ #define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code, ensures EVS-BEness */ -#define FIX_2485_CHECKLOWPRECISSION diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 87d29ef74..855a27288 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -2492,10 +2492,6 @@ void perform_noise_estimation_enc_fx( int element_mode /* i : is element EVS or IVAS */ ) { -#ifdef FIX_2485_CHECKLOWPRECISSION - element_mode = 0; - move32(); -#endif if ( element_mode == 0 ) { (void) input_Fs; -- GitLab From ec880276d65320f298a43cb7a9230e68159db268 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 25 Mar 2026 08:34:40 +0100 Subject: [PATCH 20/21] test ivas-basops --- lib_com/fd_cng_com_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 74e4ade79..ae4575ab0 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1906,7 +1906,7 @@ void minimum_statistics_fx( scalar16 = shl( scalar16, s3 ); scalar16 = s_max( scalar16, MSALPHACORMAX ); -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) hFdCngCom->msAlphaCor[cnt] = L_add( Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ), L_mult( scalar16, msAlphaCorAlpha2 ) ); #else @@ -2061,7 +2061,7 @@ void minimum_statistics_fx( } /* Compute the PSD (smoothed periodogram) in each band */ -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode ) +#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), Mpy_32_16_1( L_sub( 2147483647l, msAlpha[j] ), msPeriodog[j] ) ) ); #else -- GitLab From a983b3e9447d4de452e70ff5a9b35b1b3a239e2e Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 25 Mar 2026 09:27:54 +0100 Subject: [PATCH 21/21] cleanup - delete EVS-basop BE-switch and code --- lib_com/fd_cng_com_fx.c | 4 ++-- lib_com/options.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index ae4575ab0..3ddbb5ddf 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1906,7 +1906,7 @@ void minimum_statistics_fx( scalar16 = shl( scalar16, s3 ); scalar16 = s_max( scalar16, MSALPHACORMAX ); -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) +#ifdef FIX_2485_HARMONIZE_minimum_statistics hFdCngCom->msAlphaCor[cnt] = L_add( Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ), L_mult( scalar16, msAlphaCorAlpha2 ) ); #else @@ -2061,7 +2061,7 @@ void minimum_statistics_fx( } /* Compute the PSD (smoothed periodogram) in each band */ -#if defined( FIX_2485_HARMONIZE_minimum_statistics ) && defined( FIX_2485_HARMONIZE_minimum_statistics_EVSmode_ ) +#ifdef FIX_2485_HARMONIZE_minimum_statistics msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), Mpy_32_16_1( L_sub( 2147483647l, msAlpha[j] ), msPeriodog[j] ) ) ); #else diff --git a/lib_com/options.h b/lib_com/options.h index e6138769c..f2005357a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -90,7 +90,6 @@ #define HARMONIZE_2481_EXTEND_SHRINK /* FhG: basop issue 2481: Harmonize extend_frm_*fx() and shrink_frm_*fx() */ #define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */ #define FIX_2485_HARMONIZE_minimum_statistics /* FhG: harmonize minimum_statistics and minimum_statistics_fx */ -#define FIX_2485_HARMONIZE_minimum_statistics_EVSmode /* FhG: harmonize... and use EVS-code for certain calculations, instead of IVAS code, ensures EVS-BEness */ /* #################### End BE switches ################################## */ -- GitLab