From 8d903edcba85e12ba4c8f893c1fee5385098bcae Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 3 Dec 2025 11:23:06 -0500 Subject: [PATCH 1/3] 2261, remove unnecessary Aq scaling --- lib_com/options.h | 2 +- lib_enc/acelp_core_enc_fx.c | 8 ++++++++ lib_enc/ivas_core_enc_fx.c | 4 ++++ lib_enc/ivas_front_vad_fx.c | 3 ++- lib_enc/ivas_ism_enc_fx.c | 3 ++- lib_enc/updt_enc_fx.c | 5 +++++ 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 1a7b596d5..bf41d29d9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -96,7 +96,7 @@ #define FIX_2015_PREMPH_SAT_ALT_PART2 /* VA: Add missing scaling factor to be passed to AVQ_cod() */ #define FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH /* VA: Fix Issue 2253 where the encoder and decoder could get out of sync */ #define NONBE_FIX_1967_SBA_DECODER_MONO_OUT_BIG_DIFFERENCES /* Dolby: Fix basop issue 1967 */ - +#define FIX_2261_REMOVE_LP_RESCALING /* VA: Remove of unnecessary lpc coefficient rescaling */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index ff4c684e8..80a2847b8 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1099,11 +1099,13 @@ ivas_error acelp_core_enc_ivas_fx( move16(); st->hLPDmem->q_mem_syn = st->Q_syn; move16(); +#ifndef FIX_2261_REMOVE_LP_RESCALING // Scaling Aq to Q12 FOR( Word16 k = 0; k < NB_SUBFR16k; k++ ) { Scale_sig( &Aq[( M + 1 ) * k], M + 1, sub( norm_s( Aq[( M + 1 ) * k] ), 2 ) ); } +#endif /* synthesis at 12.8kHz sampling rate */ syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, sub( Q_new, 1 ), st->Q_syn ); @@ -1244,11 +1246,13 @@ ivas_error acelp_core_enc_ivas_fx( st->stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); // Q15 move16(); } +#ifndef FIX_2261_REMOVE_LP_RESCALING // Scaling Aq to Q12 FOR( Word16 k = 0; k < NB_SUBFR16k; k++ ) { Scale_sig( &Aq[( M + 1 ) * k], M + 1, sub( norm_s( Aq[( M + 1 ) * k] ), 2 ) ); } +#endif test(); IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO ) { @@ -1455,6 +1459,10 @@ ivas_error acelp_core_enc_ivas_fx( { Copy( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 } +#ifdef FIX_2261_REMOVE_LP_RESCALING + // Scaling Aq to Q12 + Scale_sig( st->hBWE_TD->cur_sub_Aq_fx, M + 1, sub( norm_s( st->hBWE_TD->cur_sub_Aq_fx[0] ), 2 ) ); +#endif } diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 96bbca887..4aa814406 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -224,11 +224,13 @@ ivas_error ivas_core_enc_fx( Scale_sig( fft_buff_fx[n], ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum // fft_buff_fx_exp = add(fft_buff_fx_exp,1); +#ifndef FIX_2261_REMOVE_LP_RESCALING FOR( i = 0; i < st->nb_subfr; i++ ) { Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } +#endif IF( EQ_32( ivas_format, SBA_FORMAT ) ) { IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, @@ -334,10 +336,12 @@ ivas_error ivas_core_enc_fx( test(); IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { +#ifndef FIX_2261_REMOVE_LP_RESCALING FOR( i = 0; i < st->nb_subfr; i++ ) { Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } +#endif TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; Word16 Q_spec_old, L_spec; diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index 35400f652..f3809f436 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -636,8 +636,9 @@ ivas_error front_vad_spar_fx( } relE_fx = sub( Etot_fx[0], extract_h( st->lp_speech_32fx ) ); +#ifndef FIX_2261_REMOVE_LP_RESCALING Scale_sig( A_fx, ( L_FRAME / L_SUBFR ) * ( M + 1 ), -2 ); // Q12 - +#endif st->mem_wsp_fx = (Word16) shl_sat( st->mem_wsp_fx, Q_inp_12k8 - st->mem_wsp_q ); /* Q_inp_12k8 */ st->mem_wsp_q = Q_inp_12k8; move16(); diff --git a/lib_enc/ivas_ism_enc_fx.c b/lib_enc/ivas_ism_enc_fx.c index ea509dd10..6a1d1e676 100644 --- a/lib_enc/ivas_ism_enc_fx.c +++ b/lib_enc/ivas_ism_enc_fx.c @@ -238,11 +238,12 @@ ivas_error ivas_ism_enc_fx( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ +#ifndef FIX_2261_REMOVE_LP_RESCALING FOR( i = 0; i < hSCE->hCoreCoder[0]->nb_subfr; i++ ) { Scale_sig( &A_fx[sce_id][0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[sce_id][0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } - +#endif set16_fx( old_wsp_fx[sce_id][0], 0, L_WSP ); q_old_wsp = Q15; move16(); diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index 62af228a0..b8975905e 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -141,6 +141,11 @@ void updt_enc_fx( } /* core switching updates */ Copy( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8_fx, M + 1 ); +#ifdef FIX_2261_REMOVE_LP_RESCALING + // Scaling Aq to Q12 + Scale_sig( st->old_Aq_12_8_fx, M + 1, sub( norm_s( st->old_Aq_12_8_fx[0] ), 2 ) ); +#endif + st->old_Es_pred_fx = Es_pred; move16(); -- GitLab From 85ddbe3bbfa22fa04c132343c75f0bfb06b9ad9f Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 3 Dec 2025 16:05:41 -0500 Subject: [PATCH 2/3] Tentative to fix crash, and EVS BE --- lib_enc/acelp_core_enc_fx.c | 4 ---- lib_enc/ivas_core_enc_fx.c | 4 ++-- lib_enc/updt_enc_fx.c | 4 ---- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 80a2847b8..6fe47c6dd 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1459,10 +1459,6 @@ ivas_error acelp_core_enc_ivas_fx( { Copy( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 } -#ifdef FIX_2261_REMOVE_LP_RESCALING - // Scaling Aq to Q12 - Scale_sig( st->hBWE_TD->cur_sub_Aq_fx, M + 1, sub( norm_s( st->hBWE_TD->cur_sub_Aq_fx[0] ), 2 ) ); -#endif } diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 4aa814406..36ee1a0da 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -224,13 +224,13 @@ ivas_error ivas_core_enc_fx( Scale_sig( fft_buff_fx[n], ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum // fft_buff_fx_exp = add(fft_buff_fx_exp,1); -#ifndef FIX_2261_REMOVE_LP_RESCALING FOR( i = 0; i < st->nb_subfr; i++ ) { +#ifndef FIX_2261_REMOVE_LP_RESCALING Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 +#endif Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } -#endif IF( EQ_32( ivas_format, SBA_FORMAT ) ) { IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index b8975905e..a9b15cfe4 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -141,10 +141,6 @@ void updt_enc_fx( } /* core switching updates */ Copy( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8_fx, M + 1 ); -#ifdef FIX_2261_REMOVE_LP_RESCALING - // Scaling Aq to Q12 - Scale_sig( st->old_Aq_12_8_fx, M + 1, sub( norm_s( st->old_Aq_12_8_fx[0] ), 2 ) ); -#endif st->old_Es_pred_fx = Es_pred; move16(); -- GitLab From f9b88a260e86b535d148fd641c62b659dc0ad11e Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 3 Dec 2025 16:44:03 -0500 Subject: [PATCH 3/3] Fix clang --- 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 36ee1a0da..e79c5bd4c 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -227,7 +227,7 @@ ivas_error ivas_core_enc_fx( FOR( i = 0; i < st->nb_subfr; i++ ) { #ifndef FIX_2261_REMOVE_LP_RESCALING - Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 + Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 #endif Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } -- GitLab