diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 49bb03f57ac0f2ede5c7e801012cd246ca972686..dc59ec752986a0750a75777d68d3aedf254b2414 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -620,7 +620,7 @@ void ivas_analy_sp_fx( *q_fr_bands = add( *q_fr_bands, exp ); move16(); - exp = sub( getScaleFactor32( band_energies, 2 * NB_BANDS ), 1 ); + exp = getScaleFactor32( band_energies, 2 * NB_BANDS ); scale_sig32( band_energies, 2 * NB_BANDS, exp ); /* q_band_energies + exp */ *q_band_energies = add( *q_band_energies, exp ); move16(); diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 4a8c4edd269883639042cdbfa76d0309a9d3f6f9..e883d9ec1b5386d508348573c41e300f6f3a4416 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -945,78 +945,41 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( st->idchan == 0 || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) && lr_vad_enabled && band_energies_LR_fx != NULL ) + Word16 norm; + norm = L_norm_arr( st->hFdCngEnc->msPeriodog_fx, NPART ); + IF( NE_16( norm, Q31 ) ) { - Word16 normmsPeriodog_fx = Q31, zero_flag = 0; - move16(); - move16(); - zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); - IF( zero_flag ) - { - normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); - move16(); - } - st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); - st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); + scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, norm ); // exp:st->hFdCngEnc->msPeriodog_fx_exp-norm + st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, norm ); + st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( st->hFdCngEnc->msPeriodog_fx_exp_cldfb, norm ); + st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( st->hFdCngEnc->msPeriodog_fx_exp_fft, norm ); move16(); move16(); - Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); /* exp(st->hFdCngEnc->msPeriodog_fx_exp - normmsPeriodog_fx) */ - st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, normmsPeriodog_fx ); - Word16 msNoiseEst_Q = Q31; move16(); + } + norm = L_norm_arr( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); + IF( NE_16( norm, Q31 ) ) + { + scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, norm ); // exp:st->hFdCngEnc->msNoiseEst_old_fx_exp-norm + st->hFdCngEnc->msNoiseEst_old_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, norm ); move16(); - zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); - IF( zero_flag ) - { - msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); - scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); /* exp(st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q) */ - st->hFdCngEnc->msNoiseEst_old_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); - move16(); - } + } + + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_TD ) && lr_vad_enabled && band_energies_LR_fx != NULL ) + { perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, sub( Q31, band_energies_LR_fx_q ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } ELSE { - Word16 normmsPeriodog_fx = Q31, zero_flag = 0; - move16(); - move16(); - shift = getScaleFactor32( band_energies_fx, 2 * NB_BANDS ); - scale_sig32( band_energies_fx, 2 * NB_BANDS, shift ); - q_band_energies = add( q_band_energies, shift ); - - zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); /* Q0 */ - IF( zero_flag ) - { - normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); - } - st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); - st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); - move16(); - move16(); - Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); /* exp(st->hFdCngEnc->msPeriodog_fx_exp - normmsPeriodog_fx)*/ - st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, normmsPeriodog_fx ); - move16(); - Word16 msNoiseEst_Q = Q31; - move16(); - zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); /* Q0 */ - IF( zero_flag ) + norm = L_norm_arr( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); + IF( NE_16( norm, Q31 ) ) { - msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); - scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); /* exp(st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q) */ - st->hFdCngEnc->msNoiseEst_old_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); + scale_sig32( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN, norm ); // exp:st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog-norm + st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = sub( st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, norm ); move16(); } - zero_flag = get_zero_flag( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); /* Q0 */ - Word16 normmsperiodog = 31; - move16(); - IF( zero_flag ) - { - normmsperiodog = getScaleFactor32( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); - } - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = sub( 31, normmsperiodog ); - move16(); perform_noise_estimation_enc_ivas_fx( band_energies_fx, sub( Q31, q_band_energies ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index fff68e5a228754258b367f756124be6f24ba2219..ab090edb81bef6642c0d562b6f1c645670b0bb18 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -241,9 +241,9 @@ ivas_error front_vad_fx( PREEMPH_FX( hFrontVad->buffer_12k8_fx + L_FFT / 2, PREEMPH_FAC, L_FRAME, &hFrontVad->mem_preemph_fx ); - Q_new = add( sub( Q_inp, Qband ), Q_add ); - Scale_sig( hFrontVad->buffer_12k8_fx, L_FFT / 2, sub( Q_new, Q_buffer[n] ) ); /* Q_new */ - Scale_sig( hFrontVad->buffer_12k8_fx + L_FFT / 2, 384 - L_FFT / 2, sub( Q_new, add( Q_inp, Qband ) ) ); /* Q_new */ + Q_new = s_min( add( add( Q_inp, Qband ), Q_add ), Q_buffer[n] ); + scale_sig( hFrontVad->buffer_12k8_fx, L_FFT / 2, sub( Q_new, Q_buffer[n] ) ); /* Q_new */ + scale_sig( hFrontVad->buffer_12k8_fx + L_FFT / 2, 3 * L_FRAME / 2 - L_FFT / 2, sub( Q_new, add( Q_inp, Qband ) ) ); /* Q_new */ Q_buffer[n] = Q_new; move16();