From c7d55a4db19d993a88dc8bc58b720359bf357ddc Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 17:19:31 +0530 Subject: [PATCH] Fix for 3gpp issue 866 --- lib_com/fd_cng_com.c | 3 --- lib_com/fd_cng_com_fx.c | 2 -- lib_com/stat_com.h | 5 +---- lib_dec/acelp_core_dec_ivas_fx.c | 1 - lib_dec/fd_cng_dec.c | 21 +++++++++++---------- lib_dec/ivas_stereo_cng_dec.c | 6 +++--- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 11 ++--------- lib_dec/ivas_tcx_core_dec.c | 10 +++------- 8 files changed, 20 insertions(+), 39 deletions(-) diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 14c9b3c21..a03edf290 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -118,9 +118,6 @@ void initFdCngCom_flt( hFdCngCom->frame_type_previous = ACTIVE_FRAME; hFdCngCom->flag_noisy_speech = 0; hFdCngCom->likelihood_noisy_speech_flt = 0.f; -#ifdef IVAS_FLOAT_FIXED - hFdCngCom->likelihood_noisy_speech_32fx = 0; -#endif hFdCngCom->numCoreBands = 0; hFdCngCom->stopBand = 0; hFdCngCom->startBand = 0; diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 8f5528014..e11d67d69 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -163,8 +163,6 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); set32_fx( hFdCngCom->exc_cng_32fx, 0, L_FRAME16k ); set16_fx( hFdCngCom->exc_cng, 0, L_FRAME16k ); - hFdCngCom->likelihood_noisy_speech_32fx = 0; - move32(); return; } diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 7cc45ae38..97fec1041 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -532,10 +532,7 @@ typedef struct int16_t flag_noisy_speech; float likelihood_noisy_speech_flt; -#ifdef IVAS_FLOAT_FIXED - Word32 likelihood_noisy_speech_32fx; -#endif - Word16 likelihood_noisy_speech; + Word16 likelihood_noisy_speech; // Q15 #ifndef IVAS_FLOAT_FIXED float coherence_flt; /* inter-channel coherence of noise */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 679120dbb..834691ce0 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1552,7 +1552,6 @@ ivas_error acelp_core_dec_ivas_fx( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ); move32(); } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 10c25db4d..0c3f8afd6 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -59,7 +59,7 @@ #define CNA_ACT_DN_FACT 0.7 /* downward updating factor for CNA during active frames */ #endif // IVAS_FLOAT_FIXED -#define DELTA_MASKING_NOISE_Q31 0 +#define DELTA_MASKING_NOISE_Q15 0 #define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ #define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ #define LOG_10_BASE_2 1783446566 /* Q29 */ @@ -1955,7 +1955,7 @@ void generate_masking_noise_ivas_fx( /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ *exp_out = Q15; move16(); - IF( GT_32( hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 ) ) + IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) ) { IF( NE_16( core, AMR_WB_CORE ) ) { @@ -1997,7 +1997,7 @@ void generate_masking_noise_ivas_fx( } /* Exclude clean speech */ - scale_fx = Mpy_32_32( scale_fx, hFdCngCom->likelihood_noisy_speech_32fx ); // Q30 + scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); // Q30 /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ @@ -2680,7 +2680,7 @@ void generate_masking_noise_lb_dirac_fx( IF( cna_flag ) { /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ - IF( GT_32( hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 ) ) + IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) ) { /* Compute additional CN level */ FOR( i = 0; i < 15; i++ ) @@ -2695,8 +2695,8 @@ void generate_masking_noise_lb_dirac_fx( } } - scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */ - scale = Mpy_32_32( scale, hFdCngCom->likelihood_noisy_speech_32fx ); /* Q30 */ + scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */ + scale = Mpy_32_16_1( scale, hFdCngCom->likelihood_noisy_speech ); /* Q30 */ } } @@ -2738,7 +2738,7 @@ void generate_masking_noise_lb_dirac_fx( FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { rand_gauss_fx( ptr_r, seed, exp_out ); - Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); + Word16 exp2 = hFdCngCom->cngNoiseLevelExp; Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); // hFdCngCom->fftBuffer_exp + exp2 - 31 move32(); @@ -2758,6 +2758,7 @@ void generate_masking_noise_lb_dirac_fx( /* Perform STFT synthesis */ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); + scale_sig32( tdBuffer + n_samples_start, n_samples_out_loop, Q9 ); // Q2 -> Q11 } ELSE @@ -2935,7 +2936,7 @@ void generate_masking_noise_dirac_ivas_fx( } } - scale_fx = L_shr( scaleTable_cn_dirac[i].scale_ivas, Q3 ); /* Q11 */ + scale_fx = L_shr( L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ), Q3 ); /* Q27 */ scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); } } @@ -2959,11 +2960,11 @@ void generate_masking_noise_dirac_ivas_fx( /*HF CLDFB - CNA and/or FD-CNG*/ if ( fd_cng_flag ) { - scale_fx = L_add( scale_fx, 2048 ); // 1 in Q11 + scale_fx = L_add( scale_fx, ONE_IN_Q27 ); // 1 in Q27 } IF( scale_fx != 0 ) { - q_scale = 11; + q_scale = 27; move16(); q_shift = norm_l( scale_fx ); scale_fx = L_shl( scale_fx, q_shift ); diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 7737a251d..60375dd78 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -1384,9 +1384,9 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); /* Q0 */ move16(); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99 in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), + mult_r( 328 /* 0.01 in Q15 */, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q15 */ + move16(); } test(); diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 6731b8b0d..155e207b8 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -535,11 +535,6 @@ void stereo_mdct_core_dec_fx( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s ); } test(); - IF( sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom ) - { - sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* 16 - q_likelihood_noisy_speech */ - } - test(); test(); IF( sts[ch]->igf != 0 && sts[ch]->hIGFDec && sts[ch]->hIGFDec->virtualSpec_fx ) { @@ -1066,10 +1061,8 @@ static void run_min_stats_fx( noisy_speech_detection_fx( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub( 15, power_spec_e ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), Mpy_32_32( st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01 ) ); /* q_likelihood_noisy_speech */ - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* q_likelihood_noisy_speech - 16 */ - move32(); - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99 in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), mult_r( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 328 /* 0.01 in Q15 */ ) ); /* Q15 */ + move16(); st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move32(); } diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 4ac7c32a8..7930720f3 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -954,14 +954,10 @@ void stereo_tcx_core_dec_fx( IF( st->hFdCngDec != NULL && ( EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) { noisy_speech_detection_fx( st->hFdCngDec, st->VAD && EQ_16( st->m_frame_type, ACTIVE_FRAME ), signal_out_fx, 0 ); - - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* Q15 */ - st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ - move32(); - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99f in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), mult_r( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 328 /* 0.01f in Q15 */ ) ); /* Q15 */ + st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move16(); + move32(); IF( NE_16( st->element_mode, IVAS_CPE_TD ) ) { -- GitLab