From 4817473b559d0464e7a695110745690c6f161dd0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 6 Feb 2025 12:39:29 +0530 Subject: [PATCH] Fix for 3GPP issue 1251: Basop Encoder: Spectral holes between 2-4 kHz and spectral differences for Unified Stereo @24kbps Link #1251 --- lib_com/stat_com.h | 2 +- lib_enc/fd_cng_enc.c | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 78d358be5..45a16dc1a 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -411,7 +411,7 @@ typedef struct Word16 psize_norm[NPART]; /* Partition sizes, fractional variable Q15-psize_norm_exp*/ Word16 psize_inv[NPART]; /* Inverse of partition sizes Q15*/ // Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - Word16 scalingFactor; // Q15 + Word16 scalingFactor; // exp = -15 Word16 invScalingFactor; // Q15 Word16 nCLDFBpart; /* Number of CLDFB spectral partitions */ Word16 CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 5c493876b..5fdc5e6f0 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -92,10 +92,12 @@ void perform_noise_estimation_enc_ivas_fx( move16(); assert( numSlots == 16 ); - Word32 numSlots_inv_fx = 134217728; + Word32 numSlots_inv_fx = 1073741824; // Q34 of .0625 move32(); Word32 *periodog = hFdCngEnc->hFdCngCom->periodog; /* exp(peridog_exp) */ Word32 *ptr_per_fx = periodog; + Word64 periodog_64; + Word16 periodog_exp[PERIODOGLEN]; Word16 npart = hFdCngEnc->hFdCngCom->npart; /* Q0 */ move16(); Word16 nFFTpart = hFdCngEnc->hFdCngCom->nFFTpart; /* Q0 */ @@ -130,19 +132,19 @@ void perform_noise_estimation_enc_ivas_fx( SWITCH( input_Fs ) { case 8000: - scaleEB_fx = 62912; + scaleEB_fx = 251648; // Q35 move32(); BREAK; case 16000: - scaleEB_fx = 15728; + scaleEB_fx = 62912; // Q35 move32(); BREAK; case 32000: - scaleEB_fx = 3928; + scaleEB_fx = 15728; // Q35 move32(); BREAK; case 48000: - scaleEB_fx = 1744; + scaleEB_fx = 6991; // Q35 move32(); BREAK; default: @@ -151,8 +153,8 @@ void perform_noise_estimation_enc_ivas_fx( } ELSE { - scaleEB_fx = Mpy_32_16_1( numSlots_inv_fx, hFdCngEnc->hFdCngCom->scalingFactor ); - scaleEB_fx = L_shl( scaleEB_fx, 4 ); + scaleEB_fx = Mpy_32_32( numSlots_inv_fx, L_deposit_l( hFdCngEnc->hFdCngCom->scalingFactor ) ); // Q34 + Q30 - Q31 = Q33 + scaleEB_fx = L_shl( scaleEB_fx, 2 ); // Q35 } /* preemphasis compensation and grouping of per bin energies into msPeriodog */ @@ -167,22 +169,38 @@ void perform_noise_estimation_enc_ivas_fx( hFdCngEnc->msPeriodog_fx_exp_fft = add( band_energies_exp, PREEMPH_COMPENSATION_EXP ); move16(); + Word16 max_exp = -31; + move16(); + i = 0; + move16(); /* Adjust to the desired time resolution by averaging the periodograms over the time slots */ FOR( j = numCoreBands; j < regularStopBand; j++ ) { - *ptr_per_fx = Mpy_32_32( enerBuffer[j], scaleEB_fx ); /* exp(enerBuffer_exp) */ + periodog_64 = W_mult_32_32( enerBuffer[j], scaleEB_fx ); + Word16 scale = W_norm( periodog_64 ); + *ptr_per_fx = W_extract_h( W_shl( periodog_64, scale ) ); move32(); + periodog_exp[i] = sub( Q31, add( add( sub( Q31, enerBuffer_exp ), 35 - 31 ), scale ) ); + move16(); + max_exp = s_max( max_exp, periodog_exp[i] ); ptr_per_fx++; - move16(); + i++; } - /* exponent for cldfb part of msPeriodog */ - hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); - move16(); + // hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); + // move16(); numBands = sub( regularStopBand, numCoreBands ); /* Q0 */ + FOR( i = 0; i < numBands; i++ ) + { + + periodog[i] = L_shr( periodog[i], sub( max_exp, periodog_exp[i] ) ); + move16(); + } + hFdCngEnc->hFdCngCom->exp_cldfb_periodog = max_exp; + move16(); IF( numBands > 0 ) { ///* Adjust CLDFB filterbank to the desired frequency resolution by averaging over spectral partitions for SID transmission */ -- GitLab