diff --git a/lib_com/options.h b/lib_com/options.h index a884d61ec7b505ad65665d3b7e013a20a3a02a20..8a87331cb5a58bffbb3ad71b6fd4c22cc4d80007 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -115,6 +115,7 @@ #define OPT_2308_FIND_TARGET /* VA: Issue 2308, Speeds up computation and improve accuracy of the impulse response */ #define OPT_NBE_2311_HARM_GSC_GAIN /* VA: issue 2311: non-BE part of the GSC gain harmonization */ #define FIX_2261_REMOVE_LP_RESCALING /* VA: Remove of unnecessary lpc coefficient rescaling */ +#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 2efae00e2752c4c7100add8f563723bd078a33e3..76e388498129b720ecec16abfb56b8e3c3bb5a3c 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig_fx.c +++ b/lib_enc/ivas_corecoder_enc_reconfig_fx.c @@ -236,8 +236,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, 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 */ +#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 +252,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, 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 */ +#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 +277,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, 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 */ +#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 +293,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, 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 */ + 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 +314,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, 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(); - 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, 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 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 +342,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, 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, 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 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 813cae04bed7c4f0bd26e5e3ede69a73407ba208..842c4be34fef22b9f2f7b3902ea42465c39e2cc1 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 ) ) { @@ -435,10 +446,17 @@ ivas_error ivas_cpe_enc_fx( * Temporal inter-channel alignment, stereo adjustment *----------------------------------------------------------------*/ +#ifdef FIX_2320_OOB_SCE_SWITCHING + 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, 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 ) ) ); 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(); @@ -447,11 +465,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, 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 ) ); 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(); @@ -715,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 ) { @@ -842,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; @@ -1194,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 }