From 278986f14089996c0f7d5bbef37083f7320e3686 Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 31 Oct 2025 09:29:08 +0100 Subject: [PATCH 1/5] Enable hp20_fx_32_opt() for Encoder --- lib_com/options.h | 2 +- lib_enc/ivas_enc_fx.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 676b3d674..60b12c414 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,7 +84,7 @@ #define FIX_BASOP_ASSERT_IN_TONAL_MDCT_PLC /* FhG: fix for issue 2165 - using saturating addition in tonal MDCT PLC function */ #define OPT_2146_BASOP_UTIL_ADD_MANT32EXP /* Dlb: optimized version of BASOP_Util_Add_Mant32Exp() */ #define FIX_2166_ASSERT_OSBA_PLC_STEREO_OUT /* FhG: fix for issue 2166 - add missing averaging factor 0.5 in for the sum of energies in function stereo_dft_dmx_swb_nrg_fx()*/ - +#define FIX_2086_ENABLE_HP20_OPT_FOR_ENC /* FhG: Enable hp20_fx_32_opt() for Encoder */ #define FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE /* FhG: Use dynamic Q factor for synth_fx and synthFB_fx to prevent overflow */ /* ################### End FIXES switches ########################### */ diff --git a/lib_enc/ivas_enc_fx.c b/lib_enc/ivas_enc_fx.c index 095d4c2cf..4d8f99650 100644 --- a/lib_enc/ivas_enc_fx.c +++ b/lib_enc/ivas_enc_fx.c @@ -158,11 +158,19 @@ ivas_error ivas_enc_fx( test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) ) { +#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC + hp20_fx_32_opt( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#else hp20_fx_32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#endif } ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) ) { +#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC + hp20_fx_32_opt( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#else hp20_fx_32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#endif } } -- GitLab From 0342dccc05e40e4d1a96d3e02414eb3c3c38d3a3 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 3 Nov 2025 15:01:38 +0100 Subject: [PATCH 2/5] Handle negative shr in hp20_fx_32_opt() --- lib_com/hp50_fx.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib_com/hp50_fx.c b/lib_com/hp50_fx.c index 1586bc252..3debe546b 100644 --- a/lib_com/hp50_fx.c +++ b/lib_com/hp50_fx.c @@ -331,8 +331,10 @@ void hp20_fx_32_opt( move32(); move32(); move32(); +#ifndef FIX_2086_ENABLE_HP20_OPT_FOR_ENC mem_fx[4] = L_deposit_l( prescale_current_frame ); move32(); +#endif IF( EQ_32( Fs, 8000 ) ) { @@ -405,7 +407,36 @@ void hp20_fx_32_opt( signal_fx[1] = W_round64_L( W_shl( W_y1, prescale ) ); move32(); +#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC + Word16 scf_min = 63; + move16(); + IF( GT_32( prescale, prescale_current_frame ) ) + { + if ( NE_64( W_y1, 0 ) ) + scf_min = s_min( scf_min, W_norm( W_y1 ) ); + if ( NE_64( W_y2, 0 ) ) + scf_min = s_min( scf_min, W_norm( W_y1 ) ); + if ( NE_32( x1, 0 ) ) + scf_min = s_min( scf_min, norm_l( x1 ) ); + if ( NE_32( x2, 0 ) ) + scf_min = s_min( scf_min, norm_l( x2 ) ); + diff = sub( prescale_current_frame, prescale ); + diff = s_max( negate( scf_min ), diff ); + prescale_current_frame = add( prescale, diff ); + //prescale_current_frame = prescale; + //diff = 0; + //move16(); + } + ELSE + { + diff = sub( prescale_current_frame, prescale ); + } + mem_fx[4] = L_deposit_l( prescale_current_frame ); + move32(); +#else diff = sub( prescale_current_frame, prescale ); +#endif + W_y1 = W_shr( W_y1, diff ); W_y2 = W_shr( W_y2, diff ); x2 = L_shr( x2, diff ); -- GitLab From 1037c58204bf07dfdab78e3d9468adb7df7baf61 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 3 Nov 2025 15:05:04 +0100 Subject: [PATCH 3/5] Apply clang formatting patch --- lib_com/hp50_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/hp50_fx.c b/lib_com/hp50_fx.c index 3debe546b..e5f762ed9 100644 --- a/lib_com/hp50_fx.c +++ b/lib_com/hp50_fx.c @@ -423,9 +423,9 @@ void hp20_fx_32_opt( diff = sub( prescale_current_frame, prescale ); diff = s_max( negate( scf_min ), diff ); prescale_current_frame = add( prescale, diff ); - //prescale_current_frame = prescale; - //diff = 0; - //move16(); + // prescale_current_frame = prescale; + // diff = 0; + // move16(); } ELSE { -- GitLab From bdebaafc79b8682b3b6d508119944737f9e28059 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 3 Nov 2025 17:03:21 +0100 Subject: [PATCH 4/5] Handle overflow in shr() scaling more simply --- lib_com/hp50_fx.c | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/lib_com/hp50_fx.c b/lib_com/hp50_fx.c index e5f762ed9..26cc77794 100644 --- a/lib_com/hp50_fx.c +++ b/lib_com/hp50_fx.c @@ -316,8 +316,12 @@ void hp20_fx_32_opt( prescale = s_min( prescale, diff ); prescale = sub( 1 + HP20_FX_COEFF_SCALE, prescale ); - +#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC + if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) || // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead + LT_16( prescale_current_frame, prescale ) ) // To avoid overflow in the subsequent shr() scaling for W_y1, W_y2, x2, and x1 calculations before the for loop. +#else if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) ) // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead +#endif { prescale_current_frame = prescale; } @@ -331,10 +335,8 @@ void hp20_fx_32_opt( move32(); move32(); move32(); -#ifndef FIX_2086_ENABLE_HP20_OPT_FOR_ENC mem_fx[4] = L_deposit_l( prescale_current_frame ); move32(); -#endif IF( EQ_32( Fs, 8000 ) ) { @@ -407,36 +409,7 @@ void hp20_fx_32_opt( signal_fx[1] = W_round64_L( W_shl( W_y1, prescale ) ); move32(); -#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC - Word16 scf_min = 63; - move16(); - IF( GT_32( prescale, prescale_current_frame ) ) - { - if ( NE_64( W_y1, 0 ) ) - scf_min = s_min( scf_min, W_norm( W_y1 ) ); - if ( NE_64( W_y2, 0 ) ) - scf_min = s_min( scf_min, W_norm( W_y1 ) ); - if ( NE_32( x1, 0 ) ) - scf_min = s_min( scf_min, norm_l( x1 ) ); - if ( NE_32( x2, 0 ) ) - scf_min = s_min( scf_min, norm_l( x2 ) ); - diff = sub( prescale_current_frame, prescale ); - diff = s_max( negate( scf_min ), diff ); - prescale_current_frame = add( prescale, diff ); - // prescale_current_frame = prescale; - // diff = 0; - // move16(); - } - ELSE - { - diff = sub( prescale_current_frame, prescale ); - } - mem_fx[4] = L_deposit_l( prescale_current_frame ); - move32(); -#else diff = sub( prescale_current_frame, prescale ); -#endif - W_y1 = W_shr( W_y1, diff ); W_y2 = W_shr( W_y2, diff ); x2 = L_shr( x2, diff ); -- GitLab From 56448500a6cc7d5050c54a08ed9d574af60717c5 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Mon, 3 Nov 2025 20:51:24 +0100 Subject: [PATCH 5/5] empty commit to push -- GitLab