From c9872fcbf5f3ad3c542cd2eaf81efa1633fecb51 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 20 Mar 2025 14:42:55 +0530 Subject: [PATCH] Fix for 3GPP issue 1365: Narrowband difference between BASOP decoder and float decoder with McMASA bitstream Link #1365 With these changes, the narrowband difference for the 1st channel is eliminated. However, for the 2nd channel, even after using 64-bit calculations for energyBuildup_fx, there is still a loss of precision. When comparing energyBuildup >= 1.0f, the value for fixed is 1.00006783, while for float it is 0.999947906. --- lib_rend/ivas_reverb_fx.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib_rend/ivas_reverb_fx.c b/lib_rend/ivas_reverb_fx.c index 870f8795d..f985ac063 100644 --- a/lib_rend/ivas_reverb_fx.c +++ b/lib_rend/ivas_reverb_fx.c @@ -230,6 +230,7 @@ static void ivas_binaural_reverb_setReverbTimes_fx( Word16 tmp, tmp_exp, scale, tmpVal_exp, attenuationFactorPerSample_exp, attenuationFactorPerSampleSq_exp, energyBuildup_exp, currentEnergy_exp, intendedEnergy_exp, actualizedEnergy_exp; Word16 sine_inp, norm, div_exp1, div1, sine, binCenterFreq_exp; Word16 reverb_exp = 0; + Word32 tmp32; move16(); hReverb->binRend_RandNext = (UWord16) BIN_REND_RANDOM_SEED; @@ -376,29 +377,27 @@ static void ivas_binaural_reverb_setReverbTimes_fx( UWord16 ret_binRend = binRend_rand( hReverb ); - tmp = BASOP_Util_Divide3232_Scale( ret_binRend, PCM16_TO_FLT_FAC_FX, &tmp_exp ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_deposit_h( tmp ), tmp_exp, L_negate( 1073741824 ), 0, &exp ); - L_tmp = Mpy_32_32( L_tmp, 214748364 ); // exp + 0 + tmp32 = BASOP_Util_Divide3232_Scale_cadence( ret_binRend, PCM16_TO_FLT_FAC_FX, &tmp_exp ); + L_tmp = BASOP_Util_Add_Mant32Exp( tmp32, tmp_exp, L_negate( 1073741824 ), 0, &exp ); + L_tmp = Mpy_32_32( L_tmp, 214748365 ); // exp + 0 L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, exp, currentEnergy_fx, currentEnergy_exp, &exp ); energyBuildup_fx = BASOP_Util_Add_Mant32Exp( energyBuildup_fx, energyBuildup_exp, L_tmp, exp, &energyBuildup_exp ); - IF( energyBuildup_fx >= 0 ) /* A new filter tap is added at this condition */ + + IF( ( BASOP_Util_Cmp_Mant32Exp( energyBuildup_fx, energyBuildup_exp, 1, 31 ) >= 0 ) ) { - IF( ( BASOP_Util_Cmp_Mant32Exp( energyBuildup_fx, energyBuildup_exp, 1, 31 ) > 0 ) ) - { - /* Four efficient phase operations: n*pi/2, n=0,1,2,3 */ - hReverb->tapPhaseShiftType[bin][ch][tap] = (Word16) ( binRend_rand( hReverb ) % 4 ); - move16(); - /* Set the tapPointer to point to the determined sample at the loop buffer */ + /* Four efficient phase operations: n*pi/2, n=0,1,2,3 */ + hReverb->tapPhaseShiftType[bin][ch][tap] = (Word16) ( binRend_rand( hReverb ) % 4 ); + move16(); + /* Set the tapPointer to point to the determined sample at the loop buffer */ - hReverb->tapPointersReal_fx[bin][ch][tap] = &( hReverb->loopBufReal_fx[bin][sample] ); - hReverb->tapPointersImag_fx[bin][ch][tap] = &( hReverb->loopBufImag_fx[bin][sample] ); + hReverb->tapPointersReal_fx[bin][ch][tap] = &( hReverb->loopBufReal_fx[bin][sample] ); + hReverb->tapPointersImag_fx[bin][ch][tap] = &( hReverb->loopBufImag_fx[bin][sample] ); - energyBuildup_fx = BASOP_Util_Add_Mant32Exp( energyBuildup_fx, energyBuildup_exp, L_negate( 1073741824 ), 1, &energyBuildup_exp ); /* A tap is added, thus remove its energy from the buildup */ + energyBuildup_fx = BASOP_Util_Add_Mant32Exp( energyBuildup_fx, energyBuildup_exp, L_negate( 1073741824 ), 1, &energyBuildup_exp ); /* A tap is added, thus remove its energy from the buildup */ - tap = add( tap, 1 ); + tap = add( tap, 1 ); - actualizedEnergy_fx = BASOP_Util_Add_Mant32Exp( actualizedEnergy_fx, actualizedEnergy_exp, 1073741824, 1, &actualizedEnergy_exp ); - } + actualizedEnergy_fx = BASOP_Util_Add_Mant32Exp( actualizedEnergy_fx, actualizedEnergy_exp, 1073741824, 1, &actualizedEnergy_exp ); } currentEnergy_fx = BASOP_Util_Add_Mant32Exp( currentEnergy_fx, currentEnergy_exp, 0, 0, ¤tEnergy_exp ); -- GitLab