From b7ce8ea634826fe749e9aaf253d41b645d20cb41 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 16 Oct 2024 22:02:44 +0530 Subject: [PATCH] Fix for 3GPP issue 921: Decoder crash for MC51 at 48kbps FER in decoder_tcx_noisefilling_fx() [x] Fix - Exponents for E_2ndlast and E_last not handled properly in decoder_tcx_noisefilling_fx. BASOP_Util_Add_Mant32Exp also giving issues when mant is 0 but exp is non-zero. Used Word64 to accumulate energies and corrected exponent usage. --- lib_dec/dec_tcx_fx.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f6ce2cd0f..1f0bb5d6a 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4733,12 +4733,12 @@ void decoder_tcx_noisefilling_fx( Word16 exp1, exp2; exp1 = 0; exp2 = 0; - Word32 E_2ndlast, E_last; + Word64 E_2ndlast, E_last; E_2ndlast = E_last = EPSILON_FX; move16(); move16(); - move32(); - move32(); + move64(); + move64(); Word16 tmp_len; IF( st->element_mode > EVS_MONO ) @@ -4754,11 +4754,19 @@ void decoder_tcx_noisefilling_fx( FOR( i = 0; i < tmp_len; i = i + 2 ) { - E_2ndlast = BASOP_Util_Add_Mant32Exp( E_2ndlast, exp2, L_mult0( st->hTonalMDCTConc->lastBlockData.spectralData[i], st->hTonalMDCTConc->lastBlockData.spectralData[i] ), 29, &exp2 ); - E_last = BASOP_Util_Add_Mant32Exp( E_last, exp1, L_mult0( st->hTonalMDCTConc->lastBlockData.spectralData[i + 1], st->hTonalMDCTConc->lastBlockData.spectralData[i + 1] ), 29, &exp1 ); + E_2ndlast = W_mac_16_16( E_2ndlast, st->hTonalMDCTConc->lastBlockData.spectralData[i], st->hTonalMDCTConc->lastBlockData.spectralData[i] ); /* Q(31 - 2 * st->hTonalMDCTConc->lastBlockData.spectralData_exp) */ + E_last = W_mac_16_16( E_last, st->hTonalMDCTConc->lastBlockData.spectralData[i + 1], st->hTonalMDCTConc->lastBlockData.spectralData[i + 1] ); /* Q(31 - 2 * st->hTonalMDCTConc->lastBlockData.spectralData_exp) */ } - tmp1 = BASOP_Util_Divide3232_Scale( E_2ndlast, E_last, &tmp2 ); + exp2 = W_norm( E_2ndlast ); + E_2ndlast = W_shl( E_2ndlast, exp2 ); + exp2 = sub( 63, add( sub( 31, shl( st->hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ), exp2 ) ); + + exp1 = W_norm( E_last ); + E_last = W_shl( E_last, exp1 ); + exp1 = sub( 63, add( sub( 31, shl( st->hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ), exp1 ) ); + + tmp1 = BASOP_Util_Divide3232_Scale( W_extract_h( E_2ndlast ), W_extract_h( E_last ), &tmp2 ); tmp2 = add( tmp2, sub( exp2, exp1 ) ); #ifdef BASOP_NOGLOB -- GitLab