From d51b093cd572f7e3cfe7c91ec8c38f72b03f9c15 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jan 2026 15:56:41 +0100 Subject: [PATCH 1/3] fix FIX_2320_OOB_SCE_SWITCHING --- lib_com/options.h | 1 + lib_enc/ivas_corecoder_enc_reconfig_fx.c | 47 ++++++++++++++++++++++-- lib_enc/ivas_cpe_enc_fx.c | 16 +++++++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 4a272cf24..806e6261c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -145,6 +145,7 @@ #define FIX_2315_AGC_MEMORY_RESET /* VA: basop issue 2315: fix reset of the AGC memory */ #define FIX_2312_CONDITION_MISSING_GSC_DEC_LR /* VA: basop issue 2297: addition of condition missing in the GSC gain decoder at low-rate */ #define FIX_2313_HF_RESET_16KHZ /* VA: basop issue 2313: Call hf_synth_reset_fx() also for 16 kHz output_Fs */ +#define FIX_2320_OOB_SCE_SWITCHING /* VA: basop issue 2320: Correct the length of the buffer to be scaled in SCE/CPE switching */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/ivas_corecoder_enc_reconfig_fx.c b/lib_enc/ivas_corecoder_enc_reconfig_fx.c index 2efae00e2..c2763aa5b 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig_fx.c +++ b/lib_enc/ivas_corecoder_enc_reconfig_fx.c @@ -227,6 +227,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( Word16 q_com_cpe = Q15, q_com_cpe32 = Q31; move16(); move16(); +#ifdef FIX_2320_OOB_SCE_SWITCHING + Word16 len_fir = NS2SA_FX2( hEncoderConfig->input_Fs, DELAY_FIR_RESAMPL_NS ); +#endif IF( nSCE_old > 0 ) { FOR( k = 0; k < nSCE_old; k++ ) @@ -236,8 +239,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ); +#ifdef FIX_2320_OOB_SCE_SWITCHING + shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, len_fir ) ), Q1 ); + scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ +#else shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ +#endif st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ); @@ -247,8 +255,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32, shift ); move16(); q_com_sce32 = s_min( q_com_sce32, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 ); +#ifdef FIX_2320_OOB_SCE_SWITCHING + shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, add( input_frame, len_fir ) ), Q1 ); + scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ +#else shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ +#endif st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32, shift ); move16(); q_com_sce32 = s_min( q_com_sce32, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 ); @@ -267,8 +280,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ); +#ifdef FIX_2320_OOB_SCE_SWITCHING + shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, len_fir ) ), Q1 ); + scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ +#else shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ +#endif st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ); @@ -278,8 +296,13 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32, shift ); move16(); q_com_cpe32 = s_min( q_com_cpe32, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 ); +#ifdef FIX_2320_OOB_SCE_SWITCHING + shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, add( input_frame, len_fir ) ), Q1 ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ +#else shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ +#endif st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32, shift ); move16(); q_com_cpe32 = s_min( q_com_cpe32, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 ); @@ -294,10 +317,18 @@ ivas_error ivas_corecoder_enc_reconfig_fx( scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ) ); /* q_com */ st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = q_com; move16(); - scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ +#ifdef FIX_2320_OOB_SCE_SWITCHING + scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, len_fir ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ +#else + scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ +#endif st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = q_com; move16(); - Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ +#ifdef FIX_2320_OOB_SCE_SWITCHING + Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, add( shl( input_frame, 1 ), len_fir ), Q6 ); /* Q6 + q_com */ +#else + Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ +#endif st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( Q6, q_com ); st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 = add( Q6, q_com ); move16(); @@ -314,10 +345,18 @@ ivas_error ivas_corecoder_enc_reconfig_fx( scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); /* q_com */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = q_com; move16(); - scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ +#ifdef FIX_2320_OOB_SCE_SWITCHING + scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, len_fir ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ +#else + scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ +#endif st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = q_com; move16(); +#ifdef FIX_2320_OOB_SCE_SWITCHING + Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, add( shl( input_frame, 1 ), len_fir ), Q6 ); /* Q6 + q_com */ +#else Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ +#endif st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( Q6, q_com ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 = add( Q6, q_com ); move16(); diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 7792f57d3..fd0a9b01a 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -437,10 +437,18 @@ ivas_error ivas_cpe_enc_fx( * Temporal inter-channel alignment, stereo adjustment *----------------------------------------------------------------*/ +#ifdef FIX_2320_OOB_SCE_SWITCHING + Word16 len_input_buff = add( shl( input_frame, 1 ), NS2SA_FX2( hEncoderConfig->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, len_input_buff ), L_norm_arr( sts[1]->input_buff32_fx, len_input_buff ) ); + q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) ); + scale_sig32( sts[1]->input_buff32_fx, len_input_buff, sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ + scale_sig32( sts[0]->input_buff32_fx, len_input_buff, sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ +#else shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ); q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) ); scale_sig32( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ scale_sig32( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ +#endif sts[0]->q_inp32 = sts[1]->q_inp32 = sts[0]->q_old_inp32 = sts[1]->q_old_inp32 = q_min; move16(); move16(); @@ -449,11 +457,17 @@ ivas_error ivas_cpe_enc_fx( stereo_tca_enc_fx( hCPE, input_frame ); +#ifdef FIX_2320_OOB_SCE_SWITCHING + shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, len_input_buff ), sts[0]->q_inp32 ), 16 ); + shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, len_input_buff ), sts[1]->q_inp32 ), 16 ) ); + Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, len_input_buff, sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift + Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, len_input_buff, sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift +#else shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ); shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[1]->q_inp32 ), 16 ) ); Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift - +#endif sts[0]->q_inp = sts[1]->q_inp = sts[0]->q_old_inp = sts[1]->q_old_inp = shift; move16(); move16(); -- GitLab From f58f7608c19937c12b89857eca05f1bb0635a014 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jan 2026 16:07:10 +0100 Subject: [PATCH 2/3] simplification --- lib_enc/ivas_corecoder_enc_reconfig_fx.c | 27 +++++++++++------------- lib_enc/ivas_cpe_enc_fx.c | 15 ++++++------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/lib_enc/ivas_corecoder_enc_reconfig_fx.c b/lib_enc/ivas_corecoder_enc_reconfig_fx.c index c2763aa5b..76e388498 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig_fx.c +++ b/lib_enc/ivas_corecoder_enc_reconfig_fx.c @@ -227,9 +227,6 @@ ivas_error ivas_corecoder_enc_reconfig_fx( Word16 q_com_cpe = Q15, q_com_cpe32 = Q31; move16(); move16(); -#ifdef FIX_2320_OOB_SCE_SWITCHING - Word16 len_fir = NS2SA_FX2( hEncoderConfig->input_Fs, DELAY_FIR_RESAMPL_NS ); -#endif IF( nSCE_old > 0 ) { FOR( k = 0; k < nSCE_old; k++ ) @@ -240,8 +237,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ); #ifdef FIX_2320_OOB_SCE_SWITCHING - shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, len_fir ) ), Q1 ); - scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ + shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame ), Q1 ); + scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ #else shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ @@ -256,8 +253,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); q_com_sce32 = s_min( q_com_sce32, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 ); #ifdef FIX_2320_OOB_SCE_SWITCHING - shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, add( input_frame, len_fir ) ), Q1 ); - scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ + shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, input_frame ), Q1 ); + scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, input_frame, shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ #else shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ @@ -281,8 +278,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ); #ifdef FIX_2320_OOB_SCE_SWITCHING - shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, len_fir ) ), Q1 ); - scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ + shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame ), Q1 ); + scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ #else shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ @@ -297,8 +294,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); q_com_cpe32 = s_min( q_com_cpe32, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 ); #ifdef FIX_2320_OOB_SCE_SWITCHING - shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, add( input_frame, len_fir ) ), Q1 ); - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, add( input_frame, len_fir ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ + shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, input_frame ), Q1 ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, input_frame, shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ #else shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ @@ -318,14 +315,14 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = q_com; move16(); #ifdef FIX_2320_OOB_SCE_SWITCHING - scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, len_fir ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ + scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ #else scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ #endif st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = q_com; move16(); #ifdef FIX_2320_OOB_SCE_SWITCHING - Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, add( shl( input_frame, 1 ), len_fir ), Q6 ); /* Q6 + q_com */ + Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, shl( input_frame, 1 ), Q6 ); /* Q6 + q_com */ #else Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ #endif @@ -346,14 +343,14 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = q_com; move16(); #ifdef FIX_2320_OOB_SCE_SWITCHING - scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, len_fir ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ + scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ #else scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ #endif st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = q_com; move16(); #ifdef FIX_2320_OOB_SCE_SWITCHING - Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, add( shl( input_frame, 1 ), len_fir ), Q6 ); /* Q6 + q_com */ + Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, shl( input_frame, 1 ), Q6 ); /* Q6 + q_com */ #else Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ #endif diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index fd0a9b01a..569a924f8 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -438,11 +438,10 @@ ivas_error ivas_cpe_enc_fx( *----------------------------------------------------------------*/ #ifdef FIX_2320_OOB_SCE_SWITCHING - Word16 len_input_buff = add( shl( input_frame, 1 ), NS2SA_FX2( hEncoderConfig->input_Fs, DELAY_FIR_RESAMPL_NS ) ); - shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, len_input_buff ), L_norm_arr( sts[1]->input_buff32_fx, len_input_buff ) ); + shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, shl( input_frame, 1 ) ), L_norm_arr( sts[1]->input_buff32_fx, shl( input_frame, 1 ) ) ); q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) ); - scale_sig32( sts[1]->input_buff32_fx, len_input_buff, sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ - scale_sig32( sts[0]->input_buff32_fx, len_input_buff, sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ + scale_sig32( sts[1]->input_buff32_fx, shl( input_frame, 1 ), sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ + scale_sig32( sts[0]->input_buff32_fx, shl( input_frame, 1 ), sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ #else shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ); q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) ); @@ -458,10 +457,10 @@ ivas_error ivas_cpe_enc_fx( stereo_tca_enc_fx( hCPE, input_frame ); #ifdef FIX_2320_OOB_SCE_SWITCHING - shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, len_input_buff ), sts[0]->q_inp32 ), 16 ); - shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, len_input_buff ), sts[1]->q_inp32 ), 16 ) ); - Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, len_input_buff, sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift - Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, len_input_buff, sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift + shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, shl( input_frame, 1 ) ), sts[0]->q_inp32 ), 16 ); + shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, shl( input_frame, 1 ) ), sts[1]->q_inp32 ), 16 ) ); + Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, shl( input_frame, 1 ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift + Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, shl( input_frame, 1 ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift #else shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ); shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[1]->q_inp32 ), 16 ) ); -- GitLab From 181180dd8e4ff803c80b149222f2c415598d7979 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jan 2026 18:47:16 +0100 Subject: [PATCH 3/3] optimization --- lib_enc/ivas_cpe_enc_fx.c | 48 ++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 010d1e2e2..842c4be34 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -130,7 +130,10 @@ ivas_error ivas_cpe_enc_fx( Word16 NFFT_inner; move16(); move16(); - Word16 q_com, shift, q_min, gb; +#ifdef FIX_2320_OOB_SCE_SWITCHING + Word16 input_frame_2; +#endif + Word16 i, j, q_com, shift, q_min, gb; error = IVAS_ERR_OK; move32(); @@ -156,6 +159,9 @@ ivas_error ivas_cpe_enc_fx( * Initialization - general *-----------------------------------------------------------------*/ +#ifdef FIX_2320_OOB_SCE_SWITCHING + input_frame_2 = shl( input_frame, 1 ); +#endif set16_fx( q_re_im_buf, 0, CPE_CHANNELS ); tdm_SM_or_LRTD_Pri = 0; @@ -178,7 +184,7 @@ ivas_error ivas_cpe_enc_fx( set16_fx( voicing_fr_fx[0], 0, NB_SUBFR ); set16_fx( voicing_fr_fx[1], 0, NB_SUBFR ); - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { set16_zero_fx( fft_buff_fx[i], 2 * L_FFT ); set16_zero_fx( old_inp_16k_16fx[i], L_INP ); @@ -252,9 +258,9 @@ ivas_error ivas_cpe_enc_fx( move16(); } - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { - FOR( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) { set_zero_fx( realBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); set_zero_fx( imagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); @@ -408,8 +414,13 @@ ivas_error ivas_cpe_enc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { gb = find_guarded_bits_fx( sts[0]->encoderLookahead_FB ); +#ifdef FIX_2320_OOB_SCE_SWITCHING + shift = L_norm_arr( sts[1]->old_input_signal32_fx, input_frame_2 ); + shift = s_min( shift, L_norm_arr( sts[0]->old_input_signal32_fx, input_frame_2 ) ); +#else shift = L_norm_arr( sts[1]->old_input_signal32_fx, shl( input_frame, 1 ) ); shift = s_min( shift, L_norm_arr( sts[0]->old_input_signal32_fx, shl( input_frame, 1 ) ) ); +#endif IF( LT_16( shift, gb ) ) { @@ -436,10 +447,10 @@ ivas_error ivas_cpe_enc_fx( *----------------------------------------------------------------*/ #ifdef FIX_2320_OOB_SCE_SWITCHING - shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, shl( input_frame, 1 ) ), L_norm_arr( sts[1]->input_buff32_fx, shl( input_frame, 1 ) ) ); + shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, input_frame_2 ), L_norm_arr( sts[1]->input_buff32_fx, input_frame_2 ) ); q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) ); - scale_sig32( sts[1]->input_buff32_fx, shl( input_frame, 1 ), sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ - scale_sig32( sts[0]->input_buff32_fx, shl( input_frame, 1 ), sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ + scale_sig32( sts[1]->input_buff32_fx, input_frame_2, sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ + scale_sig32( sts[0]->input_buff32_fx, input_frame_2, sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ #else shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ); q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) ); @@ -455,10 +466,10 @@ ivas_error ivas_cpe_enc_fx( stereo_tca_enc_fx( hCPE, input_frame ); #ifdef FIX_2320_OOB_SCE_SWITCHING - shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, shl( input_frame, 1 ) ), sts[0]->q_inp32 ), 16 ); - shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, shl( input_frame, 1 ) ), sts[1]->q_inp32 ), 16 ) ); - Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, shl( input_frame, 1 ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift - Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, shl( input_frame, 1 ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift + shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, input_frame_2 ), sts[0]->q_inp32 ), 16 ); + shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, input_frame_2 ), sts[1]->q_inp32 ), 16 ) ); + Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, input_frame_2, sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift + Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, input_frame_2, sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift #else shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ); shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[1]->q_inp32 ), 16 ) ); @@ -728,12 +739,9 @@ ivas_error ivas_cpe_enc_fx( move16(); /* Determine the energy ratio between the 2 channels */ - tdm_ratio_idx = stereo_tdm_ener_analysis_fx( - ivas_format, - hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Q0 */ + tdm_ratio_idx = stereo_tdm_ener_analysis_fx( ivas_format, hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Q0 */ /* Compute the downmix signal based on the ratio index */ - Word16 tdm_SM_flag; IF( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) { @@ -855,11 +863,19 @@ ivas_error ivas_cpe_enc_fx( // Normalise the input buffer from Q15 Word16 input_norm, q_inp; //, common_q, fir_delay_len; +#ifdef FIX_2320_OOB_SCE_SWITCHING + input_norm = L_norm_arr( sts[0]->input32_fx - input_frame, input_frame_2 ); +#else input_norm = L_norm_arr( sts[0]->input32_fx - input_frame, shl( input_frame, 1 ) ); +#endif q_inp = sub( add( Q15, input_norm ), 16 ); // Rescale the old input, input and FIR delay section of input buffer +#ifdef FIX_2320_OOB_SCE_SWITCHING + Copy_Scale_sig32_16( sts[0]->input32_fx - input_frame, sts[0]->input_fx - input_frame, input_frame_2, sub( add( Q16, q_inp ), Q15 ) ); // Q15 -> q_inp +#else Copy_Scale_sig32_16( sts[0]->input32_fx - input_frame, sts[0]->input_fx - input_frame, shl( input_frame, 1 ), sub( add( Q16, q_inp ), Q15 ) ); // Q15 -> q_inp +#endif // Update the Q-factors sts[0]->q_inp = q_inp; @@ -1207,7 +1223,7 @@ ivas_error ivas_cpe_enc_fx( } } - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { Copy_Scale_sig_16_32_no_sat( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, Q16 ); // Q(-1) -> Q15 } -- GitLab