diff --git a/lib_com/options.h b/lib_com/options.h index 131188e6513ce3e9efdd996ae8318c3d97f00b3c..10420386d57f581790988381d048d17fbdd1135c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,6 +83,7 @@ #define FIX_1946_CRASH_JBM_PROCESSING /* FhG: Increased guard bits of DFT_fx */ #define FIX_1980_CRASH_FDCNG_ENCODESID /* FhG: Add one bit of headroom in e_fx calculation in FdCng_encodeSID_ivas_fx() */ #define FIX_1987_CRASH_OMASA_ENERGY /* FhG: Replace cldfbAnalysis_ts_fx_fix_q() with cldfbAnalysis_ts_fx_var_q() to avoid assertion error */ +#define FIX_1962_FORMAT_CONV_SPECTRAL_DIFF /* FhG: Improved precision of targetEnergy in ivas_ls_setup_conversion_process_mdct_fx() */ /* #################### Start BASOP porting switches ############################ */ #define NONBE_1244_FIX_SWB_BWE_MEMORY /* VA: issue 1244: fix to SWB BWE memory in case of switching from FB coding - pending a review by Huawei */ diff --git a/lib_dec/ivas_out_setup_conversion_fx.c b/lib_dec/ivas_out_setup_conversion_fx.c index fde543e96e2c1b0289dd050e7735ea03521dc3dc..dc5bf9b90cf177b39b93c65606905884943655a3 100644 --- a/lib_dec/ivas_out_setup_conversion_fx.c +++ b/lib_dec/ivas_out_setup_conversion_fx.c @@ -662,8 +662,13 @@ void ivas_ls_setup_conversion_process_mdct_fx( Word16 inChannels, outChannels, num_CPE; Word16 transform_type[MAX_CICP_CHANNELS][2]; Word16 frameSize; +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + Word64 targetEnergy64[MAX_SFB + 2], dmxEnergy64[MAX_SFB + 2]; + Word16 dmxEnergy_exp_temp, scf1, scf2; +#else Word32 targetEnergy[MAX_SFB + 2], dmxEnergy[MAX_SFB + 2]; Word16 dmxEnergy_exp[MAX_SFB + 2], dmxEnergy_exp_temp; +#endif Word32 dmxCoeff; Word32 dmxSignalReal[L_FRAME48k], dmxSignalImag[L_FRAME48k]; Word32 eqGain; @@ -748,12 +753,20 @@ void ivas_ls_setup_conversion_process_mdct_fx( /* set overall frequency resolution of (sub)frame to maximum of (sub)frame, requires conversion if both channels are not the same */ frameSize = hLsSetUpConversion->sfbOffset[hLsSetUpConversion->sfbCnt]; move16(); - +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + set64_fx( targetEnergy64, 0, MAX_SFB + 2 ); + set64_fx( dmxEnergy64, 0, MAX_SFB + 2 ); + scf1 = 63; + scf2 = 63; + move16(); + move16(); +#else set32_fx( targetEnergy, 0, MAX_SFB + 2 ); set32_fx( dmxEnergy, 0, MAX_SFB + 2 ); set16_fx( dmxEnergy_exp, 0, MAX_SFB + 2 ); dmxEnergy_exp_temp = 0; move16(); +#endif FOR( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) { @@ -772,8 +785,12 @@ void ivas_ls_setup_conversion_process_mdct_fx( /* Step 1: Compute the target energy and DMX signal (possible since we have all signals in TCX20 resolution) */ IF( dmxCoeff ) { +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + Word64 targetEne64; + Word32 tmpDMXSig; +#else Word32 tmpDMXSig, targetEne; - +#endif /* Convert the signal resolution to TCX20 */ /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ pTmp[0] = x[chInIdx][0]; // Q(q_output) @@ -816,8 +833,13 @@ void ivas_ls_setup_conversion_process_mdct_fx( stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; move16(); +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + targetEne64 = 0; + move64(); +#else targetEne = 0; move32(); +#endif /* Loop over all the bins in the band */ FOR( binIdx = start; binIdx < stop; binIdx++ ) @@ -825,15 +847,30 @@ void ivas_ls_setup_conversion_process_mdct_fx( tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), sig[0][binIdx] ); dmxSignalReal[binIdx] = L_add( dmxSignalReal[binIdx], tmpDMXSig ); move32(); +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + targetEne64 = W_mac_32_32( targetEne64, tmpDMXSig, tmpDMXSig ); +#else targetEne = L_add( targetEne, Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); - +#endif tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), mdst[binIdx] ); dmxSignalImag[binIdx] = L_add( dmxSignalImag[binIdx], tmpDMXSig ); move32(); +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + targetEne64 = W_mac_32_32( targetEne64, tmpDMXSig, tmpDMXSig ); +#else targetEne = L_add( targetEne, Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); +#endif } +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + targetEnergy64[bandIdx] = W_add( targetEnergy64[bandIdx], W_shr( targetEne64, 1 ) ); + if ( targetEnergy64[bandIdx] != 0 ) + { + scf1 = s_min( scf1, W_norm( targetEnergy64[bandIdx] ) ); + } +#else targetEnergy[bandIdx] = L_add( targetEnergy[bandIdx], targetEne ); move32(); +#endif } /* end of band loop */ } } @@ -841,52 +878,98 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + Word32 tmpReal, tmpImag; + Word64 DMXEne64; +#else Word32 tmpReal, tmpImag, DMXEne; Word16 DMXEne_exp; - +#endif start = hLsSetUpConversion->sfbOffset[bandIdx]; move16(); stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; move16(); /* Loop over all the bins in the band */ +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + DMXEne64 = 0; + move64(); +#else DMXEne = 0; move32(); DMXEne_exp = 0; move16(); +#endif + FOR( binIdx = start; binIdx < stop; binIdx++ ) { tmpReal = dmxSignalReal[binIdx]; move32(); tmpImag = dmxSignalImag[binIdx]; move32(); - +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + DMXEne64 = W_mac_32_32( DMXEne64, tmpReal, tmpReal ); + DMXEne64 = W_mac_32_32( DMXEne64, tmpImag, tmpImag ); +#else DMXEne = BASOP_Util_Add_Mant32Exp( DMXEne, DMXEne_exp, L_add( Mpy_32_32( tmpReal, tmpReal ), Mpy_32_32( tmpImag, tmpImag ) ), sub( 40, shl( q_output, 1 ) ), &DMXEne_exp ); +#endif + } +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + dmxEnergy64[bandIdx] = W_add( dmxEnergy64[bandIdx], W_shr( DMXEne64, 1 ) ); + if ( dmxEnergy64[bandIdx] != 0 ) + { + scf2 = s_min( scf2, W_norm( dmxEnergy64[bandIdx] ) ); } +#else dmxEnergy[bandIdx] = BASOP_Util_Add_Mant32Exp( dmxEnergy[bandIdx], dmxEnergy_exp[bandIdx], DMXEne, DMXEne_exp, &dmxEnergy_exp[bandIdx] ); move32(); dmxEnergy_exp_temp = s_max( dmxEnergy_exp_temp, dmxEnergy_exp[bandIdx] ); +#endif } } /* end of out channel loop */ - +#ifndef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF /* Scaling to common exponent */ FOR( bandIdx = 0; bandIdx < MAX_SFB + 2; bandIdx++ ) { dmxEnergy[bandIdx] = L_shl( dmxEnergy[bandIdx], sub( dmxEnergy_exp[bandIdx], dmxEnergy_exp_temp ) ); move32(); } +#endif /* Step 3: Peform energy smoothing */ - +#ifndef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF Word16 te_scale = getScaleFactor32( hLsSetUpConversion->targetEnergyPrev_fx[0], hLsSetUpConversion->sfbCnt ); scale_sig32( hLsSetUpConversion->targetEnergyPrev_fx[0], hLsSetUpConversion->sfbCnt, te_scale ); Word16 dmx_sacle = getScaleFactor32( hLsSetUpConversion->dmxEnergyPrev_fx[0], hLsSetUpConversion->sfbCnt ); scale_sig32( hLsSetUpConversion->dmxEnergyPrev_fx[0], hLsSetUpConversion->sfbCnt, dmx_sacle ); - +#endif + +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + Word16 targetEnergy_e = sub( add( sub( 40, shl( q_output, 1 ) ), 1 ), scf1 ); + dmxEnergy_exp_temp = sub( add( sub( 40, shl( q_output, 1 ) ), 1 ), scf2 ); + Word16 te_max_e = s_max( targetEnergy_e, hLsSetUpConversion->te_prev_exp[0] ); + Word16 dmx_max_e = s_max( dmxEnergy_exp_temp, hLsSetUpConversion->dmx_prev_exp[0] ); +#else Word16 te_max_e = s_max( sub( 40, shl( q_output, 1 ) ), sub( hLsSetUpConversion->te_prev_exp[0], te_scale ) ); Word16 dmx_max_e = s_max( dmxEnergy_exp_temp, sub( hLsSetUpConversion->dmx_prev_exp[0], dmx_sacle ) ); +#endif FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + Word32 targetEnergy, dmxEnergy; + + targetEnergy = W_extract_h( W_shl( targetEnergy64[bandIdx], scf1 ) ); + targetEnergy = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, L_shr( targetEnergy, sub( te_max_e, targetEnergy_e ) ) ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx], sub( te_max_e, hLsSetUpConversion->te_prev_exp[0] ) ) ) ); + move32(); + hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy; + move32(); + + dmxEnergy = W_extract_h( W_shl( dmxEnergy64[bandIdx], scf2 ) ); + dmxEnergy = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, L_shr( dmxEnergy, sub( dmx_max_e, dmxEnergy_exp_temp ) ) ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx], sub( dmx_max_e, hLsSetUpConversion->dmx_prev_exp[0] ) ) ) ); + move32(); + hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy; + move32(); +#else targetEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, L_shr( targetEnergy[bandIdx], sub( te_max_e, sub( 40, shl( q_output, 1 ) ) ) ) ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx], sub( te_max_e, sub( hLsSetUpConversion->te_prev_exp[0], te_scale ) ) ) ) ); move32(); dmxEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, L_shr( dmxEnergy[bandIdx], sub( dmx_max_e, dmxEnergy_exp_temp ) ) ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx], sub( dmx_max_e, sub( hLsSetUpConversion->dmx_prev_exp[0], dmx_sacle ) ) ) ) ); @@ -895,6 +978,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( move32(); hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; /* dmx_prev_exp = 40 - 2*q_output */ move32(); +#endif } hLsSetUpConversion->te_prev_exp[0] = te_max_e; /* te_prev_exp = 40 - 2*q_output */ @@ -928,7 +1012,13 @@ void ivas_ls_setup_conversion_process_mdct_fx( move16(); /* Compute Eq gains */ +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + ivas_lssetupconversion_computeEQFactor_fx( &hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx], hLsSetUpConversion->te_prev_exp[0], + &hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx], hLsSetUpConversion->dmx_prev_exp[0], + &eqGain ); // Q(eqGain) = 30 +#else ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], hLsSetUpConversion->te_prev_exp[0], &dmxEnergy[bandIdx], hLsSetUpConversion->dmx_prev_exp[0], &eqGain ); // Q(eqGain) = 30 +#endif FOR( binIdx = start; binIdx < stop; binIdx++ ) { x[chInIdx][0][binIdx] = Mpy_32_32( L_shl( x[chInIdx][0][binIdx], 1 ), eqGain ); // Q - 1 @@ -948,8 +1038,13 @@ void ivas_ls_setup_conversion_process_mdct_fx( move16(); /* Compute Eq gains */ +#ifdef FIX_1962_FORMAT_CONV_SPECTRAL_DIFF + ivas_lssetupconversion_computeEQFactor_fx( &hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx], hLsSetUpConversion->te_prev_exp[0], + &hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx], hLsSetUpConversion->dmx_prev_exp[0], + &eqGain ); +#else ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], hLsSetUpConversion->te_prev_exp[0], &dmxEnergy[bandIdx], hLsSetUpConversion->dmx_prev_exp[0], &eqGain ); - +#endif FOR( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { IF( EQ_16( transform_type[chInIdx][subFrameIdx], TCX_10 ) )