From 132d8b831cb0e12e433df95bc50ce3ef25659063 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 11 Apr 2025 20:57:11 +0530 Subject: [PATCH] Fix for 3GPP issue 1472: Precision issue with power spectrum causes different behavior with silent channels in MCT Link #1472 --- lib_com/ivas_sns_com_fx.c | 13 ++++++++++--- lib_enc/ivas_core_enc_fx.c | 27 ++++++++++++++++++++++++++- lib_enc/ivas_core_pre_proc_front_fx.c | 13 ------------- lib_enc/ivas_core_pre_proc_fx.c | 12 +++++++----- lib_enc/ivas_cpe_enc_fx.c | 2 +- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index fa64b0092..f1e44be78 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -200,9 +200,16 @@ void sns_compute_scf_fx( /* mean = sum / FDNS_NPTS; -Q6 is for division with FDNS_NPTS and -Q1 is to reduce Q by one */ - mean = W_shl_sat_l( sum, -Q7 ); // q_out - nf = Mpy_32_32( mean, 214748 /* powf( 10.0f, -4.0f ) in Q31 */ ); // q_out - nf = L_max( nf, L_shl( 256, sub( q_out, 40 ) ) /* powf( 2.0f, -32.0f ) in Q40 */ ); // q_out + mean = W_shl_sat_l( sum, -Q7 ); // q_out + nf = Mpy_32_32( mean, 214748 /* powf( 10.0f, -4.0f ) in Q31 */ ); // q_out + + IF( LE_32( nf, L_shl_sat( 256, sub( q_out, 40 ) ) ) ) /* powf( 2.0f, -32.0f ) in Q40 */ + { + nf = 256; + move32(); + q_out = 40; + move16(); + } FOR( i = 0; i < FDNS_NPTS; i++ ) { diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 3c62a0d18..066d105d5 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -419,7 +419,6 @@ ivas_error ivas_core_enc_fx( } } - /*---------------------------------------------------------------------* * MDCT stereo: joint TCX Core Encoding *---------------------------------------------------------------------*/ @@ -532,6 +531,12 @@ ivas_error ivas_core_enc_fx( st->hTcxEnc->exp_buf_speech_ltp = st->exp_buf_speech_enc; move16(); } + Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); + Scale_sig( st->input_fx - input_frame, input_frame, sub( -1, st->q_old_inp ) ); + st->q_inp = -1; + move16(); + st->q_old_inp = -1; + move16(); } Word16 Q_spec_old[2], L_spec; @@ -612,6 +617,8 @@ ivas_error ivas_core_enc_fx( * Postprocessing, BWEs and Updates *---------------------------------------------------------------------*/ + Word16 tmp_input_fx[L_FRAME48k], tmp_old_input_fx[L_FRAME48k], q_inp[2]; + FOR( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; @@ -626,6 +633,17 @@ ivas_error ivas_core_enc_fx( move16(); } + Copy( st->input_fx - input_frame, tmp_old_input_fx, input_frame ); + Copy( st->input_fx, tmp_input_fx, input_frame ); + q_inp[0] = st->q_old_inp; + q_inp[1] = st->q_inp; + + Scale_sig( st->input_fx - input_frame, 2 * input_frame, sub( -1, st->q_inp ) ); + st->q_inp = -1; + move16(); + st->q_old_inp = -1; + move16(); + /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ @@ -787,6 +805,13 @@ ivas_error ivas_core_enc_fx( } } + Copy( tmp_old_input_fx, st->input_fx - input_frame, input_frame ); + Copy( tmp_input_fx, st->input_fx, input_frame ); + st->q_old_inp = q_inp[0]; + move16(); + st->q_inp = q_inp[1]; + move16(); + /*---------------------------------------------------------------------* * Channel-aware mode - write signaling information into the bitstream *---------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 0d6a5901a..bac22a5b7 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1575,12 +1575,6 @@ ivas_error pre_proc_front_ivas_fx( move16(); IF( flag_16k_smc ) { - Scale_sig( st->input_fx - input_frame, input_frame_full, sub( -1, st->q_inp ) ); /* Q(-1) */ - st->q_inp = -1; - move16(); - st->q_old_inp = -1; - move16(); - Word16 Q_old_inp_16k = -1; move16(); @@ -1718,13 +1712,6 @@ ivas_error pre_proc_front_ivas_fx( st->exp_old_inp_12k8 = sub( Q15, add( *Q_new, shift ) ); move16(); - Scale_sig( st->input_fx - input_frame, input_frame_full, sub( -1, st->q_inp ) ); - st->q_inp = -1; - move16(); - st->q_old_inp = -1; - move16(); - - // Scale_sig( old_inp_12k8_fx, L_INP_12k8, negate( add( *Q_new, 1 ) ) ); *Q_new = sub( *Q_new, Q_inp_const ); // ivas_core_enc will assume inp signal (12k8 and 16k) in Q_new - 1 move16(); diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 781d290ac..b2ec13983 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -565,9 +565,6 @@ ivas_error pre_proc_ivas_fx( Scale_sig( st->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc_pe ) ) ); /* Q15 - Q_old_inp_16k */ st->exp_buf_speech_enc_pe = sub( Q15, Q_old_inp_16k ); move16(); - Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); - st->q_inp = -1; - move16(); Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); /* Q15 - Q_old_inp_16k */ st->mem_wsp_enc = shl( st->mem_wsp_enc, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); // Q_old_inp_16k move16(); @@ -713,7 +710,7 @@ ivas_error ivas_compute_core_buffers_fx( Word16 *inp_16k_fx, *new_inp_16k_fx; Word16 delay, element_mode; Word16 temp1F_icatdmResampBuf_fx[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ - Word16 mem_decim16k_dummy_fx[2 * L_FILT_MAX]; + Word16 mem_decim16k_dummy_fx[2 * L_FILT_MAX], input_buf_fx[L_FRAME48k * 2]; Word16 *signal_in_fx; Word16 lMemRecalc, lMemRecalc_16k, L_frame_tmp, L_look; Word32 input_Fs; @@ -733,7 +730,12 @@ ivas_error ivas_compute_core_buffers_fx( set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); set16_fx( epsP_h, 0, M + 1 ); set16_fx( epsP_l, 0, M + 1 ); - signal_in_fx = st->input_fx; /* st->q_inp */ + set16_fx( input_buf_fx, 0, L_FRAME48k * 2 ); + + Copy_Scale_sig( st->input_fx - input_frame, input_buf_fx, input_frame, sub( -1, st->q_old_inp ) ); + Copy_Scale_sig( st->input_fx, input_buf_fx + input_frame, input_frame, sub( -1, st->q_inp ) ); + + signal_in_fx = &input_buf_fx[input_frame]; /* st->q_inp */ input_Fs = st->input_Fs; /* Q0 */ move32(); diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 1bb31810d..b5ed69560 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -430,7 +430,7 @@ ivas_error ivas_cpe_enc_fx( stereo_tca_enc_fx( hCPE, input_frame ); - shift = s_min( 0, 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 = 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 -- GitLab