From 5f77256c31f9f455f48b343692c6a7b0cae0f062 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 12 May 2025 19:44:36 +0530 Subject: [PATCH 1/2] Fix for 3GPP issue 1254: BASOP encoder OSBA 256 kbps: broken signal envelope Link #1254 --- lib_com/ivas_prot_fx.h | 2 +- lib_com/prot_fx.h | 46 ++++++++-------- lib_enc/igf_enc.c | 75 ++++++++++++++++++-------- lib_enc/ivas_mct_core_enc_fx.c | 31 +++++------ lib_enc/ivas_mct_enc_mct_fx.c | 14 +++-- lib_enc/ivas_stereo_mdct_core_enc_fx.c | 51 ++++-------------- lib_enc/tcx_utils_enc_fx.c | 20 +++---- 7 files changed, 116 insertions(+), 123 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 5816c60b5..5bdbd7d73 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3341,7 +3341,7 @@ void mctStereoIGF_enc_fx( Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate */ Word16 q_powerSpec[MCT_MAX_CHANNELS], /* i : Q for powSpec_fx */ Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : same as powerSpec_fx but for inverse spect.*/ - Word16 q_powerSpecMsInv[MCT_MAX_CHANNELS], /* i : Q for powSpecMsInv_fx */ + Word16 *q_powerSpecMsInv[MCT_MAX_CHANNELS][NB_DIV], /* i : Q for powSpecMsInv_fx */ Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */ const Word16 sp_aud_decision0[MCT_MAX_CHANNELS] /* i : speech audio decision */ ); diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 9b78b44d8..bbd5416da 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10841,32 +10841,32 @@ void ProcessStereoIGF_fx( Word32 *pITFMDCTSpectrum_fx[CPE_CHANNELS][NB_DIV], /* i : MDCT spectrum fir ITF */ Word16 q_pITFMDCTSpectrum_1, Word16 q_pITFMDCTSpectrum_2, - Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ - Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ - Word16 exp_pPowerSpectrumMsInv_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrumMsInv_fx */ - Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ - Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i/o: exp of inv_spectrum_fx */ - const Word16 frameno, /* i : flag indicating index of current subfr. */ - const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate, /* i : element bitrate */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ + Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i/o: exp of inv_spectrum_fx */ + const Word16 frameno, /* i : flag indicating index of current subfr. */ + const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ + const Word32 element_brate, /* i : element bitrate */ const Word16 mct_on ); /*igf_enc.c*/ void IGFEncApplyStereo_fx( - STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ - Word16 ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ - const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */ - const Word16 igfGridIdx, /* i : IGF grid index */ - Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ - Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ - Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ - Word16 exp_pPowerSpectrumMsInv_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrumMsInv_fx */ - Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ - Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i : exp of inverse spectrum */ - const Word16 frameno, /* i : flag indicating index of current subfr. */ - const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate, /* i : element bitrate */ + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ + Word16 ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ + const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */ + const Word16 igfGridIdx, /* i : IGF grid index */ + Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ + Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i : exp of inverse spectrum */ + const Word16 frameno, /* i : flag indicating index of current subfr. */ + const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ + const Word32 element_brate, /* i : element bitrate */ const Word16 mct_on ); void IGFSaveSpectrumForITF_ivas_fx( diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 9769d83b6..18995bd1d 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -1002,12 +1002,12 @@ static void IGF_CalculateStereoEnvelope_fx( const Word32 *pPowerSpectrum_fx, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ Word16 pPowerSpectrum_e, /* i : exponent for pPowerSpectrum_fx */ const Word32 *pPowerSpectrumMsInv_fx, /* i : inverse power spectrum */ - Word16 pPowerSpectrumMsInv_e, /* i : exponent for pPowerSpectrumMsInv_fx */ + Word16 *q_pPowerSpectrumMsInv, /* i : Q for pPowerSpectrumMsInv_fx */ const Word16 igfGridIdx, /* i : IGF grid index */ const Word16 coreMsMask[N_MAX], /* i : line wise ms Mask */ const Word16 isTransient, /* i : flag indicating if transient is detected */ - const Word16 last_core_acelp /* i : indicator if last frame was ACELP core */ -) + const Word16 last_core_acelp, /* i : indicator if last frame was ACELP core */ + const Word16 mct_on ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; @@ -1047,6 +1047,32 @@ static void IGF_CalculateStereoEnvelope_fx( Word16 slope_e; /*stores exponent for slope_fx*/ Word16 sfbEnergyR_e; /*stores exponent for sfbEnergyR*/ Word16 tmp_e; + Word32 temp_pPowerSpectrumMsInv[N_MAX], length; + Word16 q_temp_pPowerSpectrumMsInv = Q31, i; + move16(); + + IF( pPowerSpectrumMsInv_fx != NULL ) + { + length = N_MAX; + move16(); + if ( mct_on ) + { + length = L_FRAME48k; + move16(); + } + FOR( i = 0; i < length; i++ ) + { + IF( pPowerSpectrumMsInv_fx[i] != 0 ) + { + q_temp_pPowerSpectrumMsInv = s_min( q_temp_pPowerSpectrumMsInv, add( q_pPowerSpectrumMsInv[i], norm_l( pPowerSpectrumMsInv_fx[i] ) ) ); + } + } + FOR( i = 0; i < length; i++ ) + { + temp_pPowerSpectrumMsInv[i] = L_shl( pPowerSpectrumMsInv_fx[i], sub( q_temp_pPowerSpectrumMsInv, q_pPowerSpectrumMsInv[i] ) ); + move32(); + } + } hPrivateData = &hIGFEnc->igfData; hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; @@ -1130,10 +1156,10 @@ static void IGF_CalculateStereoEnvelope_fx( norm_exp = norm_l( pMDCTSpectrumMsInv_fx[strt_cpy] ); final_exp = sub( pMDCTSpectrumMsInv_e, norm_exp ); scaled_value = L_shl( pMDCTSpectrumMsInv_fx[strt_cpy], norm_exp ); - sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ - sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrumMsInv_fx[strt_cpy], pPowerSpectrumMsInv_e, &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ - tileSrcSpec_fx[sub( strt_cpy, tmp )] = pPowerSpectrumMsInv_fx[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ - tileSrcSpec_e = pPowerSpectrumMsInv_e; + sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ + sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrumMsInv_fx[strt_cpy], sub( 31, q_pPowerSpectrumMsInv[strt_cpy] ), &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ + tileSrcSpec_fx[sub( strt_cpy, tmp )] = temp_pPowerSpectrumMsInv[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ + tileSrcSpec_e = sub( 31, q_temp_pPowerSpectrumMsInv ); } ELSE { @@ -2620,24 +2646,25 @@ void IGFEncApplyMono_ivas_fx( *-------------------------------------------------------------------*/ void IGFEncApplyStereo_fx( - STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ - Word16 ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ - const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */ - const Word16 igfGridIdx, /* i : IGF grid index */ - Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ - Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ - Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ - Word16 exp_pPowerSpectrumMsInv_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrumMsInv_fx */ - Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ - Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i : exp of inverse spectrum */ - const Word16 frameno, /* i : flag indicating index of current subfr. */ - const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate, /* i : element bitrate */ + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ + Word16 ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ + const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */ + const Word16 igfGridIdx, /* i : IGF grid index */ + Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ + Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i : exp of inverse spectrum */ + const Word16 frameno, /* i : flag indicating index of current subfr. */ + const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ + const Word32 element_brate, /* i : element bitrate */ const Word16 mct_on ) { Word32 *pPowerSpectrumParameter_fx[NB_DIV]; /* If it is NULL it informs a function that specific handling is needed */ Word32 *pPowerSpectrumParameterMsInv_fx[NB_DIV]; + Word16 *q_pPowerSpectrumParameterMsInv_fx[NB_DIV]; Word16 coreMsMask[N_MAX]; Word16 sfb, ch, last_core_acelp; STEREO_MDCT_BAND_PARAMETERS *sfbConf; @@ -2681,6 +2708,8 @@ void IGFEncApplyStereo_fx( pPowerSpectrumParameter_fx[1] = &pPowerSpectrum_fx[1][0]; pPowerSpectrumParameterMsInv_fx[0] = pPowerSpectrumMsInv_fx[0][0]; pPowerSpectrumParameterMsInv_fx[1] = pPowerSpectrumMsInv_fx[1][0]; + q_pPowerSpectrumParameterMsInv_fx[0] = q_pPowerSpectrumMsInv_fx[0][0]; + q_pPowerSpectrumParameterMsInv_fx[1] = q_pPowerSpectrumMsInv_fx[1][0]; } ELSE { @@ -2688,6 +2717,8 @@ void IGFEncApplyStereo_fx( pPowerSpectrumParameter_fx[1] = NULL; pPowerSpectrumParameterMsInv_fx[0] = NULL; pPowerSpectrumParameterMsInv_fx[1] = NULL; + q_pPowerSpectrumParameterMsInv_fx[0] = NULL; + q_pPowerSpectrumParameterMsInv_fx[1] = NULL; } FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -2696,7 +2727,7 @@ void IGFEncApplyStereo_fx( IGF_UpdateInfo( hIGFEnc[ch], igfGridIdx ); IGF_CalculateStereoEnvelope_fx( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], sts[ch]->hTcxEnc->spectrum_e[frameno], inv_spectrum_fx[ch][frameno], exp_inv_spectrum_fx[ch], pPowerSpectrumParameter_fx[ch], exp_pPowerSpectrum_fx[ch], pPowerSpectrumParameterMsInv_fx[ch], - exp_pPowerSpectrumMsInv_fx[ch], igfGridIdx, coreMsMask, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp ); + q_pPowerSpectrumParameterMsInv_fx[ch], igfGridIdx, coreMsMask, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, mct_on ); IF( EQ_16( sts[ch]->core, TCX_20_CORE ) ) { diff --git a/lib_enc/ivas_mct_core_enc_fx.c b/lib_enc/ivas_mct_core_enc_fx.c index 0ab232dd9..71890120b 100644 --- a/lib_enc/ivas_mct_core_enc_fx.c +++ b/lib_enc/ivas_mct_core_enc_fx.c @@ -244,8 +244,8 @@ void ivas_mct_core_enc_fx( Word32 inv_spectrum_long_fx[MCT_MAX_CHANNELS][L_FRAME48k]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ Word16 total_side_bits; Word16 chBitRatios[MCT_MAX_CHANNELS]; - Word16 q_powSpec[MCT_MAX_CHANNELS], q_powerSpecMsInv[MCT_MAX_CHANNELS], q_spec, q_origSpec, tmp_s; - Word16 tmp_q_powSpec[L_FRAME48k], tmp_q_powSpecInv[L_FRAME48k], *tmp_q_psi[2]; + Word16 q_powSpec[MCT_MAX_CHANNELS], q_spec, q_origSpec, tmp_s; + Word16 tmp_q_powSpec[L_FRAME48k], tmp_q_powSpecInv[MCT_MAX_CHANNELS][L_FRAME48k], *tmp_q_psi[MCT_MAX_CHANNELS][2]; Word64 W_tmp; Encoder_State *sts[MCT_MAX_CHANNELS]; Encoder_State *st; @@ -285,16 +285,17 @@ void ivas_mct_core_enc_fx( inv_mdst_spectrum_fx[ch][0] = powerSpecMsInv_fx[ch][0] = powerSpecMsInv_long_fx[ch]; inv_mdst_spectrum_fx[ch][1] = powerSpecMsInv_fx[ch][1] = powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; + set16_fx( tmp_q_powSpecInv[ch], 63, L_FRAME48k ); + + tmp_q_psi[ch][0] = tmp_q_powSpecInv[ch]; + tmp_q_psi[ch][1] = &tmp_q_powSpecInv[ch][N_TCX10_MAX]; + inv_spectrum_fx[ch][0] = inv_spectrum_long_fx[ch]; inv_spectrum_fx[ch][1] = inv_spectrum_long_fx[ch] + N_TCX10_MAX; } - set16_fx( tmp_q_powSpecInv, 63, L_FRAME48k ); set16_fx( tmp_q_powSpec, 63, L_FRAME48k ); - tmp_q_psi[0] = tmp_q_powSpecInv; - tmp_q_psi[1] = &tmp_q_powSpecInv[N_TCX10_MAX]; - FOR( ( cpe_id = 0, i = 0 ); cpe_id < nCPE; cpe_id++ ) { FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -451,7 +452,7 @@ void ivas_mct_core_enc_fx( tmp_s = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, tmp_s ); powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); - tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + tmp_q_psi[ch][n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); } @@ -465,7 +466,7 @@ void ivas_mct_core_enc_fx( tmp_s = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, tmp_s ); powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_tmp ); - tmp_q_psi[n][0] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + tmp_q_psi[ch][n][0] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); @@ -477,7 +478,7 @@ void ivas_mct_core_enc_fx( tmp_s = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, tmp_s ); powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); - tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + tmp_q_psi[ch][n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); } @@ -486,7 +487,7 @@ void ivas_mct_core_enc_fx( tmp_s = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, tmp_s ); powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_tmp ); - tmp_q_psi[n][L_subframeTCX - 1] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + tmp_q_psi[ch][n][L_subframeTCX - 1] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); } @@ -529,8 +530,6 @@ void ivas_mct_core_enc_fx( { q_powSpec[ch] = Q31; move16(); - q_powerSpecMsInv[ch] = Q31; - move16(); /* NOTE: This logic has been added because using a constant headroom while computing `powSpec` and `powSpecMsInv` leads to significant precision loss, which results in poor quality. */ FOR( i = 0; i < L_FRAME48k; i++ ) { @@ -539,18 +538,12 @@ void ivas_mct_core_enc_fx( q_powSpec[ch] = s_min( q_powSpec[ch], add( tmp_q_powSpec[i], norm_l( powerSpec_fx[ch][i] ) ) ); move16(); } - IF( powerSpecMsInv_fx[ch][0][i] != 0 ) - { - q_powerSpecMsInv[ch] = s_min( q_powerSpecMsInv[ch], add( tmp_q_powSpecInv[i], norm_l( powerSpecMsInv_fx[ch][0][i] ) ) ); - move16(); - } } FOR( n = 0; n < nSubframes; n++ ) { FOR( i = 0; i < L_subframeTCX; i++ ) { - powerSpecMsInv_fx[ch][n][i] = L_shr( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_powerSpecMsInv[ch] ) ); powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )], sub( tmp_q_powSpec[i + ( n * L_subframeTCX )], q_powSpec[ch] ) ); move32(); move32(); @@ -609,7 +602,7 @@ void ivas_mct_core_enc_fx( { IF( hMCT->currBlockDataCnt > 0 ) { - mctStereoIGF_enc_fx( hMCT, sts, orig_spectrum_fx, q_origSpec, powerSpec_fx, q_powSpec, powerSpecMsInv_fx, q_powerSpecMsInv, inv_spectrum_fx, sp_aud_decision0 ); + mctStereoIGF_enc_fx( hMCT, sts, orig_spectrum_fx, q_origSpec, powerSpec_fx, q_powSpec, powerSpecMsInv_fx, tmp_q_psi, inv_spectrum_fx, sp_aud_decision0 ); } ELSE { diff --git a/lib_enc/ivas_mct_enc_mct_fx.c b/lib_enc/ivas_mct_enc_mct_fx.c index 94015abb7..8ff17ae01 100644 --- a/lib_enc/ivas_mct_enc_mct_fx.c +++ b/lib_enc/ivas_mct_enc_mct_fx.c @@ -986,19 +986,19 @@ void mctStereoIGF_enc_fx( Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate */ Word16 q_powerSpec[MCT_MAX_CHANNELS], /* i : Q for powSpec_fx */ Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : same as powerSpec_fx but for inverse spect.*/ - Word16 q_powerSpecMsInv[MCT_MAX_CHANNELS], /* i : Q for powSpecMsInv_fx */ + Word16 *q_powerSpecMsInv[MCT_MAX_CHANNELS][NB_DIV], /* i : Q for powSpecMsInv_fx */ Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */ const Word16 sp_aud_decision0[MCT_MAX_CHANNELS] /* i : speech audio decision */ ) { Word32 *p_powerSpecMsInv_fx[CPE_CHANNELS][NB_DIV]; + Word16 *q_p_powerSpecMsInv_fx[CPE_CHANNELS][NB_DIV]; Word32 *p_inv_spectrum_fx[CPE_CHANNELS][NB_DIV]; Word32 *p_orig_spectrum_fx[CPE_CHANNELS][NB_DIV]; Word32 *p_powerSpec_fx[NB_DIV]; Word16 b, nSubframes, L_subframeTCX; Word16 p_ch[2], n, ch, ch1, ch2; - Word16 q_pSI_ch[2]; Word16 q_pS_ch[2]; Encoder_State *p_st[NB_DIV]; Encoder_State *st; @@ -1059,12 +1059,12 @@ void mctStereoIGF_enc_fx( p_orig_spectrum_fx[1][n] = orig_spectrum_fx[ch2][n]; p_powerSpecMsInv_fx[0][n] = powerSpecMsInv_fx[ch1][n]; // q_powerSpec p_powerSpecMsInv_fx[1][n] = powerSpecMsInv_fx[ch2][n]; + q_p_powerSpecMsInv_fx[0][n] = q_powerSpecMsInv[ch1][n]; // q_powerSpec + q_p_powerSpecMsInv_fx[1][n] = q_powerSpecMsInv[ch2][n]; p_inv_spectrum_fx[0][n] = inv_spectrum_fx[ch1][n]; p_inv_spectrum_fx[1][n] = inv_spectrum_fx[ch2][n]; q_pS_ch[0] = q_powerSpec[ch1]; - q_pSI_ch[0] = q_powerSpecMsInv[ch1]; q_pS_ch[1] = q_powerSpec[ch2]; - q_pSI_ch[1] = q_powerSpecMsInv[ch2]; move16(); move16(); @@ -1072,20 +1072,18 @@ void mctStereoIGF_enc_fx( IF( NE_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[n], hMCT->hBlockData[b]->hStereoMdct->IGFStereoMode[n] ) || EQ_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[n], SMDCT_BW_MS ) ) { - Word16 exp_powerSpec_fx[CPE_CHANNELS], exp_powerSpecMsInv_fx[CPE_CHANNELS], exp_inv_spectrum_fx[CPE_CHANNELS]; + Word16 exp_powerSpec_fx[CPE_CHANNELS], exp_inv_spectrum_fx[CPE_CHANNELS]; FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { exp_powerSpec_fx[ch] = sub( Q31, q_pS_ch[ch] ); - exp_powerSpecMsInv_fx[ch] = sub( Q31, q_pSI_ch[ch] ); exp_inv_spectrum_fx[ch] = p_st[ch]->hTcxEnc->spectrum_e[n]; move16(); move16(); - move16(); } ProcessStereoIGF_fx( hMCT->hBlockData[b]->hStereoMdct, p_st, hMCT->hBlockData[b]->mask, p_orig_spectrum_fx, q_origSpec, q_origSpec, p_powerSpec_fx, exp_powerSpec_fx, - p_powerSpecMsInv_fx, exp_powerSpecMsInv_fx, p_inv_spectrum_fx, exp_inv_spectrum_fx, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 ); + p_powerSpecMsInv_fx, q_p_powerSpecMsInv_fx, p_inv_spectrum_fx, exp_inv_spectrum_fx, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 ); } ELSE { diff --git a/lib_enc/ivas_stereo_mdct_core_enc_fx.c b/lib_enc/ivas_stereo_mdct_core_enc_fx.c index 8acbc3e87..cbbc0d000 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_core_enc_fx.c @@ -137,8 +137,10 @@ void stereo_mdct_core_enc_fx( Word32 *orig_spectrum_fx[CPE_CHANNELS][NB_DIV]; /* Pointers to MDCT output for a short block (L/R) */ Word64 powerSpec64[CPE_CHANNELS][N_MAX]; Word16 exp_powerSpec64[CPE_CHANNELS][NB_DIV]; - Word32 powerSpecMsInv_long_fx[CPE_CHANNELS][N_MAX]; /* MS inv power spectrum, also inverse MDST spectrum */ + Word32 powerSpecMsInv_long_fx[CPE_CHANNELS][N_MAX]; /* MS inv power spectrum, also inverse MDST spectrum */ + Word16 q_powerSpecMsInv_long_fx[CPE_CHANNELS][N_MAX]; /*Q: MS inv power spectrum, also inverse MDST spectrum */ Word32 *powerSpecMsInv_fx[CPE_CHANNELS][NB_DIV]; + Word16 *q_powerSpecMsInv_fx[CPE_CHANNELS][NB_DIV]; Word32 quantized_spectrum_long_fx[CPE_CHANNELS][N_MAX]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ Word32 *quantized_spectrum_fx[CPE_CHANNELS][NB_DIV]; Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV]; @@ -152,8 +154,6 @@ void stereo_mdct_core_enc_fx( Word32 *p_mdst_spectrum_long_fx[CPE_CHANNELS]; Word32 mdst_spectrum_long_fx[CPE_CHANNELS][N_MAX]; Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV]; - Word16 exp_powSpecMsInv[MCT_MAX_CHANNELS]; - Word16 tmp_q_powSpecInv[N_MAX], *exp_powSpecInv[2]; Word64 W_tmp; Encoder_State *st, **sts; STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct; @@ -186,11 +186,6 @@ void stereo_mdct_core_enc_fx( set16_fx( exp_powerSpec64[ch], 0, NB_DIV ); } - set16_fx( tmp_q_powSpecInv, 63, N_MAX ); - - exp_powSpecInv[0] = tmp_q_powSpecInv; - exp_powSpecInv[1] = &tmp_q_powSpecInv[N_TCX10_MAX]; - sts = hCPE->hCoreCoder; hStereoMdct = hCPE->hStereoMdct; hBstr = sts[0]->hBstr; @@ -254,6 +249,9 @@ void stereo_mdct_core_enc_fx( { inv_mdst_spectrum_fx[ch][0] = powerSpecMsInv_fx[ch][0] = powerSpecMsInv_long_fx[ch]; inv_mdst_spectrum_fx[ch][1] = powerSpecMsInv_fx[ch][1] = powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; + q_powerSpecMsInv_fx[ch][0] = q_powerSpecMsInv_long_fx[ch]; + q_powerSpecMsInv_fx[ch][1] = q_powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; + set16_fx( q_powerSpecMsInv_long_fx[ch], 63, L_FRAME48k ); quantized_spectrum_fx[ch][0] = quantized_spectrum_long_fx[ch]; quantized_spectrum_fx[ch][1] = quantized_spectrum_long_fx[ch] + N_TCX10_MAX; inv_spectrum_fx[ch][0] = quantized_spectrum_fx[ch][0]; @@ -444,7 +442,7 @@ void stereo_mdct_core_enc_fx( W_tmp = W_mac_32_32( W_mult_32_32( imdct, imdct ), imdst, imdst ); // exp: 2*exp norm = W_norm( W_tmp ); powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*exp-norm - exp_powSpecInv[n][i] = sub( shl( exp, 1 ), norm ); + q_powerSpecMsInv_fx[ch][n][i] = sub( 31, sub( shl( exp, 1 ), norm ) ); move32(); move16(); @@ -464,7 +462,7 @@ void stereo_mdct_core_enc_fx( W_tmp = W_mult_32_32( mdct, mdct ); // exp: 2*(sts[ch]->hTcxEnc->spectrum_e[n]+1) (exp) norm = W_norm( W_tmp ); powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*(sts[ch]->hTcxEnc->spectrum_e[n]+1)-norm (exp-norm) - exp_powSpecInv[n][0] = sub( exp, norm ); + q_powerSpecMsInv_fx[ch][n][0] = sub( 31, sub( exp, norm ) ); move32(); move16(); @@ -477,7 +475,7 @@ void stereo_mdct_core_enc_fx( W_tmp = W_mac_32_32( W_mult_32_32( mdst, mdst ), mdct, mdct ); // exp: 2*(sts[ch]->hTcxEnc->spectrum_e[n]+1) (exp) norm = W_norm( W_tmp ); powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*(sts[ch]->hTcxEnc->spectrum_e[n]+1)-norm (exp-norm) - exp_powSpecInv[n][i] = sub( exp, norm ); + q_powerSpecMsInv_fx[ch][n][i] = sub( 31, sub( exp, norm ) ); move32(); move16(); } @@ -486,7 +484,7 @@ void stereo_mdct_core_enc_fx( W_tmp = W_mult_32_32( mdct, mdct ); // exp: 2*(sts[ch]->hTcxEnc->spectrum_e[n]+1) (exp) norm = W_norm( W_tmp ); powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*(sts[ch]->hTcxEnc->spectrum_e[n]+1)-norm (exp-norm) - exp_powSpecInv[n][L_subframeTCX - 1] = sub( exp, norm ); + q_powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = sub( 31, sub( exp, norm ) ); move32(); move16(); } @@ -512,33 +510,6 @@ void stereo_mdct_core_enc_fx( move16(); } } - - /* Aligning the Q-factors */ - exp = MIN_16; - move16(); - FOR( n = 0; n < nSubframes; n++ ) - { - FOR( i = 0; i < L_subframeTCX; i++ ) - { - if ( powerSpecMsInv_fx[ch][n][i] != 0 ) - { - exp = s_max( exp, exp_powSpecInv[n][i] ); - } - } - } - IF( NE_16( exp, MIN_16 ) ) - { - FOR( n = 0; n < nSubframes; n++ ) - { - FOR( i = 0; i < L_subframeTCX; i++ ) - { - powerSpecMsInv_fx[ch][n][i] = L_shl( powerSpecMsInv_fx[ch][n][i], sub( exp_powSpecInv[n][i], exp ) ); - move32(); - } - } - } - exp_powSpecMsInv[ch] = exp; - move16(); } FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -656,7 +627,7 @@ void stereo_mdct_core_enc_fx( move16(); ProcessStereoIGF_fx( hStereoMdct, sts, ms_mask, orig_spectrum_fx, sub( Q31, p_orig_spectrum_e[0] ), sub( Q31, p_orig_spectrum_e[1] ), - p_powerSpec_fx, exp_powSpec, powerSpecMsInv_fx, exp_powSpecMsInv, inv_spectrum_fx, exp_inv_spectrum, + p_powerSpec_fx, exp_powSpec, powerSpecMsInv_fx, q_powerSpecMsInv_fx, inv_spectrum_fx, exp_inv_spectrum, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate, 0 ); } ELSE diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index acc52c2aa..680a69fa5 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -4029,15 +4029,15 @@ void ProcessStereoIGF_fx( Word32 *pITFMDCTSpectrum_fx[CPE_CHANNELS][NB_DIV], /* i : MDCT spectrum fir ITF */ Word16 q_pITFMDCTSpectrum_1, Word16 q_pITFMDCTSpectrum_2, - Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ - Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ - Word16 exp_pPowerSpectrumMsInv_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrumMsInv_fx */ - Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ - Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i/o: exp of inv_spectrum_fx */ - const Word16 frameno, /* i : flag indicating index of current subfr. */ - const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate, /* i : element bitrate */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: exp of pPowerSpectrum_fx */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ + Word16 *q_pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: Q of pPowerSpectrumMsInv_fx */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + Word16 exp_inv_spectrum_fx[CPE_CHANNELS], /* i/o: exp of inv_spectrum_fx */ + const Word16 frameno, /* i : flag indicating index of current subfr. */ + const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ + const Word32 element_brate, /* i : element bitrate */ const Word16 mct_on ) { Word16 ch, igfGridIdx, isIndepFlag, bsBits, pBsStart, curr_order; @@ -4078,7 +4078,7 @@ void ProcessStereoIGF_fx( IGFSaveSpectrumForITF_ivas_fx( hIGFEnc[1], igfGridIdx, pITFMDCTSpectrum_fx[1][frameno], sub( Q31, q_pITFMDCTSpectrum_2 ) ); - IGFEncApplyStereo_fx( hStereoMdct, ms_mask, hIGFEnc, igfGridIdx, sts, pPowerSpectrum_fx, exp_pPowerSpectrum_fx, pPowerSpectrumMsInv_fx, exp_pPowerSpectrumMsInv_fx, + IGFEncApplyStereo_fx( hStereoMdct, ms_mask, hIGFEnc, igfGridIdx, sts, pPowerSpectrum_fx, exp_pPowerSpectrum_fx, pPowerSpectrumMsInv_fx, q_pPowerSpectrumMsInv_fx, inv_spectrum_fx, exp_inv_spectrum_fx, frameno, sp_aud_decision0, element_brate, mct_on ); FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) -- GitLab From 253d721065338c97b05c4b32f4fe544bb8c650ba Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 13 May 2025 11:58:42 +0530 Subject: [PATCH 2/2] Fix for LTV Crash: Multi-channel 7_1_4 bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, 7_1_4 out --- lib_enc/ivas_stereo_mdct_core_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_stereo_mdct_core_enc_fx.c b/lib_enc/ivas_stereo_mdct_core_enc_fx.c index cbbc0d000..2a71fc34d 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_core_enc_fx.c @@ -251,7 +251,7 @@ void stereo_mdct_core_enc_fx( inv_mdst_spectrum_fx[ch][1] = powerSpecMsInv_fx[ch][1] = powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; q_powerSpecMsInv_fx[ch][0] = q_powerSpecMsInv_long_fx[ch]; q_powerSpecMsInv_fx[ch][1] = q_powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; - set16_fx( q_powerSpecMsInv_long_fx[ch], 63, L_FRAME48k ); + set16_fx( q_powerSpecMsInv_long_fx[ch], 63, N_MAX ); quantized_spectrum_fx[ch][0] = quantized_spectrum_long_fx[ch]; quantized_spectrum_fx[ch][1] = quantized_spectrum_long_fx[ch] + N_TCX10_MAX; inv_spectrum_fx[ch][0] = quantized_spectrum_fx[ch][0]; -- GitLab