From 0cc38a34ccb890f9b7108e0ef7b97958dca1a7e4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 8 Aug 2024 18:33:21 +0530 Subject: [PATCH] LTV crash fixes and updates for addressing high MLD issue in ISM formats [x] crash fix for ltv case +10dB : [ltv-stereo bitrate switching from 13.2 kbps to 128 kbps, 32kHz in, 32kHz out] [x] Fix for High MLD issue in ISM Stream: stv-3 ISM with metadata at 128 kbps, 48 kHz in, 32 kHz out, HOA3 out, random FER at 5% [x] Resolved LTV crash: +10dB [ltv-stereo at 32 kbps, 32kHz in, 32kHz out, DTX on, MONO out, random FER at 5%] --- lib_com/cnst.h | 3 --- lib_com/swb_tbe_com_fx.c | 2 +- lib_dec/cng_dec_fx.c | 3 +-- lib_dec/fd_cng_dec.c | 4 ++-- lib_dec/tonalMDCTconcealment_fx.c | 22 ++++++++++++++-------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 50f851427..81e1647ca 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -776,9 +776,6 @@ enum #define L_FILT_2OVER3 12 #define L_FILT_2OVER3_LP 3 -#ifdef NONE_BE_FIX_816_LFE_PLC_FLOAT -#define MAX_LP_FILTER_ORDER 20 /* Max order of an LP filter */ -#endif typedef enum { diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 59bde6cdf..588340b8d 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3467,7 +3467,7 @@ void GenShapedSHBExcitation_ivas_fx( /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ L_tmp = L_mult( White_exc16k[k], scale ); /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); + exc16kWhtnd[k] = round_fx_sat( L_shl_sat( L_tmp, NOISE_QADJ ) ); move16(); /* exc16kWhtnd: Q_bwe_exc */ } diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index fdb708f46..ea829b955 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1332,8 +1332,7 @@ static void shb_CNG_decod_ivas_fx( move32(); } fra = L_Extract_lc( L_tmp, &exp ); - L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ - L_tmp = L_shr( L_tmp, 10 ); + L_tmp = L_shr( Pow2( exp, fra ), 5 ); /*Q5 */ if ( !L_tmp ) { L_tmp = 1; diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index e5a7bb666..6c41de1f4 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -2047,7 +2047,7 @@ void generate_masking_noise_ivas_fx( { rand_gauss_fx( &fftBuffer_fx[0], seed, *exp_out ); // Q15 ptr_r_fx = fftBuffer_fx + 2; - Word16 exp1 = sub( 32, hFdCngCom->cngNoiseLevelExp ); + Word16 exp1 = add( hFdCngCom->cngNoiseLevelExp, 1 ); Word32 mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); // Q = noise_exp-1 mpy1 = L_shl( mpy1, exp1 ); // Q31 fftBuffer_fx[0] = Mpy_32_32( fftBuffer_fx[0], mpy1 ); /* DC component in FFT */ // Q = Q15 @@ -2065,7 +2065,7 @@ void generate_masking_noise_ivas_fx( { /* Real part in FFT bins */ rand_gauss_fx( ptr_r_fx, seed, *exp_out ); // Q15 - Word16 exp2 = sub( 32, hFdCngCom->cngNoiseLevelExp ); + Word16 exp2 = add( hFdCngCom->cngNoiseLevelExp, 1 ); Word32 mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); // Q = noise_exp-1 ( *ptr_r_fx ) = L_shl( Mpy_32_32( *ptr_r_fx, mpy2 ), exp2 ); // Q = Q15 ptr_r_fx += 2; diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 13da71352..ec4e4abe7 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -760,7 +760,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move32(); #endif - // Word16 nBands; + Word16 nBands; Word32 invScaleFactors_fx[FDNS_NPTS]; Word16 old_power_spectrum_q, power_spectrum_q; @@ -826,16 +826,17 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( tmp_exp = old_exp; move16(); powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); + move32(); powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); move32(); } FOR( i = 0; i < hTonalMDCTConc->nScaleFactors; i++ ) { - move16(); - move16(); invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; + move16(); invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); + move16(); } power_spectrum_q = sub( 31, powerSpectrum_exp ); @@ -846,6 +847,8 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ IF( psychParamsCurrent == NULL ) { + nBands = FDNS_NPTS; + move16(); mdct_shaping( powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp ); } ELSE @@ -857,8 +860,8 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore, &length ); power_spectrum_q = add( power_spectrum_q, 1 ); - // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); - // nBands = psychParamsCurrent->nBands; + nBands = psychParamsCurrent->nBands; + move16(); } IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) { @@ -874,13 +877,17 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); #else - powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); + powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); #endif move32(); } + Word16 shift = Find_Max_Norm32( powerSpectrum, nSamples ); + scale_sig32( powerSpectrum, nSamples, shift ); + powerSpectrum_exp = sub( powerSpectrum_exp, shift ); + /* 16 bits are now enough for storing the power spectrum */ FOR( i = 0; i < nSamples; i++ ) { @@ -892,7 +899,6 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move32(); } - powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); hTonalMDCTConc->secondLastPowerSpectrum_exp = powerSpectrum_exp; move16(); } -- GitLab