From ce3ba2950404e5a188c61232a411a48350ed86ed Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 2 Apr 2025 12:40:42 +0530 Subject: [PATCH] Fix for 3GPP issue 1445: Deviations with MCT between BASOP and float for LTV 5.1 coded with 128kbps - 1 Link #1445 --- lib_enc/amr_wb_enc_fx.c | 2 +- lib_enc/bw_detect_fx.c | 12 +++++++++--- lib_enc/ivas_core_pre_proc_front_fx.c | 2 +- lib_enc/ivas_mdct_core_enc_fx.c | 9 +++++---- lib_enc/pre_proc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 14 +++++++------- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 6f46e5c12..1580a7818 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -372,7 +372,7 @@ void amr_wb_enc_fx( * WB, SWB and FB bandwidth detector *----------------------------------------------------------------*/ - bw_detect_fx( st, st->input_fx, NULL, NULL, NULL, MONO_FORMAT, 0 ); + bw_detect_fx( st, st->input_fx, NULL, NULL, NULL, MONO_FORMAT, 0, 0 ); /* in AMR_WB IO, limit the maximum band-width to WB */ if ( GT_16( st->bwidth, WB ) ) diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 2e9b2c5db..8a150d514 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -41,12 +41,12 @@ void bw_detect_fx( Encoder_State *st, /* i/o: Encoder State */ const Word16 signal_in[], /* i : input signal */ - Word16 *spectrum, /* i : MDCT spectrum */ + Word16 *spectrum, /* i : MDCT spectrum Q_spec */ const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ const Word16 *cldfbBuf_Ener_Exp, /* i : CLDFB Energy Exponent */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 mct_on /* i : flag MCT mode */ -) + const Word16 mct_on, /* i : flag MCT mode */ + const Word16 Q_spec ) { Word16 Q_dct; Word16 i, j, k, bw_max, bin_width, n_bins; @@ -312,6 +312,11 @@ void bw_detect_fx( bin_width = i_mult( bin_width, l_frame / BWD_TOTAL_WIDTH ); Copy( spectrum, spect, l_frame ); + if ( st->element_mode != EVS_MONO ) + { + Q_dct = Q_spec; + move16(); + } } /*---------------------------------------------------------------------* * compute energy per spectral bins @@ -903,6 +908,7 @@ void bw_detect_fx( return; } + /*-------------------------------------------------------------------* * set_bw_fx() * diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 34d90a165..bb065ae20 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -870,7 +870,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 input_fx_tmp[480]; Copy_Scale_sig( st->input_fx, input_fx_tmp, shr( input_frame, 1 ), negate( st->q_inp ) ); /*scaling from Q_inp_const to q0*/ - bw_detect_fx( st, input_fx_tmp, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0 ); + bw_detect_fx( st, input_fx_tmp, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0, 0 ); } IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) diff --git a/lib_enc/ivas_mdct_core_enc_fx.c b/lib_enc/ivas_mdct_core_enc_fx.c index e27ec8c11..7c3daebda 100644 --- a/lib_enc/ivas_mdct_core_enc_fx.c +++ b/lib_enc/ivas_mdct_core_enc_fx.c @@ -1283,16 +1283,17 @@ void ivas_mdct_core_whitening_enc_fx( FOR( n = 0; n < nSubframes; n++ ) { Word16 spect_fx[L_FRAME48k]; - Word16 q_spectrum, l_frame; + Word16 q_spectrum, lshift, l_frame; /*l_frame = (int16_t)(st->input_Fs / FRAMES_PER_SEC); 1 / FRAMES_PER_SEC = 0.2f */ l_frame = extract_l( Mpy_32_32( st->input_Fs, 42949673 /* 0.2f in Q31 */ ) ); if ( EQ_16( st->core, TCX_10_CORE ) ) { l_frame = shr( l_frame, 1 ); } - q_spectrum = L_norm_arr( st->hTcxEnc->spectrum_fx[n], l_frame ); - Copy_Scale_sig32_16( st->hTcxEnc->spectrum_fx[n], spect_fx, l_frame, q_spectrum ); - bw_detect_fx( st, NULL, spect_fx, NULL, NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); + lshift = L_norm_arr( st->hTcxEnc->spectrum_fx[n], l_frame ); + Copy_Scale_sig32_16( st->hTcxEnc->spectrum_fx[n], spect_fx, l_frame, lshift ); + q_spectrum = sub( add( sub( Q31, st->hTcxEnc->spectrum_e[n] ), lshift ), 16 ); + bw_detect_fx( st, NULL, spect_fx, NULL, NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on, q_spectrum ); test(); if ( EQ_16( nSubframes, NB_DIV ) && n == 0 ) diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index efecb33ed..cbb2cf421 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -298,7 +298,7 @@ void pre_proc_fx( move16(); } - bw_detect_fx( st, signal_in, NULL, enerBuffer, sf_energySum, MONO_FORMAT, 0 ); + bw_detect_fx( st, signal_in, NULL, enerBuffer, sf_energySum, MONO_FORMAT, 0, 0 ); /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 3f7f17fe7..e54d3025e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -138,13 +138,13 @@ void AVQ_encmux_ivas_fx( void bw_detect_fx( Encoder_State *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : i signal */ - Word16 *spectrum, /* i : MDCT spectrum */ - const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ - const Word16 *cldfbBuf_Ener_Exp, /* i : CLDFB Energy Exponent */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 mct_on /* i : flag MCT mode */ -); + const Word16 signal_in[], /* i : input signal */ + Word16 *spectrum, /* i : MDCT spectrum Q_spec */ + const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ + const Word16 *cldfbBuf_Ener_Exp, /* i : CLDFB Energy Exponent */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 mct_on, /* i : flag MCT mode */ + const Word16 Q_spec ); void core_switching_post_enc_fx( /*done */ Encoder_State *st_fx, /* i/o: encoder state structure */ -- GitLab