From 94867874c0b26ca86173860a33890570ac1b1d0e Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 7 Oct 2025 15:43:46 +0200 Subject: [PATCH 1/7] increase cldfb buffer precision --- lib_com/options.h | 1 + lib_enc/ivas_core_enc_fx.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index ef687f30e..c6823abd3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -108,6 +108,7 @@ #define FIX_2003_CON_TCX_OVERFLOW /* FhG: Use a dynamic scaling factor for the synth buffer at the output of con_tcx_ivas_fx() */ #define OPT_TCXLTP_FILTER_LOOP /* FhG: optimize loop in tcx_ltp_synth_filter */ #define FIX_2602_NONBE_SAT_IN_SWB_TBE_SCALE /* Dolby/FhG: fix for issue 2026: Saturation in SWB TBE re-scaling function preventing StereoDownmix complexity job to complete */ +#define FIX_2021_BANDWIDTH_EXTENSION_PROBLEM /* FhG: increase cldfb buffer precision*/ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 2c23205d0..cb7bd262f 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -698,7 +698,21 @@ ivas_error ivas_core_enc_fx( /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ /* Scaling cldfb_state_fx */ scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer - +#ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM + Word16 scf_min = 31; + move16(); + FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scf_min = s_min( scf_min, getScaleFactor32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); + scf_min = s_min( scf_min, getScaleFactor32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); + } + FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, scf_min ); + scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, scf_min ); + } + q_re_im_buf[n] = add( q_re_im_buf[n], scf_min ); +#endif swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx[n], imagBuffer_fx[n], q_re_im_buf[n], hCPE ); /* Re-scaling cldfb_state_fx */ -- GitLab From 643bcca538bce468216cfbf928d14159b8f52d5b Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 7 Oct 2025 16:55:22 +0200 Subject: [PATCH 2/7] replace getScaleFactor32 with L_norm_arr --- lib_enc/ivas_core_enc_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index cb7bd262f..1fdb05eed 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -703,8 +703,8 @@ ivas_error ivas_core_enc_fx( move16(); FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scf_min = s_min( scf_min, getScaleFactor32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); - scf_min = s_min( scf_min, getScaleFactor32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); + scf_min = s_min( scf_min, L_norm_arr( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); + scf_min = s_min( scf_min, L_norm_arr( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); } FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) { -- GitLab From 84fb5fdd442b8a09e7dc29bbae55cd3426a1ec6e Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 7 Oct 2025 19:07:15 +0200 Subject: [PATCH 3/7] fix CLDFB buffers scaling --- lib_enc/ivas_core_enc_fx.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 1fdb05eed..39efaff9a 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -697,9 +697,8 @@ ivas_error ivas_core_enc_fx( { /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ /* Scaling cldfb_state_fx */ - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer #ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM - Word16 scf_min = 31; + Word16 shift, scf_cldfb, scf_min = 31; move16(); FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) { @@ -712,11 +711,43 @@ ivas_error ivas_core_enc_fx( scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, scf_min ); } q_re_im_buf[n] = add( q_re_im_buf[n], scf_min ); + + scf_cldfb = L_norm_arr( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length ); + + IF( NE_32( scf_cldfb, 31 ) ) + { + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, scf_cldfb ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer + st->cldfbSynTd->Q_cldfb_state = add( st->cldfbSynTd->Q_cldfb_state, scf_cldfb ); + + shift = sub( st->cldfbSynTd->Q_cldfb_state, sub( q_re_im_buf[n], 1 ) ); + IF( GT_32( sub( q_re_im_buf[n], 1 ), st->cldfbSynTd->Q_cldfb_state ) ) + { + FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, shift ); + scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, shift ); + } + q_re_im_buf[n] = add( st->cldfbSynTd->Q_cldfb_state, 1 ); + } + ELSE + { + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( shift ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer + st->cldfbSynTd->Q_cldfb_state = q_re_im_buf[n]; + } + } + +#else + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer #endif + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx[n], imagBuffer_fx[n], q_re_im_buf[n], hCPE ); +#ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM + st->cldfbSynTd->Q_cldfb_state = sub( q_re_im_buf[n], 1 ); +#else /* Re-scaling cldfb_state_fx */ scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ) ); // q_realImagBuffer -> st->cldfbSynTd->Q_cldfb_state +#endif } ELSE IF( GE_32( input_Fs, 32000 ) ) { -- GitLab From 042d9e814dc91c15c290ed7b1618a2cb869c5213 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 7 Oct 2025 19:11:29 +0200 Subject: [PATCH 4/7] clang formatting patch --- lib_enc/ivas_core_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 39efaff9a..b8ee1a82e 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -737,7 +737,7 @@ ivas_error ivas_core_enc_fx( } #else - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer #endif swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx[n], imagBuffer_fx[n], q_re_im_buf[n], hCPE ); -- GitLab From 2e471cbd878602d377d5189929cdf836d52112c4 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 7 Oct 2025 20:33:36 +0200 Subject: [PATCH 5/7] remove realBuffer_fx,imagBuffer_fx normalization --- lib_enc/ivas_core_enc_fx.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index b8ee1a82e..c53eb1041 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -698,25 +698,12 @@ ivas_error ivas_core_enc_fx( /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ /* Scaling cldfb_state_fx */ #ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM - Word16 shift, scf_cldfb, scf_min = 31; - move16(); - FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scf_min = s_min( scf_min, L_norm_arr( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); - scf_min = s_min( scf_min, L_norm_arr( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX ) ); - } - FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scale_sig32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, scf_min ); - scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, scf_min ); - } - q_re_im_buf[n] = add( q_re_im_buf[n], scf_min ); - + Word16 shift, scf_cldfb; scf_cldfb = L_norm_arr( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length ); IF( NE_32( scf_cldfb, 31 ) ) { - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, scf_cldfb ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, scf_cldfb ); st->cldfbSynTd->Q_cldfb_state = add( st->cldfbSynTd->Q_cldfb_state, scf_cldfb ); shift = sub( st->cldfbSynTd->Q_cldfb_state, sub( q_re_im_buf[n], 1 ) ); @@ -735,7 +722,6 @@ ivas_error ivas_core_enc_fx( st->cldfbSynTd->Q_cldfb_state = q_re_im_buf[n]; } } - #else scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer #endif -- GitLab From 09b441b3b4abb8ceee1a158995311c27a9fe4fea Mon Sep 17 00:00:00 2001 From: naghibza Date: Wed, 8 Oct 2025 11:37:06 +0200 Subject: [PATCH 6/7] increase CldfbHB_fx calculation precision --- lib_enc/ivas_core_enc_fx.c | 33 +++++++++++++++------------------ lib_enc/swb_pre_proc_fx.c | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index c53eb1041..296bff89a 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -698,29 +698,26 @@ ivas_error ivas_core_enc_fx( /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ /* Scaling cldfb_state_fx */ #ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM - Word16 shift, scf_cldfb; + Word16 q_shift, scf_cldfb; scf_cldfb = L_norm_arr( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length ); - IF( NE_32( scf_cldfb, 31 ) ) - { - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, scf_cldfb ); - st->cldfbSynTd->Q_cldfb_state = add( st->cldfbSynTd->Q_cldfb_state, scf_cldfb ); + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, scf_cldfb ); + st->cldfbSynTd->Q_cldfb_state = add( st->cldfbSynTd->Q_cldfb_state, scf_cldfb ); - shift = sub( st->cldfbSynTd->Q_cldfb_state, sub( q_re_im_buf[n], 1 ) ); - IF( GT_32( sub( q_re_im_buf[n], 1 ), st->cldfbSynTd->Q_cldfb_state ) ) - { - FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scale_sig32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, shift ); - scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, shift ); - } - q_re_im_buf[n] = add( st->cldfbSynTd->Q_cldfb_state, 1 ); - } - ELSE + q_shift = sub( sub( q_re_im_buf[n], 1 ), st->cldfbSynTd->Q_cldfb_state ); // cldfb_state_fx will be used in cldfbSynthesis_ivas_fx and has to be aligned with (q_re_im_buf[n] - 1) + IF( GT_32( q_shift, 0 ) ) + { + FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( shift ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer - st->cldfbSynTd->Q_cldfb_state = q_re_im_buf[n]; + scale_sig32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); + scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); } + q_re_im_buf[n] = add( st->cldfbSynTd->Q_cldfb_state, 1 ); + } + ELSE + { + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, q_shift ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer + st->cldfbSynTd->Q_cldfb_state = sub( q_re_im_buf[n], 1 ); } #else scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf[n], st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 2cd295acd..f857cbec0 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -1104,6 +1104,10 @@ void swb_pre_proc_ivas_fx( IF( ( ( st->core == ACELP_CORE ) && NE_16( st->extl, SWB_BWE_HIGHRATE ) && NE_16( st->extl, FB_BWE_HIGHRATE ) ) || ( ( EQ_32( st->total_brate, ACELP_9k60 ) || st->rf_mode ) && EQ_16( st->bwidth, SWB ) && ( st->element_mode == EVS_MONO ) ) ) { +#ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM + Word64 CldfbHB64_fx = 0; + move64(); +#endif Word32 CldfbHB_fx = 0; // fixed counterpart Word16 CldfbHB_fx_e = 0; // fixed counterpart #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -1214,16 +1218,28 @@ void swb_pre_proc_ivas_fx( { FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { +#ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM + CldfbHB64_fx = W_mac_32_32( CldfbHB64_fx, realBufferFlipped[ts][nB], realBufferFlipped[ts][nB] ); + CldfbHB64_fx = W_mac_32_32( CldfbHB64_fx, imagBufferFlipped[ts][nB], imagBufferFlipped[ts][nB] ); +#else realQ_neg1 = extract_l( L_shr( realBufferFlipped[ts][nB], 16 ) ); imagQ_neg1 = extract_l( L_shr( imagBufferFlipped[ts][nB], 16 ) ); /* Q(-1), headroom needed */ CldfbHB_fx = L_mac0_o( CldfbHB_fx, realQ_neg1, realQ_neg1, &Overflow ); CldfbHB_fx = L_mac0_o( CldfbHB_fx, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ +#endif } } +#ifdef FIX_2021_BANDWIDTH_EXTENSION_PROBLEM + Word16 scf = W_norm( CldfbHB64_fx ); + CldfbHB64_fx = W_shl( CldfbHB64_fx, scf ); + CldfbHB_fx = W_extract_h( CldfbHB64_fx ); + CldfbHB_fx_e = sub( Q31, add( shl( q_reImBuffer, 1 ), sub( scf, Q31 ) ) ); +#else CldfbHB_fx_e = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) ); exp = norm_l( CldfbHB_fx ); - CldfbHB_fx = L_shl( CldfbHB_fx, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ + CldfbHB_fx = L_shl( CldfbHB_fx, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ +#endif Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) ); CldfbHB_fx = L_mult( Cldfbtemp1, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ -- GitLab From e5996e0aed878ac5bade8f92bb9998fd824d626c Mon Sep 17 00:00:00 2001 From: naghibza Date: Wed, 8 Oct 2025 15:42:03 +0200 Subject: [PATCH 7/7] rename "for" iterator to avoid compile warning. --- lib_enc/ivas_core_enc_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 296bff89a..c296c816c 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -707,10 +707,10 @@ ivas_error ivas_core_enc_fx( q_shift = sub( sub( q_re_im_buf[n], 1 ), st->cldfbSynTd->Q_cldfb_state ); // cldfb_state_fx will be used in cldfbSynthesis_ivas_fx and has to be aligned with (q_re_im_buf[n] - 1) IF( GT_32( q_shift, 0 ) ) { - FOR( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) + FOR( int ts = 0; ts < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); - scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); + scale_sig32( realBuffer_fx[n][ts], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); + scale_sig32( imagBuffer_fx[n][ts], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); } q_re_im_buf[n] = add( st->cldfbSynTd->Q_cldfb_state, 1 ); } -- GitLab