diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index 1440cc4ea463221bcdde3081ea73dfb1e2fe7764..a059cc6f7b2dffee4b83110db59e7e7e289a730d 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -57,7 +57,8 @@ void sns_compute_scf_fx( Word32 *scf ) { Word16 i, n, k; - Word32 x[FDNS_NPTS], xs[FDNS_NPTS], sum, mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS]; + Word32 x[FDNS_NPTS], xs[FDNS_NPTS], mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS]; + Word64 sum; Word32 L_tmp; const Word16 *pow_tilt; const UWord8 nBands = pPsychParams->nBands; @@ -139,8 +140,11 @@ void sns_compute_scf_fx( } /* Noise floor at -40dB */ - sum = sum32_fx( xs, FDNS_NPTS ); - mean = L_shr( sum, 6 ); + sum = 0; + for (Word16 ind = 0; ind < FDNS_NPTS; ind++) { + sum += (Word64)xs[i]; + } + mean = (Word32)(sum >> 6); nf = Mpy_32_16_1( mean, 3 ); // 3 => powf( 10.0f, -4.0f ) in Q15 nf = L_max( nf, 0 ); // 0 => powf( 2.0f, -32.0f ) in Q15 @@ -198,8 +202,11 @@ void sns_compute_scf_fx( xl4[SNS_NPTS - 1] = L_tmp; /* Remove mean and scaling */ - sum = sum32_fx( xl4, SNS_NPTS ); - mean = L_shr( sum, 4 ); + sum = 0; + for (Word16 ind = 0; ind < SNS_NPTS; ind++) { + sum += (Word64)xl4[i]; + } + mean = (Word32)(sum >> 4); FOR( i = 0; i < SNS_NPTS; i++ ) { diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index c0b445fcbd32fe73ef2b03b2cb0dd091f2c2de36..72bebb691a812976149e43fe60f4caf859cebbe0 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -589,7 +589,7 @@ int16_t res_bpf_adapt( Word16 res_bpf_adapt_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ const Word32 *bpf_error_signal_8k, /* i : BPF modification signal */ - Word32 res_buf[STEREO_DFT_N_8k] /* i : residual buffer */ + Word32 res_buf[STEREO_DFT_N_8k] /* i : residual buffer Q12 */ ) { Word32 error_nrg; @@ -601,6 +601,8 @@ Word16 res_bpf_adapt_fx( Word16 i_start; Word16 i_end; Word16 bw_inv; + Word16 shift; + Word64 W_tmp; IF( EQ_16( hStereoDft->res_cod_band_max, 6 ) ) { @@ -617,11 +619,20 @@ Word16 res_bpf_adapt_fx( /* Measure energy of high frequency band in MDCT domain */ res_hb_nrg = L_deposit_l( 0 ); + W_tmp = W_deposit32_l( 0 ); FOR( i = i_start; i < i_end; i++ ) { - res_hb_nrg = Madd_32_32_r( res_hb_nrg, res_buf[i], res_buf[i] ); + W_tmp = W_add_nosat( W_tmp, W_mult0_32_32( res_buf[i], res_buf[i] ) ); } - res_hb_nrg = L_shl( (Word32) res_hb_nrg, Q7 ); // Q0 + + shift = W_norm( W_tmp ); + W_tmp = W_shl( W_tmp, shift ); + res_hb_nrg = W_extract_h( W_tmp ); + IF( GT_16( add( Q24, shift ), 32 ) ) + { + res_hb_nrg = L_shr( res_hb_nrg, sub( add( Q24, shift ), 32 ) ); // Q0 + } + res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) ); hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 1862d5036c06be27d92919e0e78b0eff29681d6b..51c1afd4eaed27d0908bf03a10bd95e1f6ee8991 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -45,6 +45,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx2.h" #endif // IVAS_FLOAT_FIXED @@ -1214,9 +1215,18 @@ void TonalMdctConceal_whiten_noise_shape_ivas( Word32 whitenend_noise_shape_fx[L_FRAME16k]; Word32 scfs_int_fx[FDNS_NPTS], scfs_bg_fx[FDNS_NPTS]; + Word16 q = 31; FOR( Word16 k = 0; k < L_FRAME16k; k++ ) { - whitenend_noise_shape_fx[k] = (Word32) ( whitenend_noise_shape[k] * ONE_IN_Q7 ); + if(abs((Word32)whitenend_noise_shape[k])!=0) q = s_min(q, norm_l( whitenend_noise_shape[k] )); + } + + q -= find_guarded_bits_fx(L_frame) + 2; + //q -= 1; + + FOR( Word16 k = 0; k < L_FRAME16k; k++ ) + { + whitenend_noise_shape_fx[k] = q>=0 ? ((Word32) ( whitenend_noise_shape[k] *(1<< q) )):((Word32) ( whitenend_noise_shape[k] / (1<< q) )); } sns_compute_scf_fx( whitenend_noise_shape_fx, psychParams, L_frame, scf_fx );