diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 12642e406b211ddc5dbc781cee2ff618b9a7183e..b830a3d73501ed9effa4d2add2351596c57eb0d4 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1959,6 +1959,7 @@ typedef enum _DCTTYPE #define TOD_NSPEC 80 /* number of spectral bins of the tonal detector */ #define TOD_NSPEC_INV_Q31 26843546 /* inverse of number of spectral bins of the tonal detector */ #define TOD_THR_MASS 0.86f /* initial value for the adaptive threshold of the tonal detector */ +#define TOD_THR_MASS_FX_Q22 3607101 /* initial value for the adaptive threshold of the tonal detector */ #define P2A_FACT 0.9f /* long-term averaging factor for peak-to-average ratio */ #define P2A_FACT_FX_Q15 29491 /* long-term averaging factor for peak-to-average ratio */ #define THR_P2A_HIGH 95.0f /* higher threshold to detect strongly peaky signals at low bitrates*/ diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index a4ec5e127164bd81514b65d6e744174316c2c58b..4c8df08998c6a0dccbf44138b33fe5c6642ad9d4 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -833,7 +833,7 @@ void ivas_updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis */ + const Word32 *synth, /* i : decoded synthesis Q(Qpostd) */ const Word16 Qpostd /* i : Synthesis Q value */ ) diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index 1196f2bd59da4576b0803420ba1b2e5d9a061c87..02a5152f71524b737874fb3d395e6cfe9c0bb5f5 100644 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -42,6 +42,9 @@ #include "prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -519,7 +522,81 @@ void amr_wb_enc( updt_enc( st, old_exc_flt, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec paramaters */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + f2me_buf_16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, &st->exp_buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + f2me_buf_16( st->buf_synth_flt, st->buf_synth, &st->exp_buf_synth, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); + IF( st->hTcxEnc != NULL ) + { + f2me_buf_16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, &st->exp_buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); + f2me_buf_16( st->hTcxEnc->buf_speech_ltp_flt, st->hTcxEnc->buf_speech_ltp, &st->hTcxEnc->exp_buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + } + IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + st->hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( st->hTcxEnc->tcxltp_norm_corr_past_flt, 15 ); + } +#endif + + updt_enc_common_ivas_fx( st ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + me2f_buf_16( st->buf_speech_enc_pe, st->exp_buf_speech_enc_pe, st->buf_speech_enc_pe_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + me2f_buf_16( st->buf_speech_enc, st->exp_buf_speech_enc, st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + me2f_buf_16( st->buf_synth, st->exp_buf_synth, st->buf_synth_flt, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); + IF( st->hTcxEnc != NULL ) + { + me2f_buf_16( st->buf_wspeech_enc, st->exp_buf_wspeech_enc, st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); + me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + } + + IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) + { + set_zero( st->mem_MA, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + + IF( st->hTcxEnc != NULL ) + { + IF( st->element_mode != IVAS_CPE_MDCT ) + { + st->hTcxEnc->kernel_switch_corr_past_flt = 0.f; + } + } + + IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 31 ); + } + + IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) + { + IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) + { + st->preemph_fac_flt = PREEMPH_FAC_FLT; + st->gamma_flt = GAMMA1_FLT; + } + ELSE + { + st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; + st->gamma_flt = GAMMA16k_FLT; + } + } + + IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL ) + { + IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) ) + { + IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) + { + st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); + } + } + } +#endif +#else updt_enc_common( st ); +#endif pop_wmops(); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index ca98212563e5d05d91068667ed03a6426d3d95c5..a0fb097e6654df318638c77f700ae9173bfe59fb 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -479,6 +479,9 @@ ivas_error init_encoder( } speech_music_clas_init( st->hSpMusClas ); +#if 1 + speech_music_clas_init_ivas_fx( st->hSpMusClas ); +#endif st->sp_aud_decision0 = 0; st->sp_aud_decision1 = 0; @@ -1595,7 +1598,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } - speech_music_clas_init_fx( st->hSpMusClas ); + speech_music_clas_init_ivas_fx( st->hSpMusClas ); #if 1 speech_music_clas_init( st->hSpMusClas ); #endif diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 935b76f69cd7b7e1d4c3f1e59f237bdf49b6a5b2..7dae9fc7e8a07025c1395d920f6cc182eeb7d03f 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2383,8 +2383,6 @@ ivas_error pre_proc_front_ivas_fx( L_Extract( epsP_fx[j], &epsP_h[j], &epsP_l[j] ); } - st->hSpMusClas->mean_avr_dyn_fx = float_to_fix16( st->hSpMusClas->mean_avr_dyn, Q7 ); - st->hSpMusClas->last_sw_dyn_fx = float_to_fix16( st->hSpMusClas->last_sw_dyn, Q7 ); floatToFixed_arr16( st->hSpMusClas->past_log_enr, st->hSpMusClas->past_log_enr_fx, Q8, NB_BANDS_SPMUS ); @@ -2572,9 +2570,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->ave_enr2, q_fr_bands, NB_BANDS ); fixedToFloat_arr( st->hSpMusClas->past_log_enr_fx, st->hSpMusClas->past_log_enr, Q8, NB_BANDS_SPMUS ); - st->hSpMusClas->ener_RAT = fixedToFloat_16( st->hSpMusClas->ener_RAT_fx, Q15 ); - st->hSpMusClas->mean_avr_dyn = fixedToFloat_16( st->hSpMusClas->mean_avr_dyn_fx, Q7 ); - st->hSpMusClas->last_sw_dyn = fixedToFloat_16( st->hSpMusClas->last_sw_dyn_fx, Q7 ); fixedToFloat_arr( st->hNoiseEst->old_S_fx, st->hNoiseEst->old_S, Q7, 128 ); fixedToFloat_arr( st->hNoiseEst->cor_map_fx, st->hNoiseEst->cor_map, Q15, 128 ); @@ -2792,8 +2787,6 @@ ivas_error pre_proc_front_ivas_fx( hSpMusClas->wrise_fx = float_to_fix16( hSpMusClas->wrise, 9 ); relE_fx = float_to_fix16( *relE, 8 ); floatToFixed_arr16( st->voicing, st->voicing_fx, 15, 3 ); - hSpMusClas->prev_relE_fx = float_to_fix16( hSpMusClas->prev_relE, 8 ); - hSpMusClas->relE_attack_sum_fx = float_to_fix16( hSpMusClas->relE_attack_sum, 8 ); Word16 Qfact_PS = Q_factor_arrL( PS, 128 ); floatToFixed_arr32( PS, PS_fx, Qfact_PS, 128 ); Word16 e_esp; @@ -2811,20 +2804,15 @@ ivas_error pre_proc_front_ivas_fx( smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx_0, lsp_new_fx, extract_l( L_shr( cor_map_sum_fx, sub( 23, cor_map_sum_e ) ) ) /*q8*/, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, Qfact_PS_past ); #if 1 fixedToFloat_arr( hSpMusClas->past_dlp_fx, hSpMusClas->past_dlp, Q9, HANG_LEN - 1 ); - hSpMusClas->lpm = fixedToFloat( hSpMusClas->lpm_fx, Q7 ); // Q7 - hSpMusClas->lps = fixedToFloat( hSpMusClas->lps_fx, Q7 ); // Q7 - hSpMusClas->lpn = fixedToFloat( hSpMusClas->lpn_fx, Q7 ); // Q7 - hSpMusClas->wdrop = fixedToFloat( hSpMusClas->wdrop_fx, Q9 ); // Q8 - hSpMusClas->wrise = fixedToFloat( hSpMusClas->wrise_fx, Q9 ); // Q8 - hSpMusClas->lt_dec_thres = fixedToFloat( hSpMusClas->lt_dec_thres_fx, Q9 ); // Q8 + hSpMusClas->lpm = fixedToFloat( hSpMusClas->lpm_fx, Q7 ); // Q7 + hSpMusClas->lps = fixedToFloat( hSpMusClas->lps_fx, Q7 ); // Q7 + hSpMusClas->wdrop = fixedToFloat( hSpMusClas->wdrop_fx, Q9 ); // Q8 + hSpMusClas->wrise = fixedToFloat( hSpMusClas->wrise_fx, Q9 ); // Q8 hSpMusClas->wdlp_0_95_sp = fixedToFloat( hSpMusClas->wdlp_0_95_sp_32fx, Q24 ); hSpMusClas->dlp_mean_LT = fixedToFloat_32( hSpMusClas->dlp_mean_LT_fx, Q19 ); hSpMusClas->wdlp_xtalk = fixedToFloat( hSpMusClas->wdlp_xtalk_fx, Q19 ); hSpMusClas->dlp_var_LT = fixedToFloat_32( hSpMusClas->dlp_var_LT_fx, Q19 ); - hSpMusClas->prev_relE = fixedToFloat( hSpMusClas->prev_relE_fx, Q8 ); - hSpMusClas->prev_Etot = fixedToFloat( hSpMusClas->prev_Etot_fx, Q8 ); fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); - hSpMusClas->relE_attack_sum = fixedToFloat( hSpMusClas->relE_attack_sum_fx, Q8 ); fixedToFloat_arrL32( hSpMusClas->FV_st_fx, hSpMusClas->FV_st, Q20, 15 ); fixedToFloat_arrL32( hSpMusClas->prev_FV_fx, hSpMusClas->prev_FV, Q20, 15 ); fixedToFloat_arrL32( hSpMusClas->past_dlp_mean_ST_fx, hSpMusClas->past_dlp_mean_ST, Q19, 7 ); @@ -3138,18 +3126,10 @@ ivas_error pre_proc_front_ivas_fx( st->hSpMusClas->gsc_mem_etot_fx = float_to_fix16( st->hSpMusClas->gsc_mem_etot, Q8 ); floatToFixed_arr( st->hSpMusClas->gsc_thres, st->hSpMusClas->gsc_thres_fx, Q11, 4 ); st->old_corr_fx = float_to_fix16( st->old_corr, Q15 ); - floatToFixed_arr( st->hSpMusClas->var_cor_t, st->hSpMusClas->var_cor_t_fx, Q11, VAR_COR_LEN ); floatToFixed_arrL( st->hSpMusClas->finc_prev, st->hSpMusClas->finc_prev_fx, 2 * Q_new, ATT_NSEG ); st->hSpMusClas->lt_finc_fx = floatToFixed( st->hSpMusClas->lt_finc, 2 * Q_new ); st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); st->hSpMusClas->wdlp_0_95_sp_fx = float_to_fix16( st->hSpMusClas->wdlp_0_95_sp, Q8 ); - st->hSpMusClas->ener_RAT_fx = float_to_fix16( st->hSpMusClas->ener_RAT, Q8 ); - st->hSpMusClas->lt_dec_thres_fx = float_to_fix16( st->hSpMusClas->lt_dec_thres, Q9 ); - st->hSpMusClas->tod_S_mass_lt_fx = float_to_fix( st->hSpMusClas->tod_S_mass_lt, Q22 ); - st->hSpMusClas->tod_S_mass_prev_fx = float_to_fix( st->hSpMusClas->tod_S_mass_prev, Q22 ); - st->hSpMusClas->tod_thr_lt_fx = float_to_fix( st->hSpMusClas->tod_thr_lt, Q22 ); - floatToFixed_arrL( st->hSpMusClas->tod_S_map_lt, st->hSpMusClas->tod_S_map_lt_fx, Q22, TOD_NSPEC ); - st->hSpMusClas->tod_weight_fx = float_to_fix16( st->hSpMusClas->tod_weight, Q15 ); st->hSpMusClas->mold_corr_fx = float_to_fix16( st->hSpMusClas->mold_corr, Q15 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS @@ -3163,12 +3143,6 @@ ivas_error pre_proc_front_ivas_fx( st->hSpMusClas->lt_finc = fixedToFloat( st->hSpMusClas->lt_finc_fx, 2 * Q_new ); fixedToFloat_arrL( st->hSpMusClas->tod_lt_Bin_E_fx, st->hSpMusClas->tod_lt_Bin_E, Q_new + Q_SCALE - 2, TOD_NSPEC ); st->hSpMusClas->mold_corr = fix16_to_float( st->hSpMusClas->mold_corr_fx, Q15 ); - st->hSpMusClas->tod_S_mass_lt = fix_to_float( st->hSpMusClas->tod_S_mass_lt_fx, Q22 ); - st->hSpMusClas->tod_S_mass_prev = fix_to_float( st->hSpMusClas->tod_S_mass_prev_fx, Q22 ); - st->hSpMusClas->tod_thr_lt = fix_to_float( st->hSpMusClas->tod_thr_lt_fx, Q22 ); - fixedToFloat_arrL( st->hSpMusClas->tod_S_map_lt_fx, st->hSpMusClas->tod_S_map_lt, Q22, TOD_NSPEC ); - st->hSpMusClas->tod_weight = fix16_to_float( st->hSpMusClas->tod_weight_fx, Q15 ); - fixedToFloat_arr( st->hSpMusClas->var_cor_t_fx, st->hSpMusClas->var_cor_t, Q11, VAR_COR_LEN ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index e62c45e7e98bf0de63f89aac590a07449ce82f25..5da4e6484e351023c56eec66d0923d664ea6bccc 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -48,6 +48,7 @@ #include "ivas_prot_fx.h" #include "prot_fx.h" #include "ivas_rom_enc.h" +#include "prot_fx_enc.h" #endif @@ -490,7 +491,62 @@ ivas_error ivas_cpe_enc( if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) ) { +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + sts[n]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.firState1_flt, -1 ); + sts[n]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.firState2_flt, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + sts[n]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( sts[n]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + sts[n]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( sts[n]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + sts[n]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( sts[n]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); + } + + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + sts[n]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( sts[n]->hTranDet->delayBuffer.buffer_flt[i], -1 ); + } + + sts[n]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( sts[n]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); + + floatToFixed_arr16( sts[n]->input, sts[n]->input_fx, -1, input_frame ); + + sts[n]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( sts[n]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + +#endif + + RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + sts[n]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.firState1, -1 ); + sts[n]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.firState2, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + sts[n]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( sts[n]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + sts[n]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) sts[n]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + sts[n]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( sts[n]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + sts[n]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) sts[n]->hTranDet->delayBuffer.buffer[i], -1 ); + } +#endif +#else RunTransientDetection( sts[n]->input, input_frame, sts[n]->hTranDet ); +#endif } #ifndef IVAS_FLOAT_FIXED currFlatness[n] = GetTCXAvgTemporalFlatnessMeasure( sts[n]->hTranDet, NSUBBLOCKS, 0 ); diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 643339e10e6d955db3f71570bd916a6816ce8ac5..27a4fd5779cdb0006a57fbce5eef1c90b2387efe 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -1136,8 +1136,6 @@ ivas_error front_vad_spar( floatToFixed_arr( hFrontVad->hNoiseEst->cor_map, hFrontVad->hNoiseEst->cor_map_fx, Q15, 128 ); // floatToFixed_arr( hFrontVad->hNoiseEst->cor_map, hFrontVad->hNoiseEst->old_S_fx, Q15, 128 ); hFrontVad->hNoiseEst->multi_harm_limit_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->multi_harm_limit, Q9 ); - st->hSpMusClas->mean_avr_dyn_fx = (Word16) floatToFixed( st->hSpMusClas->mean_avr_dyn, Q7 ); - st->hSpMusClas->last_sw_dyn_fx = (Word16) floatToFixed( st->hSpMusClas->last_sw_dyn, Q7 ); // cor_map_sum_fx = (Word16) floatToFixed( cor_map_sum, Q8 ); // dummy_fx = (Word16) floatToFixed( dummy, Q7 ); floatToFixed_arr( hFrontVad->hNoiseEst->old_S, hFrontVad->hNoiseEst->old_S_fx, Q7, 128 ); @@ -1147,8 +1145,6 @@ ivas_error front_vad_spar( fixedToFloat_arr( hFrontVad->hNoiseEst->cor_map_fx, hFrontVad->hNoiseEst->cor_map, Q15, 128 ); // floatToFixed_arr( hFrontVad->hNoiseEst->cor_map, hFrontVad->hNoiseEst->old_S_fx, Q15, 128 ); hFrontVad->hNoiseEst->multi_harm_limit = fixedToFloat( hFrontVad->hNoiseEst->multi_harm_limit_fx, Q9 ); - st->hSpMusClas->mean_avr_dyn = fixedToFloat( st->hSpMusClas->mean_avr_dyn_fx, Q7 ); - st->hSpMusClas->last_sw_dyn = fixedToFloat( st->hSpMusClas->last_sw_dyn_fx, Q7 ); cor_map_sum = fixedToFloat( cor_map_sum_fx, Q8 ); // dummy = fixedToFloat( dummy_fx, Q7 ); fixedToFloat_arr( hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->old_S, Q7, 128 ); @@ -1253,8 +1249,6 @@ ivas_error front_vad_spar( hSpMusClas->wrise_fx = float_to_fix16( hSpMusClas->wrise, 9 ); relE_fx = float_to_fix16( relE, 8 ); floatToFixed_arr16( st->voicing, st->voicing_fx, 15, 3 ); - hSpMusClas->prev_relE_fx = float_to_fix16( hSpMusClas->prev_relE, 8 ); - hSpMusClas->relE_attack_sum_fx = float_to_fix16( hSpMusClas->relE_attack_sum, 8 ); Word16 Qfact_PS = Q_factor_arrL( PS, 128 ); floatToFixed_arr32( PS, PS_fx, Qfact_PS, 128 ); Word16 e_esp; @@ -1274,18 +1268,13 @@ ivas_error front_vad_spar( fixedToFloat_arr( hSpMusClas->past_dlp_fx, hSpMusClas->past_dlp, Q9, HANG_LEN - 1 ); hSpMusClas->lpm = fixedToFloat( hSpMusClas->lpm_fx, Q7 ); // Q7 hSpMusClas->lps = fixedToFloat( hSpMusClas->lps_fx, Q7 ); // Q7 - hSpMusClas->lpn = fixedToFloat( hSpMusClas->lpn_fx, Q7 ); // Q7 hSpMusClas->wdrop = fixedToFloat( hSpMusClas->wdrop_fx, Q9 ); // Q9 hSpMusClas->wrise = fixedToFloat( hSpMusClas->wrise_fx, Q9 ); // Q9 - hSpMusClas->lt_dec_thres = fixedToFloat( hSpMusClas->lt_dec_thres_fx, Q9 ); // Q9 hSpMusClas->wdlp_0_95_sp = fixedToFloat( hSpMusClas->wdlp_0_95_sp_32fx, Q24 ); // Q24 hSpMusClas->dlp_mean_LT = fixedToFloat_32( hSpMusClas->dlp_mean_LT_fx, Q19 ); hSpMusClas->wdlp_xtalk = fixedToFloat( hSpMusClas->wdlp_xtalk_fx, Q19 ); hSpMusClas->dlp_var_LT = fixedToFloat_32( hSpMusClas->dlp_var_LT_fx, Q19 ); - hSpMusClas->prev_relE = fixedToFloat( hSpMusClas->prev_relE_fx, Q8 ); - hSpMusClas->prev_Etot = fixedToFloat( hSpMusClas->prev_Etot_fx, Q8 ); fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); - hSpMusClas->relE_attack_sum = fixedToFloat( hSpMusClas->relE_attack_sum_fx, Q8 ); fixedToFloat_arrL32( hSpMusClas->FV_st_fx, hSpMusClas->FV_st, Q20, 15 ); hSpMusClas->dlp_mean_ST = fixedToFloat( hSpMusClas->dlp_mean_ST_fx, Q19 ); fixedToFloat_arrL32( hSpMusClas->past_dlp_mean_ST_fx, hSpMusClas->past_dlp_mean_ST, Q19, 7 ); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index bc66cd985d31a601f1cf7359c25b872d38bee1e9..b148aad7c3826a2e75df701d40b1561573a9d02c 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -555,7 +555,62 @@ ivas_error ivas_ism_enc( * Time Domain Transient Detector *---------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState1_flt, -1 ); + st->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState2_flt, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + st->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); + } + + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st->hTranDet->delayBuffer.buffer_flt[i], 7 ); + } + + st->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); + + floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); + st->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + +#endif + + RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + st->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState1, -1 ); + st->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState2, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + st->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st->hTranDet->delayBuffer.buffer[i], -1 ); + } +#endif +#else RunTransientDetection( st->input, input_frame, st->hTranDet ); +#endif + #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 e_tmp; diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 963af28a843df9f8e76443af8a61dab78bb07c79..12eded9c0870f383e95151e6c9de18d70422d46b 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -45,6 +45,10 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx_enc.h" +#include "prot_fx.h" +#endif /*------------------------------------------------------------------------- * Local function prototypes @@ -650,6 +654,10 @@ void ivas_param_mc_enc( PARAM_MC_ENC_HANDLE hParamMC; int16_t nchan_inp; +#ifdef IVAS_FLOAT_FIXED + Word16 data_dmx_fx[PARAM_MC_MAX_TRANSPORT_CHANS][L_FRAME48k]; +#endif + push_wmops( "param_mc_enc" ); /* initializations */ @@ -700,8 +708,61 @@ void ivas_param_mc_enc( { int16_t cpe_idx = ch / 2; - RunTransientDetection( data_dmx[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); + } + + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], 7 ); + } + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); + floatToFixed_arr16( data_dmx[ch], data_dmx_fx[ch], -1, input_frame ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + +#endif + + RunTransientDetection_ivas_fx( data_dmx_fx[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); + + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); + } +#endif +#else + RunTransientDetection( data_dmx[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); +#endif ivas_param_mc_transient_detection( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); } @@ -777,7 +838,66 @@ void ivas_param_mc_enc( set_zero( data_f[ch], input_frame ); +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 data_fx[L_FRAME48k]; + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); + } + + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], -1 ); + } + + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); + + floatToFixed_arr16( data_f[ch], data_fx, -1, input_frame ); + + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + +#endif + + RunTransientDetection_ivas_fx( data_fx, input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); + } + +#endif +#else RunTransientDetection( data_f[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); +#endif } } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index feef25497a36ecd48b17a9d87526365c6131c6f3..337f39eb591c4830d538e74cd801680d3a1138ad 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -42,6 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" #include "ivas_prot_fx.h" +#include "rom_com.h" #endif @@ -661,7 +662,82 @@ ivas_error ivas_mct_enc( mvr2r( hCPE->hCoreCoder[n]->input, hCPE->hCoreCoder[n]->old_input_signal, input_frame ); /* common encoder updates */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st = hCPE->hCoreCoder[n]; + f2me_buf_16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, &st->exp_buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + f2me_buf_16( st->buf_synth_flt, st->buf_synth, &st->exp_buf_synth, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); + IF( st->hTcxEnc != NULL ) + { + f2me_buf_16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, &st->exp_buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); + f2me_buf_16( st->hTcxEnc->buf_speech_ltp_flt, st->hTcxEnc->buf_speech_ltp, &st->hTcxEnc->exp_buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + } + IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + st->hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( st->hTcxEnc->tcxltp_norm_corr_past_flt, 15 ); + } +#endif + + updt_enc_common_ivas_fx( st ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + me2f_buf_16( st->buf_speech_enc_pe, st->exp_buf_speech_enc_pe, st->buf_speech_enc_pe_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + me2f_buf_16( st->buf_speech_enc, st->exp_buf_speech_enc, st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + me2f_buf_16( st->buf_synth, st->exp_buf_synth, st->buf_synth_flt, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); + IF( st->hTcxEnc != NULL ) + { + me2f_buf_16( st->buf_wspeech_enc, st->exp_buf_wspeech_enc, st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); + me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + } + + IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) + { + set_zero( st->mem_MA, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + + IF( st->hTcxEnc != NULL ) + { + IF( st->element_mode != IVAS_CPE_MDCT ) + { + st->hTcxEnc->kernel_switch_corr_past_flt = 0.f; + } + } + + IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 31 ); + } + + IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) + { + IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) + { + st->preemph_fac_flt = PREEMPH_FAC_FLT; + st->gamma_flt = GAMMA1_FLT; + } + ELSE + { + st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; + st->gamma_flt = GAMMA16k_FLT; + } + } + + IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL ) + { + IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) ) + { + IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) + { + st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); + } + } + } +#endif +#else updt_enc_common( hCPE->hCoreCoder[n] ); +#endif } } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index e50d1d9b36e822d8b380a69a9973d253dfe2cd5d..8ed19413efdbc8cd7f9b053fd46ba121961fe4ed 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -47,6 +47,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx_enc.h" #endif @@ -143,7 +144,61 @@ ivas_error ivas_sce_enc( if ( ivas_format != MC_FORMAT || st_ivas->mc_mode != MC_MODE_PARAMMC ) { +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState1_flt, -1 ); + st->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState2_flt, -1 ); + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + st->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); + } + + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st->hTranDet->delayBuffer.buffer_flt[i], -1 ); + } + + st->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); + + floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); + + st->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + +#endif + + RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + st->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState1, -1 ); + st->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState2, -1 ); + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + st->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st->hTranDet->delayBuffer.buffer[i], -1 ); + } +#endif +#else RunTransientDetection( st->input, input_frame, st->hTranDet ); +#endif } currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 0c21dde3aab42da61478479a36a1e1cfdd589ef9..fca33216ba736450e09320318e5adb1453da7615 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -112,7 +112,7 @@ static ivas_error allocate_CoreCoder_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } #ifdef IVAS_FLOAT_FIXED - speech_music_clas_init_fx( st->hSpMusClas ); + speech_music_clas_init_ivas_fx( st->hSpMusClas ); #endif speech_music_clas_init( st->hSpMusClas ); } @@ -177,6 +177,9 @@ static ivas_error allocate_CoreCoder_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } speech_music_clas_init( st->hSpMusClas ); +#if 1 + speech_music_clas_init_ivas_fx( st->hSpMusClas ); +#endif } return IVAS_ERR_OK; diff --git a/lib_enc/nois_est.c b/lib_enc/nois_est.c index 483c26a02398932711d43eea117294fb84d8c323..32585626d96ec9982eca6298aa46d5cc11646442 100644 --- a/lib_enc/nois_est.c +++ b/lib_enc/nois_est.c @@ -154,6 +154,7 @@ void noise_est_init( } +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * noise_est_pre() * @@ -1006,3 +1007,4 @@ void noise_est( return; } +#endif diff --git a/lib_enc/pre_proc.c b/lib_enc/pre_proc.c index 096aeb07c5d62643a4cd0803273afd4d35cbcce9..f9210f67550def169bb85b428e570058feb13563 100644 --- a/lib_enc/pre_proc.c +++ b/lib_enc/pre_proc.c @@ -336,50 +336,7 @@ void pre_proc( if ( st->tcx10Enabled || st->tcx20Enabled ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState1_flt, 0 ); - st->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st->hTranDet->subblockEnergies.firState2_flt, 0 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 0 ); - } - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st->hTranDet->subblockEnergies.subblockNrg_flt[i], 0 ); - } - - - FOR( Word16 i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st->hTranDet->subblockEnergies.pDelayBuffer->buffer[i] = float_to_fix16( st->hTranDet->subblockEnergies.pDelayBuffer->buffer_flt[i], 0 ); - } - - st->hTranDet->transientDetector.attackRatioThreshold = float_to_fix16( st->hTranDet->transientDetector.attackRatioThreshold_flt, 0 ); - - floatToFixed_arr( st->input, st->input_fx, 0, input_frame ); - - st->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 0 ); - -#endif - - RunTransientDetection_ivas_fx( signal_in_fx, input_frame, st->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState1, 0 ); - st->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st->hTranDet->subblockEnergies.firState2, 0 ); - - FOR( Word16 i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st->hTranDet->subblockEnergies.subblockNrg[i], 0 ); - } -#endif -#else RunTransientDetection( signal_in, input_frame, st->hTranDet ); -#endif currFlatness = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 6355d1ef9de46d8482979f9df15096197e6980c2..1e7315e652ed0afc634ae46d091570a12b78f934 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1062,9 +1062,9 @@ void RunTransientDetection_fx( Word16 const *i, Word16 nSamplesAvailable, struct void RunTransientDetection_ivas_fx( - const Word16 *input_fx, /* i : input signal Q0 */ - const int16_t length, /* i : frame length */ - TRAN_DET_HANDLE hTranDet /* i/o: transient detection handle */ + const Word16 *input_fx, /* i : input signal Q: -1 */ + const int16_t length, /* i : frame length */ + TRAN_DET_HANDLE hTranDet /* i/o: transient detection handle */ ); /** Get the average temporal flatness measure using subblock energies aligned with the TCX. @@ -1149,6 +1149,10 @@ void speech_music_clas_init_fx( SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ); +void speech_music_clas_init_ivas_fx( + SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ +); + void pitchDoubling_det_fx( Word16 *wspeech, Word16 *pitch_ol, diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 15c13f0afc7642e5906ab17d265734be26a6d4a2..9fe43f12846962966bd49785423ec37c0cd2e413 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -49,6 +49,7 @@ #endif +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -84,9 +85,9 @@ static int16_t mode_decision( Encoder_State *st, int16_t len, float *dec_mov, fl static void var_cor_calc( const float old_corr, float *mold_corr, float var_cor_t[], int16_t *high_stable_cor ); static int16_t attack_det( const float *inp, const int16_t last_clas, const int16_t localVAD, const int16_t coder_type, const int32_t total_brate, const int16_t element_mode, const int16_t clas, float finc_prev[], float *lt_finc, int16_t *last_strong_attack ); -#ifndef IVAS_FLOAT_FIXED + static float tonal_det( const float S[], int16_t vad_flag, float tod_S_map_lt[], float *tod_thr_lt, float *tod_weight, float *tod_S_mass_prev, float *tod_S_mass_lt ); -#endif + static void tonal_context_improv( Encoder_State *st, const float PS[], const float voi_fv, const float cor_map_sum_fv, const float LPCErr ); static void order_spectrum( float *vec, const int16_t len ); @@ -98,6 +99,7 @@ static int16_t sp_mus_classif_1st( Encoder_State *st, const int16_t localVAD_HE_ static void sp_mus_classif_2nd( Encoder_State *st, const float Etot, int16_t *attack_flag, const float *inp ); static void music_mixed_classif_improv( Encoder_State *st, const float *new_inp, const float *epsP, const float etot, const float old_cor, const float cor_map_sum ); +#endif /*---------------------------------------------------------------------* @@ -155,8 +157,10 @@ void speech_music_clas_init( hSpMusClas->last_non_sta = 0.0f; set_f( hSpMusClas->past_PS, 0.0f, HIGHEST_FBIN - LOWEST_FBIN ); hSpMusClas->past_ps_diff = 0; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->past_epsP2 = 01; hSpMusClas->past_epsP = 0; +#endif hSpMusClas->flag_spitch_cnt = 0; hSpMusClas->gsc_thres[0] = TH_0_MIN; @@ -169,17 +173,24 @@ void speech_music_clas_init( hSpMusClas->gsc_nb_thr_1 = 0; hSpMusClas->gsc_nb_thr_3 = 0; hSpMusClas->mold_corr = 0.9f; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->mean_avr_dyn = 0.5f; hSpMusClas->last_sw_dyn = 10.0f; +#endif hSpMusClas->relE_attack_cnt = 0; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->prev_relE = 0.0f; hSpMusClas->prev_Etot = 0.0f; +#endif hSpMusClas->prev_vad = 0; hSpMusClas->vad_0_1_cnt = 0; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->relE_attack_sum = 0; +#endif /* speech/music classifier improvement */ +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < BUF_LEN; i++ ) { hSpMusClas->buf_flux[i] = -100; @@ -190,29 +201,40 @@ void speech_music_clas_init( hSpMusClas->buf_Ntonal2[i] = 0; hSpMusClas->buf_Ntonal_lf[i] = 0; } +#endif +#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->lpe_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->voicing_buf, 0, HANG_LEN_INIT ); +#endif hSpMusClas->gsc_hangover = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->sparse_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->hf_spar_buf, 0, HANG_LEN_INIT ); hSpMusClas->LT_sparse = 0.0f; +#endif hSpMusClas->gsc_cnt = 0; hSpMusClas->last_vad_spa = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->old_Bin_E, 0.0f, 3 * N_OLD_BIN_E ); set_f( hSpMusClas->buf_etot, 0, 4 ); set_f( hSpMusClas->buf_dlp, 0, 10 ); +#endif hSpMusClas->UV_cnt1 = 300; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->LT_UV_cnt1 = 250.0f; +#endif hSpMusClas->onset_cnt = 0; hSpMusClas->attack_hangover = 0; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->dec_mov = 0.0f; hSpMusClas->dec_mov1 = 0.0f; hSpMusClas->mov_log_max_spl = 200.0f; hSpMusClas->old_lt_diff[0] = 0.0f; hSpMusClas->old_lt_diff[1] = 0.0f; +#endif set_f( hSpMusClas->finc_prev, 0.0f, ATT_NSEG ); hSpMusClas->lt_finc = 0.0f; @@ -223,43 +245,56 @@ void speech_music_clas_init( hSpMusClas->tdm_lt_Etot = 0.01f; #endif set_f( hSpMusClas->tod_lt_Bin_E, 0.0f, TOD_NSPEC ); +#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->tod_S_map_lt, 0.0f, TOD_NSPEC ); hSpMusClas->tod_thr_lt = TOD_THR_MASS; hSpMusClas->tod_weight = 0.0f; hSpMusClas->tod_S_mass_prev = 0.0f; hSpMusClas->tod_S_mass_lt = 0.0f; +#endif /* speech/music classification */ set_s( hSpMusClas->lt_old_mode, 1, 3 ); +#ifndef IVAS_FLOAT_FIXED hSpMusClas->lt_voicing_flt = 0.5f; hSpMusClas->lt_corr_flt = 0.5f; hSpMusClas->lt_tonality_flt = 0; +#endif set_s( hSpMusClas->lt_corr_pitch, 0, 3 ); hSpMusClas->lt_hangover = 0; hSpMusClas->lowrate_pitchGain_flt = 0; hSpMusClas->lt_music_hangover = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->tonality2_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->tonality3_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->LPCErr_buf, 0, HANG_LEN_INIT ); +#endif hSpMusClas->lt_music_state = 0; hSpMusClas->lt_speech_state = 0; hSpMusClas->lt_speech_hangover = 0; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->lt_dec_thres = 10.0f; hSpMusClas->ener_RAT = 0.0f; +#endif hSpMusClas->high_stable_cor = 0; +#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->var_cor_t, 0.0f, VAR_COR_LEN ); +#endif hSpMusClas->lps = 0.0f; hSpMusClas->lpm = 0.0f; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->lpn = 0.0f; +#endif return; } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * speech_music_classif() * @@ -904,7 +939,7 @@ static void sp_mus_classif_2nd( return; } -#ifndef IVAS_FLOAT_FIXED + /*---------------------------------------------------------------------* * tonal_det() * @@ -978,7 +1013,7 @@ static float tonal_det( return S_mass; } -#endif + /*---------------------------------------------------------------------* * var_cor_calc() * @@ -1148,7 +1183,6 @@ static int16_t attack_det( *---------------------------------------------------------------------*/ /*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ -#ifndef IVAS_FLOAT_FIXED int16_t ivas_smc_gmm( Encoder_State *st, /* i/o: state structure */ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ @@ -1812,7 +1846,6 @@ int16_t ivas_smc_gmm( return dec; } -#endif /*---------------------------------------------------------------------* * ivas_smc_mode_selection() @@ -1823,7 +1856,7 @@ int16_t ivas_smc_gmm( * 1 - 0 -> GSC * 1 - 1 -> TCX *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void ivas_smc_mode_selection( Encoder_State *st, /* i/o: encoder state structure */ const int32_t element_brate, /* i : element bitrate */ @@ -2023,7 +2056,6 @@ void ivas_smc_mode_selection( return; } -#endif /*------------------------------------------------------------------------* * music_mixed_classif_improv() @@ -3075,3 +3107,4 @@ static void order_spectrum( return; } +#endif diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index ac796e54d3bc9751390116a71335bb6c74c2f445..ee1edb1b23634ff50a1ef076722a52fe05979d0b 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -285,6 +285,220 @@ void speech_music_clas_init_fx( return; } +void speech_music_clas_init_ivas_fx( + SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ +) +{ + Word16 i; + + set32_fx( hSpMusClas->FV_st_fx, 0, N_SMC_FEATURES ); //?? + + hSpMusClas->inact_cnt = 0; + move16(); + set16_fx( hSpMusClas->past_dec, 0, HANG_LEN - 1 ); + set16_fx( hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1 ); + + set32_fx( hSpMusClas->past_dlp_mean_ST_fx, 0, HANG_LEN - 1 ); + hSpMusClas->dlp_mean_ST_fx = 0; + move32(); + hSpMusClas->dlp_mean_LT_fx = 0; + move32(); + hSpMusClas->dlp_var_LT_fx = 0; + move32(); + + FOR( i = 0; i < N_SMC_FEATURES; i++ ) + { + hSpMusClas->prev_FV_fx[i] = L_add( L_shr( hout_intervals_fx[2 * i], 1 ), L_shr( hout_intervals_fx[2 * i + 1], 1 ) ); + move32(); + } + + FOR( i = 0; i < NB_BANDS_SPMUS; i++ ) + { + hSpMusClas->past_log_enr_fx[i] = -1448; /* log(E_MIN) in Q8 */ + move16(); + } + + hSpMusClas->sp_mus_state = -8; + move16(); + hSpMusClas->wdrop_fx = 0; + move16(); + hSpMusClas->wrise_fx = 0; + move16(); + hSpMusClas->wdlp_0_95_sp_fx = 0; + move16(); + hSpMusClas->wdlp_xtalk_fx = 0; + move16(); + set16_fx( hSpMusClas->last_lsp_fx, 0, M_LSP_SPMUS ); + hSpMusClas->last_cor_map_sum_fx = 0; + move16(); + hSpMusClas->last_non_sta_fx = 0; + move16(); + set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); + hSpMusClas->past_ps_diff_fx = 0; + move16(); + hSpMusClas->past_epsP2_fx = 1024; /* 1.0f in Q10 */ + move16(); + hSpMusClas->past_epsP_fx = 0; + move16(); + hSpMusClas->flag_spitch_cnt = 0; + move16(); + + + hSpMusClas->gsc_thres_fx[0] = TH_0_MIN_FX; + move16(); + hSpMusClas->gsc_thres_fx[1] = TH_1_MIN_FX; + move16(); + hSpMusClas->gsc_thres_fx[2] = TH_2_MIN_FX; + move16(); + hSpMusClas->gsc_thres_fx[3] = TH_3_MIN_FX; + move16(); + set16_fx( hSpMusClas->gsc_lt_diff_etot_fx, 0, 40 ); + hSpMusClas->gsc_mem_etot_fx = 0; + move16(); + hSpMusClas->gsc_last_music_flag = 0; + move16(); + hSpMusClas->gsc_nb_thr_1 = 0; + move16(); + hSpMusClas->gsc_nb_thr_3 = 0; + move16(); + hSpMusClas->mold_corr_fx = 29491; /* 0.9f in Q15 */ + move16(); + hSpMusClas->mean_avr_dyn_fx = 64; /* 0.5f in Q7 */ + move16(); + hSpMusClas->last_sw_dyn_fx = 2560; /* 10.0f in Q7 */ + move16(); + + hSpMusClas->relE_attack_cnt = 0; + move16(); + hSpMusClas->prev_relE_fx = 0; + move16(); + hSpMusClas->prev_Etot_fx = 0; + move16(); + hSpMusClas->prev_vad = 0; + move16(); + hSpMusClas->vad_0_1_cnt = 0; + move16(); + hSpMusClas->relE_attack_sum_fx = 0; + move16(); + + /* speech/music classifier improvement */ + FOR( i = 0; i < BUF_LEN; i++ ) + { + hSpMusClas->buf_flux_fx[i] = -12800; /*-100.0f in Q7 */ + move16(); + hSpMusClas->buf_pkh_fx[i] = 0; + move16(); + hSpMusClas->buf_epsP_tilt_fx[i] = 0; + move16(); + hSpMusClas->buf_cor_map_sum_fx[i] = 0; + move16(); + hSpMusClas->buf_Ntonal_fx[i] = 0; + move16(); + hSpMusClas->buf_Ntonal2_fx[i] = 0; + move16(); + hSpMusClas->buf_Ntonal_lf_fx[i] = 0; + move16(); + } + + set16_fx( hSpMusClas->lpe_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->voicing_buf_fx, 0, HANG_LEN_INIT ); + hSpMusClas->gsc_hangover = 0; + move16(); + set16_fx( hSpMusClas->sparse_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->hf_spar_buf_fx, 0, HANG_LEN_INIT ); + hSpMusClas->LT_sparse_fx = 0; + move16(); + hSpMusClas->gsc_cnt = 0; + move16(); + hSpMusClas->last_vad_spa = 0; + move16(); + + set16_fx( hSpMusClas->old_Bin_E_fx, 0, 3 * N_OLD_BIN_E ); + set16_fx( hSpMusClas->buf_etot_fx, 0, 4 ); + set16_fx( hSpMusClas->buf_dlp_fx, 0, 10 ); + + hSpMusClas->UV_cnt1 = 300; + move16(); + hSpMusClas->LT_UV_cnt1_fx = 16000; /* 250.0f in Q6 */ + move16(); + hSpMusClas->onset_cnt = 0; + move16(); + hSpMusClas->attack_hangover = 0; + move16(); + hSpMusClas->dec_mov_fx = 0; + move16(); + hSpMusClas->dec_mov1_fx = 0; + move16(); + hSpMusClas->mov_log_max_spl_fx = 25600; /* 200.0 in Q7 */ + move16(); + hSpMusClas->old_lt_diff_fx[0] = 0; + move16(); + hSpMusClas->old_lt_diff_fx[1] = 0; + move16(); + + set32_fx( hSpMusClas->finc_prev_fx, 0, ATT_NSEG ); + hSpMusClas->lt_finc_fx = 0; + move32(); + hSpMusClas->last_strong_attack = 0; + move16(); + hSpMusClas->tdm_lt_Etot_fx = 3; /* 0.01f in Q8 */ + move16(); + set32_fx( hSpMusClas->tod_lt_Bin_E_fx, 0, TOD_NSPEC ); + set32_fx( hSpMusClas->tod_S_map_lt_fx, 0, TOD_NSPEC ); + hSpMusClas->tod_thr_lt_fx = TOD_THR_MASS_FX_Q22; + move32(); + hSpMusClas->tod_weight_fx = 0; + move16(); + hSpMusClas->tod_S_mass_prev_fx = 0; + move32(); + hSpMusClas->tod_S_mass_lt_fx = 0; + move32(); + + /* speech/music classification */ + set16_fx( hSpMusClas->lt_old_mode, 1, 3 ); + hSpMusClas->lt_voicing = 16384; /* 0.5f in Q15 */ + move16(); + hSpMusClas->lt_corr = 16384; /* 0.5f in Q15 */ + move16(); + hSpMusClas->lt_tonality = 0; + move32(); + set16_fx( hSpMusClas->lt_corr_pitch, 0, 3 ); + hSpMusClas->lt_hangover = 0; + move16(); + hSpMusClas->lowrate_pitchGain = 0; + move16(); + + hSpMusClas->lt_music_hangover = 0; + move16(); + set16_fx( hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->tonality3_buf_fx, 0, HANG_LEN_INIT ); + set16_fx( hSpMusClas->LPCErr_buf_fx, 0, HANG_LEN_INIT ); + hSpMusClas->lt_music_state = 0; + move16(); + hSpMusClas->lt_speech_state = 0; + move16(); + hSpMusClas->lt_speech_hangover = 0; + move16(); + + hSpMusClas->lt_dec_thres_fx = 5120; /* 10.0f in Q9 */ + move16(); + hSpMusClas->ener_RAT_fx = 0; + move16(); + + hSpMusClas->high_stable_cor = 0; + move16(); + set16_fx( hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN ); + + hSpMusClas->lps_fx = 0; + move16(); + hSpMusClas->lpm_fx = 0; + move16(); + hSpMusClas->lpn_fx = 0; + move16(); + + return; +} + /*---------------------------------------------------------------------* * speech_music_classif() * diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index a4776eeb801fde98fde2acf0e00ad08e67aaa3f3..688769db0e0e6c8ba501dba21b7acc36a9f61416 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -869,9 +869,13 @@ typedef struct sp_mus_clas_structure Word16 past_ps_diff_fx; float prev_FV[N_SMC_FEATURES]; Word32 prev_FV_fx[N_SMC_FEATURES]; +#ifndef IVAS_FLOAT_FIXED float past_epsP; float past_epsP2; - Word16 past_epsP2_fx; +#else + Word16 past_epsP_fx; + Word16 past_epsP2_fx; /* Q10 */ +#endif int16_t inact_cnt; float wdrop; Word16 wdrop_fx; @@ -914,28 +918,37 @@ typedef struct sp_mus_clas_structure int16_t gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ int16_t gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ float mold_corr; + Word16 mold_corr_fx; /* Q15 */ +#ifndef IVAS_FLOAT_FIXED float mean_avr_dyn; /* Speech/music classifier - long term average dynamic */ float last_sw_dyn; /* Speech/music classifier - last dynamic */ float lt_dec_thres; /* Speech/music classifier - Long term speech/music thresold values */ float ener_RAT; /* Speech/music classifier - LF/to total energy ratio */ - Word16 mold_corr_fx; - - Word16 mean_avr_dyn_fx; /* Q7 Speech/music classifier - long term average dynamic */ - Word16 last_sw_dyn_fx; /* Q7 Speech/music classifier - last dynamic */ - Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values */ - Word16 ener_RAT_fx; /* Q15 Speech/music classifier - LF/to total energy ratio */ +#else + Word16 mean_avr_dyn_fx; /* Speech/music classifier - long term average dynamic Q7 */ + Word16 last_sw_dyn_fx; /* Speech/music classifier - last dynamic Q7 */ + Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values Q9 */ + Word16 ener_RAT_fx; /* Speech/music classifier - LF/to total energy ratio Q15 */ +#endif int16_t relE_attack_cnt; +#ifndef IVAS_FLOAT_FIXED float prev_relE; - Word16 prev_relE_fx; float prev_Etot; - Word16 prev_Etot_fx; +#else + Word16 prev_relE_fx; /* Q8 */ + Word16 prev_Etot_fx; /* Q8 */ +#endif int16_t prev_vad; int16_t vad_0_1_cnt; +#ifndef IVAS_FLOAT_FIXED float relE_attack_sum; - Word16 relE_attack_sum_fx; +#else + Word16 relE_attack_sum_fx; /* Q8 */ +#endif /* speech/music classifier improvement parameters */ +#ifndef IVAS_FLOAT_FIXED float old_Bin_E[3 * N_OLD_BIN_E]; float buf_flux[BUF_LEN]; float buf_pkh[BUF_LEN]; @@ -945,101 +958,131 @@ typedef struct sp_mus_clas_structure float buf_Ntonal2[BUF_LEN]; float buf_Ntonal_lf[BUF_LEN]; float buf_dlp[10]; - Word16 old_Bin_E_fx[3 * N_OLD_BIN_E]; - Word16 buf_flux_fx[BUF_LEN]; - Word16 buf_pkh_fx[BUF_LEN]; - Word16 buf_epsP_tilt_fx[BUF_LEN]; - Word16 buf_cor_map_sum_fx[BUF_LEN]; - Word16 buf_Ntonal_fx[BUF_LEN]; - Word16 buf_Ntonal2_fx[BUF_LEN]; - Word16 buf_Ntonal_lf_fx[BUF_LEN]; - Word16 buf_dlp_fx[10]; +#else + Word16 old_Bin_E_fx[3 * N_OLD_BIN_E]; /* Q7 */ + Word16 buf_flux_fx[BUF_LEN]; /* Q7 */ + Word16 buf_pkh_fx[BUF_LEN]; /* Q1 */ + Word16 buf_epsP_tilt_fx[BUF_LEN]; /* Q15 */ + Word16 buf_cor_map_sum_fx[BUF_LEN]; /* Q8 */ + Word16 buf_Ntonal_fx[BUF_LEN]; /* Q0 */ + Word16 buf_Ntonal2_fx[BUF_LEN]; /* Q0 */ + Word16 buf_Ntonal_lf_fx[BUF_LEN]; /* Q0 */ + Word16 buf_dlp_fx[10]; /* Q9 */ +#endif int16_t onset_cnt; +#ifndef IVAS_FLOAT_FIXED float buf_etot[4]; - Word16 buf_etot_fx[4]; +#else + Word16 buf_etot_fx[4]; /* Q8 */ +#endif int16_t attack_hangover; +#ifndef IVAS_FLOAT_FIXED float dec_mov; float dec_mov1; float mov_log_max_spl; float old_lt_diff[2]; - Word16 dec_mov_fx; - Word16 dec_mov1_fx; - Word16 mov_log_max_spl_fx; - Word16 old_lt_diff_fx[2]; +#else + Word16 dec_mov_fx; /* Q15 */ + Word16 dec_mov1_fx; /* Q15 */ + Word16 mov_log_max_spl_fx; /* Q7 */ + Word16 old_lt_diff_fx[2]; /* Q7 */ +#endif int16_t UV_cnt1; +#ifndef IVAS_FLOAT_FIXED float LT_UV_cnt1; - Word16 LT_UV_cnt1_fx; - - float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ - float lt_finc; /* strong attack detection - long-term finc energy */ - Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (Q_new * 2) */ - Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, (Q_new * 2) */ - int16_t last_strong_attack; /* strong attack detection - last strong attack flag */ - float tod_lt_Bin_E[TOD_NSPEC]; /* tonal detector - long-term energy spectrum */ +#else + Word16 LT_UV_cnt1_fx; /* Q6 */ +#endif + + float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ + float lt_finc; /* strong attack detection - long-term finc energy */ + Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (Q_new * 2) */ + Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, (Q_new * 2) */ + int16_t last_strong_attack; /* strong attack detection - last strong attack flag */ + float tod_lt_Bin_E[TOD_NSPEC]; /* tonal detector - long-term energy spectrum */ + Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_new + Q_SCALE - 2 */ +#ifndef IVAS_FLOAT_FIXED float tod_S_map_lt[TOD_NSPEC]; /* tonal detector - long-term correlation map */ float tod_thr_lt; /* tonal detector - adaptive threshold */ float tod_weight; /* tonal detector - adaptive weight */ float tod_S_mass_prev; float tod_S_mass_lt; - Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_new + Q_SCALE - 2 */ - Word32 tod_S_map_lt_fx[TOD_NSPEC]; /* tonal detector - long-term correlation map, Q22 */ - Word32 tod_thr_lt_fx; /* tonal detector - adaptive threshold, Q22 */ - Word16 tod_weight_fx; /* tonal detector - adaptive weight, Q15 */ - Word32 tod_S_mass_prev_fx; /* Q22 */ - Word32 tod_S_mass_lt_fx; /* Q22 */ +#else + Word32 tod_S_map_lt_fx[TOD_NSPEC]; /* tonal detector - long-term correlation map, Q22 */ + Word32 tod_thr_lt_fx; /* tonal detector - adaptive threshold, Q22 */ + Word16 tod_weight_fx; /* tonal detector - adaptive weight, Q15 */ + Word32 tod_S_mass_prev_fx; /* Q22 */ + Word32 tod_S_mass_lt_fx; /* Q22 */ +#endif int16_t lt_music_hangover; +#ifndef IVAS_FLOAT_FIXED float tonality2_buf[HANG_LEN_INIT]; float tonality3_buf[HANG_LEN_INIT]; float LPCErr_buf[HANG_LEN_INIT]; - Word16 tonality2_buf_fx[HANG_LEN_INIT]; - Word16 tonality3_buf_fx[HANG_LEN_INIT]; - Word16 LPCErr_buf_fx[HANG_LEN_INIT]; +#else + Word16 tonality2_buf_fx[HANG_LEN_INIT]; /* Q14 */ + Word16 tonality3_buf_fx[HANG_LEN_INIT]; /* Q14 */ + Word16 LPCErr_buf_fx[HANG_LEN_INIT]; /* Q10 */ +#endif int16_t lt_music_state; int16_t lt_speech_state; int16_t lt_speech_hangover; +#ifndef IVAS_FLOAT_FIXED float lpe_buf[HANG_LEN_INIT]; float voicing_buf[HANG_LEN_INIT]; - Word16 lpe_buf_fx[HANG_LEN_INIT]; - Word16 voicing_buf_fx[HANG_LEN_INIT]; +#else + Word16 lpe_buf_fx[HANG_LEN_INIT]; /* Q10 */ + Word16 voicing_buf_fx[HANG_LEN_INIT]; /* Q13 */ +#endif int16_t gsc_hangover; +#ifndef IVAS_FLOAT_FIXED float sparse_buf[HANG_LEN_INIT]; float hf_spar_buf[HANG_LEN_INIT]; float LT_sparse; +#else Word16 sparse_buf_fx[HANG_LEN_INIT]; - Word16 hf_spar_buf_fx[HANG_LEN_INIT]; - Word16 LT_sparse_fx; + Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ + Word16 LT_sparse_fx; /* Q8 */ +#endif int16_t gsc_cnt; /* speech/music classification */ int16_t last_vad_spa; int16_t lt_old_mode[3]; +#ifndef IVAS_FLOAT_FIXED float lt_voicing_flt; float lt_corr_flt; float lt_tonality_flt; - Word16 lt_voicing; - Word16 lt_corr; - Word32 lt_tonality; +#else + Word16 lt_voicing; /* Q15 */ + Word16 lt_corr; /* Q15 */ + Word32 lt_tonality; /* Q15 */ +#endif int16_t lt_corr_pitch[3]; int16_t lt_hangover; float lowrate_pitchGain_flt; - Word16 lowrate_pitchGain; + Word16 lowrate_pitchGain; /* Q14 */ #ifndef IVAS_FLOAT_FIXED float tdm_lt_Etot; -#endif - Word16 tdm_lt_Etot_fx; // Q8 float var_cor_t[VAR_COR_LEN]; - Word16 var_cor_t_fx[VAR_COR_LEN]; +#else + Word16 tdm_lt_Etot_fx; /* Q8 */ + Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ +#endif int16_t high_stable_cor; float lps; float lpm; Word16 lps_fx; Word16 lpm_fx; - Word16 lpn_fx; - +#ifndef IVAS_FLOAT_FIXED float lpn; +#else + Word16 lpn_fx; /* Q7 */ +#endif + } SP_MUS_CLAS_DATA, *SP_MUS_CLAS_HANDLE; @@ -1298,8 +1341,8 @@ typedef struct sc_vbr_enc_structure float sum_of_rates; /* sum of the rates of past 600 active frames */ float global_avr_rate; /* global rate up to current time. recorded a (rate in kbps) * 6000 */ #else - Word32 sum_of_rates_fx; /*Q=13 sum of the rates of past 600 active frames*/ - Word32 global_avr_rate_fx; /*Q=13 global rate upto current time. recorded a (rate in kbps) *6000*/ + Word32 sum_of_rates_fx; /*Q=13 sum of the rates of past 600 active frames*/ + Word32 global_avr_rate_fx; /*Q=13 global rate upto current time. recorded a (rate in kbps) *6000*/ #endif int16_t global_frame_cnt; /* 600 active frame block count. Used to update the global rate */ int16_t set_ppp_generic; diff --git a/lib_enc/transient_detection.c b/lib_enc/transient_detection.c index fd80f29e6041569cef1a582400d9a675fb2c9934..eeeadfb1a45b319a22bcc1fbea8cca2d9224bb10 100644 --- a/lib_enc/transient_detection.c +++ b/lib_enc/transient_detection.c @@ -900,6 +900,7 @@ void set_transient_stereo( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED /*! r: preliminary flag to force ACELP */ int16_t transient_analysis( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ @@ -989,3 +990,4 @@ int16_t transient_analysis( return prel_force_td != 0; } +#endif diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 559255b426a259db3e9421ba35b7e45f989101d2..7000b6fbee742e411a4fcc5cbfac013726264b9a 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -51,6 +51,10 @@ static void UpdateSubblockEnergies( Word16 const *input, Word16 nSamplesAvailabl static void CalculateSubblockEnergies( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void RunTransientDetector( TransientDetector *pTransientDetector ); +static void CalculateSubblockEnergies_ivas_fx( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); + +static void UpdateSubblockEnergies_ivas_fx( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); + /************************************************/ /* */ /* Functions that define transient detectors */ @@ -535,7 +539,7 @@ void RunTransientDetection_fx( Word16 const *input, Word16 nSamplesAvailable, Tr #ifdef IVAS_FLOAT_FIXED void RunTransientDetection_ivas_fx( - const Word16 *input_fx, /* i : input signal Q0 */ + const Word16 *input_fx, /* i : input signal Q: -1 */ const Word16 length, /* i : frame length */ TRAN_DET_HANDLE hTranDet /* i/o: transient detection handle */ ) @@ -552,8 +556,16 @@ void RunTransientDetection_ivas_fx( /* Variable initializations */ HighPassFilter( input_fx, length, &pSubblockEnergies->firState1, &pSubblockEnergies->firState2, filteredInput_fx ); + /* Update subblock energies. */ - UpdateSubblockEnergies( filteredInput_fx, length, pSubblockEnergies ); + Scale_sig( filteredInput_fx, L_FRAME_MAX, 8 ); + Scale_sig32( pSubblockEnergies->subblockNrg, NSUBBLOCKS + MAX_TD_DELAY, 3 ); + Scale_sig32( pSubblockEnergies->accSubblockNrg, NSUBBLOCKS + MAX_TD_DELAY + 1, 3 ); + Scale_sig( pSubblockEnergies->subblockNrgChange, NSUBBLOCKS + MAX_TD_DELAY, 3 ); + UpdateSubblockEnergies_ivas_fx( filteredInput_fx, length, pSubblockEnergies ); + Scale_sig32( pSubblockEnergies->subblockNrg, NSUBBLOCKS + MAX_TD_DELAY, -3 ); + Scale_sig32( pSubblockEnergies->accSubblockNrg, NSUBBLOCKS + MAX_TD_DELAY + 1, -3 ); + Scale_sig( pSubblockEnergies->subblockNrgChange, NSUBBLOCKS + MAX_TD_DELAY, -3 ); /* Run transient detectors. */ RunTransientDetector( pTransientDetector ); @@ -1066,6 +1078,31 @@ static void UpdateSubblockEnergies( Word16 const *input, Word16 nSamplesAvailabl CalculateSubblockEnergies( input, nSamplesAvailable, pSubblockEnergies ); } +static void UpdateSubblockEnergies_ivas_fx( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ) +{ + Word16 i; + + + assert( ( pSubblockEnergies->nDelay >= 0 ) && ( pSubblockEnergies->nDelay + NSUBBLOCKS <= (int) sizeof( pSubblockEnergies->subblockNrg ) / (int) sizeof( pSubblockEnergies->subblockNrg[0] ) ) ); + assert( pSubblockEnergies->nPartialDelay <= pSubblockEnergies->pDelayBuffer->nDelay ); + /* At least one block delay is required when subblock energy change is required */ + assert( pSubblockEnergies->nDelay >= 1 ); + + /* Shift old subblock energies */ + FOR( i = 0; i < pSubblockEnergies->nDelay; i++ ) + { + move32(); + move32(); + move16(); + pSubblockEnergies->subblockNrg[i] = pSubblockEnergies->subblockNrg[i + NSUBBLOCKS]; + pSubblockEnergies->accSubblockNrg[i] = pSubblockEnergies->accSubblockNrg[i + NSUBBLOCKS]; + pSubblockEnergies->subblockNrgChange[i] = pSubblockEnergies->subblockNrgChange[i + NSUBBLOCKS]; + } + + /* Compute filtered subblock energies for the new samples */ + CalculateSubblockEnergies_ivas_fx( input, nSamplesAvailable, pSubblockEnergies ); +} + /* This function should be inlined and WMOPS instrumentation takes that into account, meaning that all references are considered as local variables */ static void UpdatedAndStoreAccWindowNrg( Word32 newWindowNrgF, Word32 *pAccSubblockNrg, Word16 facAccSubblockNrg, Word32 *pOutAccWindowNrgF ) { @@ -1203,6 +1240,128 @@ static void CalculateSubblockEnergies( Word16 const *input, Word16 nSamplesAvail pSubblockEnergies->firState1 = firState1; pSubblockEnergies->firState2 = firState2; } + +static void CalculateSubblockEnergies_ivas_fx( Word16 const *input, Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ) +{ + DelayBuffer *pDelayBuffer; + Word16 nSubblockSize; + Word16 nDelay; + Word16 nPartialDelay; + Word16 *delayBuffer; + Word16 facAccSubblockNrg; + Word32 *pSubblockNrg; + Word32 *pAccSubblockNrg; + Word16 *pSubblockNrgChange; + Word32 *pAccSubblockTmp; + Word16 nWindows; + Word16 w, k, k2, tmp; + Word16 firState1, firState2; + Word32 w0, w1; + Word32 accu; + + move16(); + pDelayBuffer = pSubblockEnergies->pDelayBuffer; + facAccSubblockNrg = pSubblockEnergies->facAccSubblockNrg; + + move16(); + move16(); + move16(); + nSubblockSize = pDelayBuffer->nSubblockSize; + nDelay = pSubblockEnergies->nDelay; + nPartialDelay = pSubblockEnergies->nPartialDelay; + + delayBuffer = &pDelayBuffer->buffer[sub( pDelayBuffer->nDelay, nPartialDelay )]; + pSubblockNrg = &pSubblockEnergies->subblockNrg[nDelay]; + pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nDelay]; + pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nDelay]; + + move16(); + move16(); + /* nWindows = (nSamplesAvailable + nPartialDelay) / nSubblockSize */ + nWindows = shr( div_s( add( nSamplesAvailable, nPartialDelay ), shl( nSubblockSize, 7 ) ), 8 ); + firState1 = pSubblockEnergies->firState1; + firState2 = pSubblockEnergies->firState2; + pAccSubblockTmp = &pAccSubblockNrg[nWindows]; + + IF( nWindows > 0 ) + { + /* Process left over samples from the previous frame. */ + accu = L_add( 109568, 0 ); // 107 in Q10 + assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); + FOR( k = 0; k < nPartialDelay; k++ ) + { + tmp = shr( delayBuffer[k], SUBBLOCK_NRG_E / 2 ); + accu = L_mac0( accu, tmp, tmp ); + } + + /* Process new samples in the 0. subblock. */ + w = sub( nSubblockSize, nPartialDelay ); + assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); + FOR( k = 0; k < w; k++ ) + { + tmp = shr( input[k], SUBBLOCK_NRG_E / 2 ); +#ifdef BASOP_NOGLOB + accu = L_mac0_sat( accu, tmp, tmp ); +#else + accu = L_mac0( accu, tmp, tmp ); +#endif + } + + move32(); + pSubblockNrg[0] = accu; // Q10 + /* Set accumulated subblock energy at this point. */ + UpdatedAndStoreAccWindowNrg( pSubblockNrg[0], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[0] ); + + FOR( w = 1; w < nWindows; w++ ) + { + accu = L_add( 109568, 0 ); // 107 in Q10 + /* Process new samples in the w. subblock. */ + k2 = add( k, nSubblockSize ); + assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); + FOR( ; k < k2; k++ ) + { + tmp = shr( input[k], SUBBLOCK_NRG_E / 2 ); +#ifdef BASOP_NOGLOB + accu = L_mac0_sat( accu, tmp, tmp ); +#else + accu = L_mac0( accu, tmp, tmp ); +#endif + } + move32(); + pSubblockNrg[w] = accu; + /* Set accumulated subblock energy at this point. */ + UpdatedAndStoreAccWindowNrg( pSubblockNrg[w], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[w] ); + } + + /* Calculate energy change for each block. */ + FOR( w = 0; w < nWindows; w++ ) + { + w0 = L_add( pSubblockNrg[w], 0 ); + w1 = L_add( pSubblockNrg[sub( w, 1 )], 0 ); + + IF( GT_32( w0, w1 ) ) + { + k2 = BASOP_Util_Divide3232_uu_1616_Scale( w0, w1, &k ); + } + ELSE + { + k2 = BASOP_Util_Divide3232_uu_1616_Scale( w1, w0, &k ); + } + move16(); + pSubblockNrgChange[w] = MAX_16; + IF( LT_16( k, 5 ) ) + { + move16(); + pSubblockNrgChange[w] = shr( k2, sub( 5, k ) ); + } + } + } + + move16(); + move16(); + pSubblockEnergies->firState1 = firState1; + pSubblockEnergies->firState2 = firState2; +} #ifdef IVAS_CODE /*-------------------------------------------------------------------* * set_transient_stereo() diff --git a/lib_enc/updt_enc.c b/lib_enc/updt_enc.c index bf7a5bc7a801ccd1b90459133cbc06c06c954306..ded37c0a8bc2fdb74b088dac64565eb227832943 100644 --- a/lib_enc/updt_enc.c +++ b/lib_enc/updt_enc.c @@ -151,168 +151,13 @@ void updt_enc( return; } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * updt_IO_switch() * * Common updates for AMR-WB IO mode and EVS primary mode switching *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void updt_IO_switch_enc( - Encoder_State *st, /* i/o: state structure */ - const int16_t input_frame /* i : input frame length */ -) -{ - float xsp_tmp[M]; - - if ( st->last_core == AMR_WB_CORE ) /* switching to EVS primary mode */ - { - /* reset onset detection counter */ - st->tc_cnt = -1; - - /* force safety-net LSFQ in the first frames after the switching */ - st->Nb_ACELP_frames = 0; - - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ - mvr2r( stable_LSP, xsp_tmp, M ); - isf2lsf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 ); - mvr2r( stable_LSP, xsp_tmp, M ); - isp2lsp( st->lsp_old, st->lsp_old, xsp_tmp, M ); - isp2lsp( st->lsp_old1, st->lsp_old1, xsp_tmp, M ); - - mvr2r( stable_LSP, xsp_tmp, M ); - isp2lsp( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG, xsp_tmp, M ); - if ( st->hTdCngEnc->old_enr_index >= 0 ) - { - st->hTdCngEnc->old_enr_index = min( (int16_t) ( (float) st->hTdCngEnc->old_enr_index / STEP_AMR_WB_SID * STEP_SID ), 127 ); - } - /* Perform preemphasis of the old input signal @16kHz */ - st->mem_preemph16k = 0; - preemph( st->old_inp_16k, PREEMPH_FAC_16k_FLT, L_INP_MEM, &( st->mem_preemph16k ) ); - - /* reset TD BWE buffers */ - set_f( st->hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); - set_f( st->hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); - set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); -#ifdef IVAS_FLOAT_FIXED - InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* To be removed*/ - InitSWBencBufferStates( st->hBWE_TD, NULL ); -#endif -#else - InitSWBencBufferStates( st->hBWE_TD, NULL ); -#endif - - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; - set_f( st->hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( st->hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( st->hBWE_FD->old_wtda_swb, 0, L_FRAME16k ); - set_f( st->hBWE_FD->old_input_wb, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); -#ifdef IVAS_FLOAT_FIXED - wb_tbe_extras_reset_fx( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( st->hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#endif -#else - wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 ); -#endif - if ( input_frame >= L_FRAME32k ) - { -#ifdef IVAS_FLOAT_FIXED - swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); -#endif -#else - swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); -#endif - } - - if ( input_frame == L_FRAME48k ) - { - set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); - st->hBWE_TD->fb_tbe_demph = 0; -#ifdef IVAS_FLOAT_FIXED - fb_tbe_reset_enc_fx( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx, &st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &st->hBWE_TD->prev_fb_energy_fx_Q ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fb_tbe_reset_enc( st->hBWE_TD->elliptic_bpf_2_48k_mem, &st->hBWE_TD->prev_fb_energy ); -#endif -#else - fb_tbe_reset_enc( st->hBWE_TD->elliptic_bpf_2_48k_mem, &st->hBWE_TD->prev_fb_energy ); -#endif - } - - /* reset FD BWE buffers */ - st->hBWE_FD->prev_mode = NORMAL; - - /* reset the unvoiced/audio signal improvement memories */ - st->hGSCEnc->seed_tcx = 15687; - - st->use_acelp_preq = 0; - - set_f( st->hSpMusClas->finc_prev, 0.0f, ATT_NSEG ); - st->hSpMusClas->lt_finc = 0.0f; - st->hSpMusClas->last_strong_attack = 0; - set_f( st->hSpMusClas->tod_lt_Bin_E, 0.0f, TOD_NSPEC ); - set_f( st->hSpMusClas->tod_S_map_lt, 0.0f, TOD_NSPEC ); - st->hSpMusClas->tod_thr_lt = TOD_THR_MASS; - st->hSpMusClas->tod_weight = 0.0f; - st->hSpMusClas->tod_S_mass_prev = TOD_THR_MASS; - st->hSpMusClas->tod_S_mass_lt = TOD_THR_MASS; - } - else /* switching to AMR-WB IO mode */ - { - set_f( st->mem_MA, 0, M ); - - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ - mvr2r( stable_ISP, xsp_tmp, M ); - lsf2isf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 ); - mvr2r( stable_ISP, xsp_tmp, M ); - lsp2isp( st->lsp_old, st->lsp_old, xsp_tmp, M ); - mvr2r( st->lsp_old, st->lsp_old1, M ); - lsp2isp( st->lsp_old1, st->lsp_old1, xsp_tmp, M ); - mvr2r( stable_ISP, xsp_tmp, M ); - lsp2isp( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG, xsp_tmp, M ); - if ( st->hTdCngEnc->old_enr_index >= 0 ) - { - st->hTdCngEnc->old_enr_index = min( (int16_t) ( (float) st->hTdCngEnc->old_enr_index / STEP_SID * STEP_AMR_WB_SID ), 63 ); - } - - /* gain quantization memory */ - set_f( st->hAmrwb_IO->past_qua_en, -14.0f, GAIN_PRED_ORDER ); - - /* reset VBR signaling */ - if ( st->Opt_SC_VBR ) - { - st->hSC_VBR->ppp_mode = 0; - st->hSC_VBR->nelp_mode = 0; - } - /* reset the unvoiced/audio signal improvement memories */ - st->hGSCEnc->seed_tcx = 15687; - } - - if ( st->hTdCngEnc != NULL ) - { - /* Force SID in case of AMR-WB IO mode/EVS primary mode switching */ - st->hDtxEnc->cnt_SID = 0; - st->hDtxEnc->cng_cnt = 0; - st->hTdCngEnc->ho_hist_size = 0; - st->hTdCngEnc->burst_ho_cnt = 0; - } - - /* LP memories */ - mvr2r( UVWB_Ave, st->mem_AR, M ); - - /* FEC - update adaptive LSF mean vector */ - mvr2r( st->lsf_old, st->lsfoldbfi0, M ); - mvr2r( st->lsf_old, st->lsfoldbfi1, M ); - mvr2r( st->lsf_old, st->lsf_adaptive_mean, M ); - - return; -} -#else void updt_IO_switch_enc( Encoder_State *st, /* i/o: state structure */ const int16_t input_frame /* i : input frame length */