diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index b4ff332f5c299fb9f9b6a8a60e8476a955af89ee..788d2353bf65d7a56d17279612a15b9f40abd7bb 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2990,7 +2990,6 @@ Word16 ivas_acelp_tcx20_switching_fx( Word16 stab_fac, /* i : LP filter stability */ Word32 *res_cod_SNR_M, Word16 *res_cod_SNR_M_e, - Word16 *tcx_mdct_window_fx, const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 75bcaf1d696f59004402bb8344973130e9682eb5..b95ee921b1a98875abc7bfdba23178780d4ebbab 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3727,12 +3727,11 @@ void GenShapedSHBExcitation_ivas_fx( Word16 nbSubFr, lSubFr; Word16 tempQ15; Word32 tempQ31; - /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ nbSubFr = NB_SUBFR16k; lSubFr = ( L_FRAME16k / NB_SUBFR16k ); move16(); move16(); - IF( LT_32( bitrate, ACELP_24k40 ) ) + IF( LT_32( extl_brate, SWB_TBE_2k8 ) ) { nbSubFr = NB_SUBFR; move16(); @@ -3744,7 +3743,7 @@ void GenShapedSHBExcitation_ivas_fx( FOR( i = 0; i < nbSubFr; i++ ) { test(); - IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) + IF( EQ_16( coder_type, VOICED ) && ( LT_32( extl_brate, SWB_TBE_2k8 ) ) ) { exp = 0; move16(); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 1e8e45df7ebeb49cb70d4a6709d3c2937690ee78..6dc678b63e4f38c60b14ab71a616e84113ba1906 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -329,7 +329,7 @@ void InitTnsConfiguration_ivas_fx( FOR( iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++ ) { - assert( pTnsConfig->pTnsParameters[iFilter].startLineFrequency < 0.5f * nSampleRate ); + assert( pTnsConfig->pTnsParameters[iFilter].startLineFrequency < nSampleRate / 2 ); assert( nSampleRate <= 96000 ); move16(); startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); /*Q0*/ diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 4f5f6579b56ce24aa02e597fa5d4b8447103b520..acaf13a49ad8b3173bbb5bc365decb518e13ea24 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -609,7 +609,7 @@ void bass_psfilter_fx( } exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ /* gain = corr / ener */ - gain = div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ); + gain = div_s( round_fx_sat( L_shl( Ltmp, exp ) ), tmp2 ); if ( Lcorr < 0 ) { gain = sub( 0, gain ); diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index ab9697500ff495a5dcf0eb5b176e89e37b4335dc..1bfffd1021b97abe1617249d81fbda9afa805d03 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -81,26 +81,16 @@ ivas_error acelp_core_enc( Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ Word16 Q_new ) { - Word16 i, nBits; /* reserved bits */ - LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ - float old_exc_flt[L_EXC] = { 0 }, *exc; /* excitation signal buffer */ - float syn[L_FRAME16k] = { 0 }; /* synthesis signal buffer */ - float res[L_FRAME16k] = { 0 }; /* Residual signal for FER protection */ // IVAS_FLOAT_FIXED_CONVERSIONS - float exc2[L_FRAME16k]; /* enhanced excitation */ - Word16 tc_subfr; /* TC sub-frame indication */ + Word16 i, nBits; /* reserved bits */ + LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ + Word16 tc_subfr; /* TC sub-frame indication */ Word16 allow_cn_step; Word32 int_fs; Word16 nb_bits; /* parameters handling */ /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ Word16 pstreaklen; - float mem_syn_bck[M]; - - float q_env[NUM_ENV_CNG]; Word16 sid_bw = -1; - float exc3[L_FRAME16k]; - float syn1[L_FRAME16k]; - Word16 next_force_sf_bck; Word16 uc_two_stage_flag; Word16 position; @@ -109,7 +99,6 @@ ivas_error acelp_core_enc( /* bitstream */ BSTR_ENC_HANDLE hBstr = st->hBstr; -#if 1 Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ Word16 Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ @@ -133,9 +122,7 @@ ivas_error acelp_core_enc( Word16 tilt_code_bck_fx; Word32 gc_threshold_bck_fx; Word16 clip_var_bck_fx[6]; - // Word16 next_force_sf_bck_fx; Word32 q_env_fx[NUM_ENV_CNG]; - // Word16 coder_type; #ifdef MSAN_FIX set32_fx( q_env_fx, 0, NUM_ENV_CNG ); #endif @@ -145,7 +132,7 @@ ivas_error acelp_core_enc( Word16 att_fx; Word16 tmpF_fx; -#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 inp_buff[L_FRAME16k + M + 1]; Word16 *inp_fx; @@ -155,12 +142,21 @@ ivas_error acelp_core_enc( IF( st->hLPDmem ) { - floatToFixed_arr( &st->hLPDmem->old_exc_flt[-M - 1], &st->hLPDmem->old_exc[-M - 1], Q_new, L_EXC_MEM + M + 1 ); - floatToFixed_arr( st->hLPDmem->mem_syn_flt, st->hLPDmem->mem_syn, Q_new - 1, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn1_flt, st->hLPDmem->mem_syn1_fx, Q_new - 1, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn2_flt, st->hLPDmem->mem_syn2, Q_new - 1, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn3_flt, st->hLPDmem->mem_syn3, Q_new - 1, 16 ); - floatToFixed_arr( st->hLPDmem->mem_syn_r_flt, st->hLPDmem->mem_syn_r, Q_new - 1, 60 ); + Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); + st->hLPDmem->q_lpd_old_exc = Q_new; + move16(); + Scale_sig( st->hLPDmem->syn, M + 1, sub( Q_new, st->hLPDmem->q_lpd_syn ) ); + st->hLPDmem->q_lpd_syn = Q_new; + move16(); + Scale_sig( st->hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + move16(); + st->hLPDmem->q_mem_syn = sub( Q_new, 1 ); + move16(); } IF( st->hBWE_TD ) { @@ -192,12 +188,9 @@ ivas_error acelp_core_enc( Es_pred_fx = 0; move16(); - exc = old_exc_flt + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - mvr2r( hLPDmem->old_exc_flt, old_exc_flt, L_EXC_MEM ); - exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); - + Scale_sig( old_exc_fx, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); IF( st->hBWE_TD != NULL ) { bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ @@ -365,18 +358,15 @@ ivas_error acelp_core_enc( /* update Aw[] coefficients */ weight_a_subfr_fx( shr( st->L_frame, 6 ), A, Aw, st->gamma, M ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( st->hLPDmem ) { - fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, Q_new - 1, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn1_fx, st->hLPDmem->mem_syn1_flt, Q_new - 1, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn2, st->hLPDmem->mem_syn2_flt, Q_new - 1, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn3, st->hLPDmem->mem_syn3_flt, Q_new - 1, 16 ); - fixedToFloat_arr( st->hLPDmem->mem_syn_r, st->hLPDmem->mem_syn_r_flt, Q_new - 1, 60 ); + st->hLPDmem->q_mem_syn = sub( Q_new, 1 ); + move16(); + st->hLPDmem->q_lpd_old_exc = Q_new; + move16(); + st->hLPDmem->q_lpd_syn = Q_new; + move16(); } - fixedToFloat_arr( &st->hLPDmem->old_exc[-M - 1], &st->hLPDmem->old_exc_flt[-M - 1], Q_new, L_EXC_MEM + M + 1 ); - fixedToFloat_arr( old_exc_fx, old_exc_flt, Q_new, L_EXC_MEM ); -#endif test(); test(); @@ -390,29 +380,16 @@ ivas_error acelp_core_enc( * Encoding of CNG frames *----------------------------------------------------------------*/ - if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { if ( st->cng_type == LP_CNG ) { /* Run CNG post parameter update */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) - { - f2me_buf_16( &st->hTdCngEnc->cng_exc2_buf_flt[ii * L_FFT], &st->hTdCngEnc->cng_exc2_buf[ii * L_FFT], &st->hTdCngEnc->cng_Qexc_buf[ii], L_FFT ); - st->hTdCngEnc->cng_Qexc_buf[ii] = Q15 - st->hTdCngEnc->cng_Qexc_buf[ii]; - } -#endif + cng_params_postupd_ivas_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); /* encode CNG parameters */ CNG_enc_ivas_fx( st, Aq, inp_fx, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); -#endif -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr32( q_env, q_env_fx, Q6, NUM_ENV_CNG ); #endif /* comfort noise generation */ @@ -420,15 +397,11 @@ ivas_error acelp_core_enc( &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho, q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arr( exc_fx, exc, Q_new - 1, st->L_frame ); - fixedToFloat_arr( exc2_fx, exc2, Q_new - 1, st->L_frame ); - fixedToFloat_arr( exc3_fx, exc3, Q_new - 1, st->L_frame ); -#endif + Scale_sig( exc_fx, st->L_frame, 1 ); } - else + ELSE { + test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { FdCng_encodeSID_ivas_fx( st ); @@ -456,9 +429,6 @@ ivas_error acelp_core_enc( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, Q_cngNoise ); move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); -#endif generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -467,22 +437,13 @@ ivas_error acelp_core_enc( Scale_sig( st->hFdCngEnc->hFdCngCom->A_cng, ( M + 1 ), sub( Q12, sub( 14, norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ) ) ) ); FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq, lsp_new, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( exc_fx, exc, Q_new, st->L_frame ); - fixedToFloat_arr( exc2_fx, exc2, Q_new, st->L_frame ); -#endif - - mvr2r( exc2, exc3, st->L_frame ); + Copy( exc2_fx, exc3_fx, st->L_frame ); if ( st->core_brate == SID_2k40 ) { if ( st->hTdCngEnc != NULL ) { Word16 enr, enr_index; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Word16 Q_exc_l = Q_factor_arr( exc, st->L_frame ); - floatToFixed_arr( exc, exc_fx, Q_new, st->L_frame ); -#endif enr = cng_energy_ivas_fx( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att_fx, exc_fx, st->L_frame, Q_new ); /* calculate the energy quantization index */ @@ -502,73 +463,57 @@ ivas_error acelp_core_enc( if ( st->hTdCngEnc != NULL ) { st->hTdCngEnc->burst_ho_cnt = 0; + move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_exc_l; - - Q_exc_l = Q_factor_arr( exc3, st->L_frame ); - floatToFixed_arr( exc3, exc3_fx, Q_exc_l, st->L_frame ); + Scale_sig( st->hLPDmem->mem_syn, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn2, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn3, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); + st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); + move16(); + st->hLPDmem->q_mem_syn = st->Q_syn; + move16(); - floatToFixed_arr( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn3, st->Q_syn, M ); -#endif /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_exc_l, st->Q_syn ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( exc3_fx, exc, Q_exc_l, st->L_frame ); - fixedToFloat_arr( hLPDmem->mem_syn3, hLPDmem->mem_syn3_flt, st->Q_syn, M ); - fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); -#endif + syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_new - 1, st->Q_syn ); /* reset the encoder */ CNG_reset_enc_fx( st, hLPDmem, pitch_buf, voice_factors_fx, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hLPDmem->mem_w0_flt = 0.0f; -#endif - /* update st->mem_syn1_flt for ACELP core switching */ - mvr2r( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn1_flt, M ); + Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); /* update ACELP core synthesis filter memory */ - mvr2r( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn_flt, M ); + Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - mvr2r( syn1 + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + Copy( syn1_fx + add( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); /* save and delay synthesis to be used by SWB BWE */ if ( st->hBWE_FD != NULL ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->hBWE_FD->mem_deemph_old_syn_fx = float_to_fix16_thrld( st->hBWE_FD->mem_deemph_old_syn, st->Q_syn ); - floatToFixed_arr( syn1, syn1_fx, st->Q_syn, st->L_frame ); floatToFixed_arr( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->Q_syn, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); *q_old_syn_12k8_16 = st->Q_syn; move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); st->hBWE_FD->mem_deemph_old_syn = fix16_to_float( st->hBWE_FD->mem_deemph_old_syn_fx, st->Q_syn ); fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, st->Q_syn, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); #endif } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( syn1, syn1_fx, st->Q_syn, st->L_frame ); - floatToFixed_arr( hLPDmem->syn_flt, hLPDmem->syn, st->Q_syn, ( M + 1 ) ); - st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); -#endif + Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); + st->hLPDmem->q_lpd_syn = st->Q_syn; + move16(); + /*Update MODE2 core switching memory*/ deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); - fixedToFloat_arr( hLPDmem->syn, hLPDmem->syn_flt, st->Q_syn, ( M + 1 ) ); -#endif - mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + Copy( syn1_fx + st->L_frame - M - 1, hLPDmem->syn, M + 1 ); } /*----------------------------------------------------------------* @@ -579,15 +524,6 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->mem_deemp_preQ_fx = (Word16) floatToFixed( st->mem_deemp_preQ, -1 ); - IF( st->hLPDmem ) - { - floatToFixed_arr( &st->hLPDmem->mem_syn_flt[-1], &st->hLPDmem->mem_syn[-1], Q_new - 1, M + 1 ); // -1 to sync the exponent of mem_syn with mem_w0 - } - floatToFixed_arr( &hLPDmem->old_exc_flt[-M - 1], &hLPDmem->old_exc[-M - 1], Q_new, L_EXC_MEM + M + 1 ); - floatToFixed_arr( old_exc_flt, old_exc_fx, Q_new, st->L_frame ); - - st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); - f2me_buf_16( st->hGSCEnc->last_exc_dct_in, st->hGSCEnc->last_exc_dct_in_fx, &st->hGSCEnc->Q_last_exc_dct_in, L_FRAME16k ); st->hGSCEnc->Q_last_exc_dct_in = Q15 - st->hGSCEnc->Q_last_exc_dct_in; #endif @@ -810,7 +746,6 @@ ivas_error acelp_core_enc( lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new ); /* recalculation of LP residual (filtering through A[z] filter) */ - // calc_residu( inp, res, Aq, st->L_frame ); calc_residu_fx( st, inp_fx, res_fx, Aq ); st->hTdCngEnc->burst_ho_cnt = 0; @@ -835,72 +770,58 @@ ivas_error acelp_core_enc( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->mem_deemp_preQ = fixedToFloat( st->mem_deemp_preQ_fx, -1 ); - fixedToFloat_arr( mem_syn_bck_fx, mem_syn_bck, Q_new, M ); fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); - fixedToFloat_arr( old_exc_fx, old_exc_flt, Q_new, st->L_frame ); - fixedToFloat_arr( &hLPDmem->old_exc[-M - 1], &hLPDmem->old_exc_flt[-M - 1], Q_new, L_EXC_MEM + M + 1 ); - fixedToFloat_arr( res_fx, res, Q_new, st->L_frame ); - - fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, Q_new - 1, M ); - st->hLPDmem->mem_w0_flt = fixedToFloat( st->hLPDmem->mem_w0, Q_new - 1 ); - fixedToFloat_arr( exc_fx, exc, Q_new, L_FRAME16k + 1 ); - fixedToFloat_arr( exc2_fx, exc2, Q_new, L_FRAME16k ); me2f_buf_16( st->hGSCEnc->last_exc_dct_in_fx, Q15 - st->hGSCEnc->Q_last_exc_dct_in, st->hGSCEnc->last_exc_dct_in, L_FRAME16k ); - fixedToFloat_arr( syn_fx, syn, Q_new - 1, L_FRAME16k ); #endif /* update mem_syn1_flt for ACELP core switching */ - mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); + Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - mvr2r( syn + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + Copy( syn_fx + add( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); + Scale_sig( syn_fx, L_FRAME16k, sub( st->Q_syn, Q_new - 1 ) ); /* save and delay synthesis to be used by SWB BWE */ if ( st->hBWE_FD != NULL ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 old_syn_12k8_16k_fx[L_FRAME16k]; - Word16 Q_syn_l = Q_factor_arr( syn, st->L_frame ); + Word16 Q_syn_l = st->Q_syn; Word16 Q_old_syn_l = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); Q_syn_l = min( Q_syn_l, Q_old_syn_l ); Word16 Q_deemph_l = Q_factor( st->hBWE_FD->mem_deemph_old_syn ); Q_syn_l = min( Q_syn_l, Q_deemph_l ); // Q_syn_l = sub( Q_syn_l, 1 ); st->hBWE_FD->mem_deemph_old_syn_fx = float_to_fix16_thrld( st->hBWE_FD->mem_deemph_old_syn, Q_syn_l ); - floatToFixed_arr( syn, syn_fx, Q_syn_l, st->L_frame ); floatToFixed_arr( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_syn_l, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); *q_old_syn_12k8_16 = Q_syn_l; + Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, Q_syn_l ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( syn_fx, syn, Q_syn_l, st->L_frame ); st->hBWE_FD->mem_deemph_old_syn = fix16_to_float( st->hBWE_FD->mem_deemph_old_syn_fx, Q_syn_l ); fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_syn_l, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); #endif } /*Update MODE2 core switching memory*/ - mvr2r( syn, syn1, st->L_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( syn1, syn1_fx, st->Q_syn, st->L_frame ); - floatToFixed_arr( hLPDmem->syn_flt, hLPDmem->syn, st->Q_syn, ( M + 1 ) ); - st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); -#endif + Copy( syn_fx, syn1_fx, st->L_frame ); + + Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); + st->hLPDmem->q_lpd_syn = st->Q_syn; + move16(); + /*Update MODE2 core switching memory*/ deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); - // deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( syn1_fx, syn1, st->Q_syn, st->L_frame ); - fixedToFloat_arr( hLPDmem->syn, hLPDmem->syn_flt, st->Q_syn, ( M + 1 ) ); -#endif - mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); - if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + Copy( syn1_fx + st->L_frame - M - 1, hLPDmem->syn, M + 1 ); + + test(); + IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { - mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + // mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + fixedToFloat_arr( syn1_fx + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->Q_syn, st->L_frame / 2 ); } /*--------------------------------------------------------------------------------------* @@ -910,38 +831,22 @@ ivas_error acelp_core_enc( if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) { /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ - mvr2r( exc, exc2, st->L_frame ); -#ifndef IVAS_FLOAT_FIXED - stat_noise_uv_enc( st, epsP, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from float to fix - Word16 Q_exc2 = Q_factor_arr( exc2, L_FRAME ); - floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME ); -#endif - stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_exc2 ); + Copy( exc_fx, exc2_fx, st->L_frame ); + + stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new ); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from fix to float - fixedToFloat_arr( exc2_fx, exc2, Q_exc2, L_FRAME16k ); st->exc_pe = fix16_to_float( st->exc_pe_fx, st->Q_stat_noise ); -#endif #endif } /*-----------------------------------------------------------------* * Encode supplementary information for Frame Error Concealment *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_syn = Q_factor_arr( syn, L_FRAME ); - q_syn = min( q_syn, Q_factor_arr( res, L_FRAME16k ) ); - - floatToFixed_arr16( syn, syn_fx, q_syn, L_FRAME ); - floatToFixed_arr16( res, res_fx, q_syn, L_FRAME16k ); -#endif - FEC_encode_ivas_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, q_syn ); -#endif + Scale_sig( syn_fx, L_FRAME, sub( s_min( st->Q_syn, Q_new ), st->Q_syn ) ); + Scale_sig( res_fx, L_FRAME16k, sub( s_min( st->Q_syn, Q_new ), Q_new ) ); + FEC_encode_ivas_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, s_min( st->Q_syn, Q_new ) ); IF( st->hBWE_TD != NULL ) { IF( EQ_16( st->L_frame, L_FRAME ) ) @@ -991,7 +896,6 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); - // Q bwe_exc_extended_fx = 2 * Q bwe_exc_fx = 2 * q_bwe_exc Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc #endif // IVAS_FLOAT_FIXED } @@ -1007,8 +911,6 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( old_exc_flt, old_exc_fx, Q_new, L_EXC ); - IF( st->hBWE_TD != NULL ) { st->Q_exc = Q_new; @@ -1016,9 +918,8 @@ ivas_error acelp_core_enc( #endif // IVAS_FLOAT_FIXED_CONVERSIONS updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx ); - + st->hLPDmem->q_lpd_old_exc = Q_new; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, Q_new, L_EXC_MEM ); IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) { fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, Q_new, PIT16k_MAX * 2 ); @@ -1030,22 +931,23 @@ ivas_error acelp_core_enc( if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && st->core_brate > SID_2k40 ) { /* update CNG parameters in active frames */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_exc = Q_factor_arr( exc, L_EXC - L_EXC_MEM ); - q_exc = min( q_exc, Q_factor_arr( st->hTdCngEnc->cng_exc2_buf_flt, HO_HIST_SIZE * L_FFT ) ); - floatToFixed_arr16( exc, exc_fx, q_exc, L_EXC - L_EXC_MEM ); - floatToFixed_arr16( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, q_exc, HO_HIST_SIZE * L_FFT ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q_exc = st->hTdCngEnc->cng_Qexc_buf[0]; + FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) + { + q_exc = s_min( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ); + } + q_exc = s_min( q_exc, Q_new ); + + Scale_sig( exc_fx, L_EXC - L_EXC_MEM, sub( q_exc, Q_new ) ); + FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) + { + Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); + st->hTdCngEnc->cng_Qexc_buf[ii] = q_exc; + } cng_params_upd_ivas_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q6, HO_HIST_SIZE * L_FFT ); -#endif -#else -#endif // IVAS_FLOAT_FIXED IF( EQ_16( st->L_frame, L_FRAME ) ) { diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index ffb8c6e0e09782d0cc40ef05b91af1a55c309601..0f8a533f35ef547dbe2e301abdc2861c1371bf1e 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -51,10 +51,13 @@ /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void init_tcx( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate, const int16_t MCT_flag ); +#endif static void init_sig_buffers( Encoder_State *st, const int16_t L_frame_old, const int16_t L_subfr, const int32_t total_brate, const int32_t last_total_brate ); +#ifndef IVAS_FLOAT_FIXED static void init_core_sig_ana( Encoder_State *st ); +#endif static void init_acelp( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate ); static void init_modes( Encoder_State *st, const int32_t last_total_brate ); #ifdef IVAS_FLOAT_FIXED @@ -219,10 +222,11 @@ void init_coder_ace_plus_ivas_fx( /* Initialize TCX */ IF( hTcxEnc != NULL ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifndef IVAS_FLOAT_FIXED init_tcx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag ); -#endif +#else init_tcx_ivas_fx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag ); +#endif } /* Initialize Signal Buffers */ @@ -463,17 +467,19 @@ void init_coder_ace_plus( } /* Initialize Core Signal Analysis Module */ - init_core_sig_ana( st ); #ifdef IVAS_FLOAT_FIXED init_core_sig_ana_ivas_fx( st ); +#else + init_core_sig_ana( st ); #endif /* Initialize TCX */ if ( hTcxEnc != NULL ) { - init_tcx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag ); #ifdef IVAS_FLOAT_FIXED init_tcx_ivas_fx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag ); +#else + init_tcx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag ); #endif } @@ -634,7 +640,7 @@ static void init_tcx_ivas_fx( move16(); set16_fx( hTcxEnc->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); - set_c( hTcxEnc->memQuantZeros, 0, L_FRAME_PLUS ); + set8_fx( hTcxEnc->memQuantZeros, 0, L_FRAME_PLUS ); /* TCX-LTP */ hTcxEnc->tcxltp = getTcxLtp( st->sr_core ); @@ -713,7 +719,7 @@ static void init_tcx_ivas_fx( return; } #endif - +#ifndef IVAS_FLOAT_FIXED static void init_tcx( Encoder_State *st, const int16_t L_frame_old, @@ -724,35 +730,33 @@ static void init_tcx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ - hTcxEnc->spectrum[0] = hTcxEnc->spectrum_long; - hTcxEnc->spectrum[1] = hTcxEnc->spectrum_long + N_TCX10_MAX; #ifdef IVAS_FLOAT_FIXED hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx; hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX; st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_e[1] = 0; move16(); move16(); -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); -#endif #ifdef MSAN_FIX - set_zero( hTcxEnc->spectrum[0], N_TCX10_MAX ); - set_zero( hTcxEnc->spectrum[1], N_TCX10_MAX ); set_zero_fx( hTcxEnc->spectrum_fx[0], N_TCX10_MAX ); set_zero_fx( hTcxEnc->spectrum_fx[1], N_TCX10_MAX ); #endif + init_tcx_cfg_ivas_fx( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, + st->fscale, st->preemph_fac, st->tcxonly, st->rf_mode, st->igf, + st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag ); +#else +#ifdef MSAN_FIX + set_zero( hTcxEnc->spectrum[0], N_TCX10_MAX ); + set_zero( hTcxEnc->spectrum[1], N_TCX10_MAX ); +#endif + + hTcxEnc->spectrum[0] = hTcxEnc->spectrum_long; + hTcxEnc->spectrum[1] = hTcxEnc->spectrum_long + N_TCX10_MAX; + init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, st->fscale, st->encoderLookahead_enc, st->encoderLookahead_FB, st->preemph_fac_flt, st->tcxonly, st->rf_mode, st->igf, st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag ); - -#ifdef IVAS_FLOAT_FIXED - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); - init_tcx_cfg_ivas_fx( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, - st->fscale, st->preemph_fac, st->tcxonly, st->rf_mode, st->igf, - st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag ); #endif /* Init TCX target bits correction factor */ @@ -833,7 +837,7 @@ static void init_tcx( return; } - +#endif /*-----------------------------------------------------------------------* * init_sig_buffers() * @@ -898,7 +902,9 @@ static void init_sig_buffers( { lerp_flt( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); } +#ifndef IVAS_FLOAT_FIXED st->hLPDmem->mem_w0_flt = 0; +#endif st->mem_wsp_enc_flt = st->buf_wspeech_enc_flt[st->L_frame + L_SUBFR - 1]; } @@ -1083,7 +1089,7 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol * * *-----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void init_core_sig_ana( Encoder_State *st ) { @@ -1126,7 +1132,7 @@ static void init_core_sig_ana( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void init_core_sig_ana_ivas_fx( Encoder_State *st ) { @@ -1187,9 +1193,10 @@ static void init_acelp( const int32_t total_brate, const int32_t last_total_brate ) { +#ifndef IVAS_FLOAT_FIXED int16_t mem_syn_r_size_old; int16_t mem_syn_r_size_new; - +#endif LPD_state_HANDLE hLPDmem = st->hLPDmem; /* Init pitch lag */ @@ -1208,8 +1215,10 @@ static void init_acelp( { if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED set_zero( hLPDmem->syn_flt, 1 + M ); set_zero( hLPDmem->mem_syn_r_flt, L_SYN_MEM ); +#endif } if ( st->hTcxEnc != NULL ) @@ -1247,8 +1256,10 @@ static void init_acelp( { if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED mvr2r( hLPDmem->mem_syn1_flt, hLPDmem->mem_syn2_flt, M ); set_zero( hLPDmem->syn_flt, M ); +#endif } if ( st->hTcxEnc != NULL ) @@ -1272,14 +1283,14 @@ static void init_acelp( { #ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = TILT_CODE_FLT; -#else - hLPDmem->tilt_code = TILT_CODE; -#endif set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); set_zero( hLPDmem->syn_flt, 1 + M ); hLPDmem->mem_w0_flt = 0.0f; set_zero( hLPDmem->mem_syn_flt, M ); set_zero( hLPDmem->mem_syn2_flt, M ); +#else + hLPDmem->tilt_code = TILT_CODE; +#endif } /* unquantized LPC*/ @@ -1326,7 +1337,10 @@ static void init_acelp( { if ( st->L_frame != L_frame_old && st->L_frame <= L_FRAME16k && L_frame_old <= L_FRAME16k ) /* Rate switching between 12.8 and 16 kHz*/ { +#ifndef IVAS_FLOAT_FIXED float tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1]; +#endif + float A[M + 1]; #ifdef IVAS_FLOAT_FIXED Word16 A_fx[M + 1]; #endif @@ -1371,8 +1385,8 @@ static void init_acelp( /* Update wsyn */ if ( hLPDmem != NULL ) { - synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC ); #ifndef IVAS_FLOAT_FIXED + synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC ); lsp2a_stab( st->lsp_old, A, M ); #else E_LPC_f_lsp_a_conversion( st->lsp_old_fx, A_fx, M ); @@ -1380,6 +1394,7 @@ static void init_acelp( fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), M + 1 ); #endif #endif +#ifndef IVAS_FLOAT_FIXED weight_a( A, Ap, GAMMA1_FLT, M ); tmp = 0.f; tmp_buf[0] = 0.f; @@ -1387,6 +1402,7 @@ static void init_acelp( deemph( tmp_buf + 1, st->preemph_fac_flt, M, &tmp ); residu( Ap, M, tmp_buf + M, &tmp, 1 ); hLPDmem->mem_w0_flt = st->wspeech_enc_flt[-1] - tmp; +#endif } } else if ( st->L_frame != L_frame_old ) /* Rate switching involving TCX only modes */ @@ -1400,11 +1416,11 @@ static void init_acelp( { #ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = TILT_CODE_FLT; + set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); #else hLPDmem->tilt_code = TILT_CODE; #endif - set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); - +#ifndef IVAS_FLOAT_FIXED /*Resamp others memories*/ /*Size of LPC syn memory*/ mem_syn_r_size_old = (int16_t) ( 1.25 * L_frame_old / 20.f ); @@ -1415,6 +1431,7 @@ static void init_acelp( /*Untouched memories : LPDmem->syn & LPDmem->mem_w0_flt*/ hLPDmem->mem_w0_flt = 0; +#endif } /* unquantized LPC*/ @@ -1570,6 +1587,8 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh { Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); set16_fx( hLPDmem->syn, 0, M ); + hLPDmem->q_lpd_syn = Q15; + move16(); } IF( st->hTcxEnc != NULL ) { @@ -1600,6 +1619,10 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh move16(); set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); set16_fx( hLPDmem->syn, 0, 1 + M ); + hLPDmem->q_lpd_syn = Q15; + move16(); + hLPDmem->q_lpd_old_exc = Q15; + move16(); hLPDmem->mem_w0 = 0; move16(); set16_fx( hLPDmem->mem_syn, 0, M ); @@ -1705,6 +1728,8 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh move16(); set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); move16(); + hLPDmem->q_lpd_old_exc = Q15; + move16(); /*Resamp others memories*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 684e9c63179d493574a753524376e2ad80d09525..89d8685a8786805a2db6e20193bf7c0ec26bf5ef 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -212,12 +212,6 @@ void core_coder_mode_switch_ivas_fx( st->currEnergyHF_fx = 0; move32(); - /* Initialize TCX */ - IF( hTcxEnc != NULL ) - { - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); - } - /* Initialize Signal Buffers */ f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, st->L_frame ); f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); @@ -230,14 +224,11 @@ void core_coder_mode_switch_ivas_fx( set_zero( st->mem_error_bpf, 2 * L_FILT16k ); #endif init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); IF( st->hLPDmem != NULL ) { - // me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); - fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, st->prev_Q_new, L_EXC_MEM ); + st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; + move16(); } -#endif } test(); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index a92e8660a75477da16436648788dcf8abb1edbc2..e18735c849fe5674204e56f50bc18367da0b69c3 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -73,7 +73,9 @@ void core_switching_pre_enc( { if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn1_flt, M ); +#endif } if ( st->element_mode != IVAS_CPE_MDCT ) @@ -224,12 +226,12 @@ void core_switching_pre_enc( /* Reset ACELP parameters */ if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED hLPDmem->syn_flt[M] = 0; set_f( hLPDmem->mem_syn2_flt, 0.0f, M ); set_f( hLPDmem->mem_syn_flt, 0.0f, M ); set_f( hLPDmem->mem_syn1_flt, 0.0f, M ); hLPDmem->mem_w0_flt = 0.0f; -#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = 0.0f; hLPDmem->gc_threshold_flt = 0.0f; set_f( hLPDmem->dispMem_flt, 0, 8 ); @@ -273,7 +275,9 @@ void core_switching_pre_enc( /* Reset old ACELP buffers */ if ( st->element_mode == EVS_MONO && hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED set_f( hLPDmem->old_exc_flt, 0, L_EXC_MEM ); +#endif } if ( st->hBWE_TD != NULL ) @@ -301,8 +305,8 @@ void core_switching_pre_enc( if ( hLPDmem != NULL ) { - hLPDmem->mem_w0_flt = 0.0f; #ifndef IVAS_FLOAT_FIXED + hLPDmem->mem_w0_flt = 0.0f; hLPDmem->tilt_code_flt = 0.0f; #else hLPDmem->tilt_code = 0; @@ -454,7 +458,6 @@ void core_switching_pre_enc( return; } - #ifdef IVAS_FLOAT_FIXED void core_switching_pre_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -896,15 +899,22 @@ void core_switching_post_enc( floatToFixed_arr( old_inp_16k, old_inp_16k_fx, Q_new - 1, L_INP ); floatToFixed_arr( A, A_fx, 12, NB_SUBFR16k * ( M + 1 ) ); floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, 12, M + 1 ); - st->hLPDmem->mem_w0 = float_to_fix16( st->hLPDmem->mem_w0_flt, Q_new - 1 ); - floatToFixed_arr( st->hLPDmem->mem_syn_flt, st->hLPDmem->mem_syn, Q_new - 1, M ); - #endif + /* Memory scaling to keep everything in common q */ + Scale_sig( st->hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + st->hLPDmem->mem_w0 = shl( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); + move16(); + st->hLPDmem->q_mem_syn = sub( Q_new, 1 ); + move16(); + acelp_core_switch_enc_ivas_fx( st, old_inp_12k8_fx + L_INP_MEM - NS2SA( INT_FS_12k8, ACELP_LOOK_NS ), old_inp_16k_fx + L_INP_MEM - NS2SA( INT_FS_16k, ACELP_LOOK_NS ), A_fx, 0, sub( Q_new, 1 ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from fix to float fixedToFloat_arr( st->old_input_signal_fx, st->old_input_signal, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st->hLPDmem->mem_w0_flt = fix16_to_float( st->hLPDmem->mem_w0, Q_new - 1 ); #endif #endif } diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index 2c216107973a2a7f7327fd68aae6473feb5919cc..13ab0548954f0713729bec1be511f9ac396a22fb 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -828,10 +828,8 @@ void td_cng_enc_init( set16_fx( hTdCngEnc->exc_mem1_fx, 0, 30 ); set16_fx( hTdCngEnc->exc_mem2_fx, 0, 30 ); set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions - set_f( hTdCngEnc->cng_exc2_buf_flt, 0.0f, HO_HIST_SIZE * L_FFT ); -#endif + set16_fx( hTdCngEnc->cng_exc2_buf, 0, HO_HIST_SIZE * L_FFT ); + set16_fx( hTdCngEnc->cng_Qexc_buf, Q15, HO_HIST_SIZE ); /* SWB CNG/DTX */ hTdCngEnc->last_wb_cng_ener_fx = -1541; diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index e537fca286deca498d4574dfc345b0db82953be3..76af46967c9d242f8ca122d42aaa82fbb550e9b0 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -1803,11 +1803,6 @@ void FdCngEncodeMDCTStereoSID_fx( /* pad with zeros to reach common SID frame size */ push_indice( sts[1]->hBstr, IND_ENERGY, 0, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - sts[0]->preemph_fac_flt = fixedToFloat( sts[0]->preemph_fac, Q15 ); - sts[1]->preemph_fac_flt = fixedToFloat( sts[1]->preemph_fac, Q15 ); -#endif - return; } #else @@ -2400,11 +2395,6 @@ void FdCngEncodeDiracMDCTStereoSID_fx( } push_indice( sts[0]->hBstr, IND_ENERGY, gain_idx[0], 7 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - sts[0]->preemph_fac_flt = fixedToFloat( sts[0]->preemph_fac, Q15 ); - sts[1]->preemph_fac_flt = fixedToFloat( sts[1]->preemph_fac, Q15 ); -#endif - return; } #else diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index b45ac7004c058c0318e5fdb2921aca01737ac2a7..0407d443eec263c238bb8c3eebce3ec2bd4fd14f 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -405,8 +405,7 @@ void hq_core_enc_ivas_fx( { /* Store LB synthesis in case of switch to ACELP */ Copy( output_fx, st->hLPDmem->old_exc, L_FRAME16k ); - // st->hLPDmem->e_old_exc = 15; - st->prev_Q_new = 0; + st->hLPDmem->q_lpd_old_exc = 15; move16(); } pop_wmops(); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 9abd16f2e3b3686b8cacaf92d5047097dc25c7d9..b9e8f5beabb4116f03a40cb268c47a424ae5f954 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -2293,14 +2293,12 @@ ivas_error init_encoder_ivas_fx( set_zero( st->mem_error_bpf, 2 * L_FILT16k ); #endif init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); + IF( st->hLPDmem != NULL ) { - // me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); - fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, st->prev_Q_new, L_EXC_MEM ); + st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; + move16(); } -#endif /*-----------------------------------------------------------------* * FD-CNG encoder *-----------------------------------------------------------------*/ @@ -2402,21 +2400,29 @@ void LPDmem_enc_init( #ifdef IVAS_FLOAT_FIXED Word16 i; #endif +#ifndef IVAS_FLOAT_FIXED set_zero( hLPDmem->syn_flt, 1 + M ); - set_f( hLPDmem->old_exc_flt, 0, L_EXC_MEM ); hLPDmem->mem_w0_flt = 0.0f; set_f( hLPDmem->mem_syn_flt, 0, M ); set_f( hLPDmem->mem_syn1_flt, 0, M ); set_f( hLPDmem->mem_syn2_flt, 0, M ); + set_f( hLPDmem->mem_syn3_flt, 0, M ); set_zero( hLPDmem->mem_syn_r_flt, L_SYN_MEM ); +#endif #ifdef IVAS_FLOAT_FIXED #ifdef MSAN_FIX + set16_fx( hLPDmem->syn, 0, 1 + M ); + set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); + hLPDmem->mem_w0 = 0; set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); + set16_fx( hLPDmem->mem_syn1_fx, 0, M ); + set16_fx( hLPDmem->mem_syn, 0, M ); + set16_fx( hLPDmem->mem_syn2, 0, M ); + set16_fx( hLPDmem->mem_syn3, 0, M ); #endif #endif - set_f( hLPDmem->mem_syn3_flt, 0, M ); #ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = 0.0f; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 87a63bf4a074ec570abeca44444e51b03464fe9d..28ff1567f524d0dbe9a42f938c1db071ad6da41c 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -92,10 +92,6 @@ ivas_error ivas_core_enc( float *inp[CPE_CHANNELS]; float new_inp_resamp16k[CPE_CHANNELS][L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k] = { { 0 } }; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ - float shb_speech[L_FRAME16k]; - float hb_speech[L_FRAME16k / 4]; - float *new_swb_speech; - float new_swb_speech_buffer[L_FRAME48k + STEREO_DFT_OVL_MAX]; Word16 Q_new[CPE_CHANNELS] = { 0 }; #ifndef IVAS_FLOAT_FIXED float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; @@ -203,8 +199,6 @@ ivas_error ivas_core_enc( input_Fs = sts[0]->input_Fs; input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); - set_f( new_swb_speech_buffer, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); - for ( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; @@ -231,8 +225,6 @@ ivas_error ivas_core_enc( Word16 e_fft_buff; Word16 e_enerBuffer; - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); - f2me( cor_map_sum[n], &cor_map_sum_fx, &exp_cor_map_sum ); f2me_buf_16( fft_buff[n], fft_buff_fx, &e_fft_buff, ( 2 * L_FFT ) ); @@ -275,10 +267,6 @@ ivas_error ivas_core_enc( return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac_flt = fixedToFloat_16( st->preemph_fac, Q15 ); -#endif - if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE ) { st->enablePlcWaveadjust = 0; @@ -434,7 +422,6 @@ ivas_error ivas_core_enc( mvr2r( Aw[n], Aw_flt[n], st->nb_subfr * ( M + 1 ) ); floatToFixed_arr( Aw_flt[n], Aw_fx[n], Q12, st->nb_subfr * ( M + 1 ) ); - st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); floatToFixed_arr( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq, -1, L_FRAME32k / 2 + 64 ); st->hTcxEnc->Q_old_out = Q_factor_arr( st->hTcxEnc->old_out, L_FRAME32k ) - 1; @@ -498,9 +485,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - PWord16 *p; Word16 q = 0; - Word16 overlap, tmp; Word16 left_overlap, right_overlap; IF( st->element_mode > EVS_MONO && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) { @@ -508,55 +493,6 @@ ivas_error ivas_core_enc( right_overlap = st->hTcxCfg->tcx_mdct_window_delayFB; Word16 L_frame1 = 640; - p = st->hTcxCfg->tcx_mdct_window_minimumFB; - tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); - - Word16 q1 = Q_factor_arr( st->hTcxCfg->tcx_mdct_window_minimumFB_flt, tmp ); - FOR( i = 0; i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i], q1 ); - } - FOR( i = 0; i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i + tmp], q1 ); - } - - p = st->hTcxCfg->tcx_mdct_window_transFB; - tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); - - FOR( i = 0; i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_transFB_flt[i], q1 ); - } - FOR( i = 0; i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_transFB_flt[i + tmp], q1 ); - } - - p = st->hTcxCfg->tcx_aldo_window_2_FB; - tmp = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 ); - - FOR( i = 0; i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], q1 ); - } - FOR( i = 0; i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i + tmp], q1 ); - } - - tmp = st->hTcxCfg->tcx_mdct_window_min_length / 2; - p = st->hTcxCfg->tcx_mdct_window_minimum; - FOR( i = 0; i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimum_flt[i], q1 ); - } - FOR( i = 0; i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimum_flt[i + tmp], q1 ); - } - - Word16 l1 = ( shr( left_overlap, 1 ) * 2 ) + sub( L_frame1, shr( add( left_overlap, right_overlap ), 1 ) ) + ( shr( right_overlap, 1 ) * 2 ) - shr( left_overlap, 1 ) + st->hTcxCfg->tcx_offsetFB; q = Q_factor_arr( st->hTcxEnc->speech_TCX_flt, l1 ) - 1; st->hTcxEnc->q_speech_TCX = q; @@ -568,51 +504,6 @@ ivas_error ivas_core_enc( floatToFixed_arr( st->hTcxEnc->speech_TCX_flt - overlap1 / 2 + offset, st->hTcxEnc->speech_TCX - overlap1 / 2 + offset, q, l1 ); floatToFixed_arr( st->hTcxEnc->speech_TCX_flt - overlap1 / 2 + offset, st->hTcxEnc->speech_TCX - overlap1 / 2 + offset, q, 2 * L_FRAME48k + 960 ); - q1 = 15; - tmp = st->hTcxCfg->tcx_mdct_window_half_length / 2; - p = st->hTcxCfg->tcx_mdct_window_half; - FOR( i = 0; i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_half_flt[i], q1 ); - } - FOR( i = 0; i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_half_flt[i + tmp], q1 ); - } - - tmp = st->hTcxCfg->tcx_mdct_window_min_length / 2; - p = st->hTcxCfg->tcx_mdct_window_trans; - FOR( i = 0; i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_trans_flt[i], q1 ); - } - FOR( i = 0; i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_trans_flt[i + tmp], q1 ); - } - - overlap = st->hTcxCfg->tcx_mdct_window_length; - tmp = overlap / 2; - p = st->hTcxCfg->tcx_aldo_window_2; - FOR( i = 0; i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_flt[i], q1 ); - } - FOR( i = 0; i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_flt[i + tmp], q1 ); - } - - tmp = overlap / 2; - p = st->hTcxCfg->tcx_aldo_window_1_trunc; - FOR( i = -NS2SA( st->sr_core, N_ZERO_MDCT_NS ); i < tmp; i++ ) - { - p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_aldo_window_1_trunc_flt[i], q1 ); - } - FOR( i = -NS2SA( st->sr_core, N_ZERO_MDCT_NS ); i < tmp; i++ ) - { - p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_aldo_window_1_trunc_flt[i + tmp], q1 ); - } FOR( i = 0; i < L_FRAME32k / 2 + 64; i++ ) { @@ -631,21 +522,6 @@ ivas_error ivas_core_enc( #endif hq_core_enc_ivas_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( NE_16( st->element_mode, EVS_MONO ) ) - { - // st->hHQ_core->crest_lp = fix_to_float( st->hHQ_core->crest_lp_fx, st->hHQ_core->crest_lp_q ); - // st->hHQ_core->crest_mod_lp = fix_to_float( st->hHQ_core->crest_mod_lp_fx, st->hHQ_core->crest_mod_lp_q ); - } - IF( st->element_mode > EVS_MONO ) - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - st->hLPDmem->old_exc_flt[i] = fix16_to_float( st->hLPDmem->old_exc[i], 0 ); - } - } -#endif #endif } @@ -738,7 +614,7 @@ ivas_error ivas_core_enc( * Postprocessing, BWEs and Updates *---------------------------------------------------------------------*/ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; @@ -753,11 +629,13 @@ ivas_error ivas_core_enc( * WB BWE encoding *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Temporarily calculating variable Q. Will get Q values from core processing */ - // Q_new[n] = Q_factor_arrL( bwe_exc_extended[n], L_FRAME32k + NL_BUFF_OFFSET ); - // Q_new[n] = Q_new[n] / 2; + + Word32 shb_speech_fx32[L_FRAME16k]; + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 q_realImagBuffer; + Word16 old_inp_12k8_fx[L_INP_12k8], old_inp_16k_fx[L_INP]; floatToFixed_arr16( new_inp_resamp16k[n], new_inp_resamp16k_fx[n], -1, L_FRAME16k ); floatToFixed_arr( pitch_buf[n], pitch_buf_fx[n], Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float @@ -768,6 +646,51 @@ ivas_error ivas_core_enc( floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, -1, L_FRAME48k ); st->Q_old_wtda = -1; // This reset is required for resolving crash issue. Needs to be looked into further } + q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); + q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); + IF( st->cldfbSynTd ) + { + q_realImagBuffer = s_min( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ); + } + floatToFixed_arrL32( (float *) &realBuffer[n][0][0], (Word32 *) &realBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); + floatToFixed_arrL32( (float *) &imagBuffer[n][0][0], (Word32 *) &imagBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); + if ( st->element_mode == IVAS_CPE_DFT ) + { + f2me_buf( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], &hCPE->hStereoDft->DFT_fx_e[0], STEREO_DFT_N_MAX_ENC ); + f2me_buf( hCPE->hStereoDft->DFT[1], hCPE->hStereoDft->DFT_fx[1], &hCPE->hStereoDft->DFT_fx_e[1], STEREO_DFT_N_MAX_ENC ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_res_8k, hCPE->hStereoDft->output_mem_res_8k_fx, 16, STEREO_DFT_OVL_8k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_fx, 16, STEREO_DFT_OVL_MAX ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_12k8, hCPE->hStereoDft->output_mem_dmx_12k8_fx, 16, STEREO_DFT_OVL_12k8 ); + } + if ( st->hBWE_FD ) + { + for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) + { + st->hBWE_FD->old_input_fx[ii] = (Word16) st->hBWE_FD->old_input[ii]; + } + } + floatToFixed_arr( st->input_buff, st->input_buff_fx, 0 /*Q_input*/, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + 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 ); + } + + floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, Q_new[n] - 1, L_INP_12k8 ); + floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx, Q_new[n] - 1, L_INP ); + + + if ( st->hBWE_FD != NULL ) + { + // floatToFixed_arr16( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); + floatToFixed_arr16( st->hBWE_FD->old_input_lp, st->hBWE_FD->old_input_lp_fx, Q_new[n] - 1, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); + floatToFixed_arr16( st->hBWE_FD->new_input_hp, st->hBWE_FD->new_input_hp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); + } + + floatToFixed_arr( old_syn_12k8_16k[n], old_syn_12k8_16k_fx[n], Q_new[n] - 1, L_FRAME16k ); #endif test(); test(); @@ -789,133 +712,72 @@ ivas_error ivas_core_enc( /* WB BWE encoder */ wb_bwe_enc_ivas_fx( st, new_inp_resamp16k_fx[n] ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( hb_speech_fx, hb_speech, -1, L_FRAME16k / 4 ); - fixedToFloat_arr( pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); - if ( st->hBWE_FD != NULL ) + IF( st->hBWE_FD != NULL ) { - fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, -1, L_FRAME48k ); + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, Q1 ); // Q-1 -> Q0 + st->Q_old_wtda = add( st->Q_old_wtda, Q1 ); + move16(); } -#endif -#endif /*---------------------------------------------------------------------* * SWB(FB) TBE encoding * SWB(FB) BWE encoding *---------------------------------------------------------------------*/ - new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; -#ifdef IVAS_FLOAT_FIXED new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; new_swb_speech_fx_16 = new_swb_speech_buffer_fx_16 + STEREO_DFT_OVL_MAX; -#endif - if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) + test(); + test(); + IF( !st->Opt_SC_VBR && GE_32( input_Fs, 32000 ) && st->hBWE_TD != NULL ) { /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); - q_realImagBuffer = s_min( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ); - floatToFixed_arrL32( (float *) &realBuffer[n][0][0], (Word32 *) &realBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - floatToFixed_arrL32( (float *) &imagBuffer[n][0][0], (Word32 *) &imagBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - - for ( Word32 idx = 0; idx < ( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); idx++ ) - { - st->hSignalBuf->input_buff[idx] = (Word16) st->hSignalBuf->input_buff_flt[idx]; - } - if ( st->element_mode == IVAS_CPE_DFT ) - { - f2me_buf( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], &hCPE->hStereoDft->DFT_fx_e[0], STEREO_DFT_N_MAX_ENC ); - f2me_buf( hCPE->hStereoDft->DFT[1], hCPE->hStereoDft->DFT_fx[1], &hCPE->hStereoDft->DFT_fx_e[1], STEREO_DFT_N_MAX_ENC ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_res_8k, hCPE->hStereoDft->output_mem_res_8k_fx, 16, STEREO_DFT_OVL_8k ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_fx, 16, STEREO_DFT_OVL_MAX ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_12k8, hCPE->hStereoDft->output_mem_dmx_12k8_fx, 16, STEREO_DFT_OVL_12k8 ); - } - for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) - { - st->hBWE_FD->old_input_fx[ii] = (Word16) st->hBWE_FD->old_input[ii]; - } - for ( Word32 idx = 0; idx < ( L_FRAME48k ); idx++ ) - { - st->hBWE_FD->L_old_wtda_swb_fx[idx] = (Word16) st->hBWE_FD->old_wtda_swb[idx]; - st->hBWE_FD->old_fdbwe_speech_fx[idx] = (Word16) st->hBWE_FD->old_fdbwe_speech[idx]; - } -#endif - /* Scaling cldfb_state_fx */ - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ); + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); /* Re-scaling cldfb_state_fx */ - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ) ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); - fixedToFloat_arr( (Word16 *) &st->hBWE_FD->L_old_wtda_swb_fx[0], (float *) &st->hBWE_FD->old_wtda_swb[0], 0, L_FRAME48k ); - for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) - { - st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; - } - fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); - - fixedToFloat_arr( shb_speech_fx, shb_speech, Q_shb_spch, L_FRAME16k ); - - fixedToFloat_arrL32( (Word32 *) &realBuffer_fx[0][0], (float *) &realBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - fixedToFloat_arrL32( (Word32 *) &imagBuffer_fx[0][0], (float *) &imagBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - - if ( st->element_mode == IVAS_CPE_DFT ) - { - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); - } -#endif -#endif + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ) ); // q_realImagBuffer -> st->cldfbSynTd->Q_cldfb_state } - else if ( input_Fs >= 32000 ) + ELSE IF( GE_32( input_Fs, 32000 ) ) { - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( shb_speech, shb_speech_fx, Q_shb_spch, L_FRAME16k ); -#endif InitSWBencBufferStates_fx( st->hBWE_TD, shb_speech_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( shb_speech_fx, shb_speech, Q_shb_spch, L_FRAME16k ); -#endif -#endif } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->input_buff, st->input_buff_fx, 0 /*Q_input*/, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - floatToFixed_arr( pitch_buf[n], pitch_buf_fx[n], Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float -#endif + Word16 Q_shb_spch_16 = Q_shb_spch; + move16(); + Word16 shift = add( getScaleFactor16( shb_speech_fx, L_FRAME16k ), Q16 ); + Copy_Scale_sig_16_32_no_sat( shb_speech_fx, shb_speech_fx32, L_FRAME16k, shift ); // Q_shb_spch + Q_shb_spch = add( Q_shb_spch, shift ); + + IF( st->hBWE_FD ) + { + shift = getScaleFactor16( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k ); + st->Q_old_wtda = add( st->Q_old_wtda, shift ); + move16(); + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, shift ); // st->Q_old_wtda + } + + Word16 q_new_swb_speech_buffer = getScaleFactor16( new_swb_speech_buffer_fx_16, input_frame ); + Scale_sig( new_swb_speech_buffer_fx_16, q_new_swb_speech_buffer, input_frame ); // Q0->q_new_swb_speech_buffer + /* SWB TBE encoder */ - if ( st->extl == SWB_TBE || st->extl == FB_TBE ) + test(); + test(); + IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) { - if ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) + test(); + IF( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_fb_exc; - - /* Temporarily calculating variable Q. Will get Q values from core processing */ - // Q_new[n] = Q_factor_arrL( bwe_exc_extended[n], L_FRAME32k + NL_BUFF_OFFSET ); - // Q_new[n] = Q_new[n] / 2; - - // prev_lsp_wb_temp_fx, prev_lsp_wb_fx and prev_lpc_wb_fx in Q15. No float counterparts - floatToFixed_arr( shb_speech, shb_speech_fx, Q_shb_spch, L_FRAME16k ); -#endif Word16 fb_exc_fx[L_FRAME16k]; - swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], Q_shb_spch, st->voicing_fx, pitch_buf_fx[n] ); + swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], Q_shb_spch_16, st->voicing_fx, pitch_buf_fx[n] ); IF( EQ_16( st->extl, FB_TBE ) ) { @@ -924,83 +786,17 @@ ivas_error ivas_core_enc( } } } - else if ( st->extl == SWB_BWE || st->extl == FB_BWE ) + ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_inp_12k8_fx[L_INP_12k8], old_inp_16k_fx[L_INP]; - // Word16 q_val; - // Word16 q_old_inp_16k_fx, q_old_syn_12k8_16k_fx, q_old_input_lp; - // Word16 q_old_inp_12k8_fx, q_shb_speech_fx, q_new_input_hp; - - /*q_old_inp_12k8_fx = Q_factor_arr( old_inp_12k8[n], L_INP_12k8 ); - q_old_inp_16k_fx = Q_factor_arr( old_inp_16k[n], L_INP ); - q_old_syn_12k8_16k_fx = Q_factor_arr( old_syn_12k8_16k[n], L_FRAME16k ); - q_shb_speech_fx = Q_factor_arr( shb_speech, L_FRAME16k );*/ - - // q_val = s_min( q_old_inp_12k8_fx, q_old_inp_16k_fx ); - // q_val = s_min( q_val, q_old_syn_12k8_16k_fx ); - - if ( st->hBWE_FD != NULL ) - { - /*q_old_input_lp = Q_factor_arr( st->hBWE_FD->old_input_lp, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); - q_val = s_min( q_val, q_old_input_lp ); - q_new_input_hp = Q_factor_arr( st->hBWE_FD->new_input_hp, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); - q_shb_speech_fx = s_min( q_shb_speech_fx, q_new_input_hp );*/ - st->Q_old_wtda = Q_factor_arr( st->hBWE_FD->old_wtda_swb, L_FRAME48k ); - floatToFixed_arr16( st->hBWE_FD->old_input_lp, st->hBWE_FD->old_input_lp_fx, Q_new[n] - 1, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); - floatToFixed_arr16( st->hBWE_FD->new_input_hp, st->hBWE_FD->new_input_hp_fx, Q_shb_spch, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); - floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, st->Q_old_wtda, L_FRAME48k ); - } - - floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, Q_new[n] - 1, L_INP_12k8 ); - floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx, Q_new[n] - 1, L_INP ); - floatToFixed_arr( old_syn_12k8_16k[n], old_syn_12k8_16k_fx[n], Q_new[n] - 1, L_FRAME16k ); - floatToFixed_arr16( shb_speech, shb_speech_fx, Q_shb_spch, L_FRAME16k ); - - for ( int ii = 0; ii < L_FRAME48k + STEREO_DFT_OVL_MAX; ii++ ) - { - new_swb_speech_buffer_fx_16[ii] = (Word16) new_swb_speech_buffer[ii]; - } - for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) - { - st->hBWE_FD->old_input_fx[ii] = (Word16) st->hBWE_FD->old_input[ii]; - } -#endif + Copy_Scale_sig_32_16( shb_speech_fx32, shb_speech_fx, L_FRAME16k, -Q16 ); // Q_shb_spch - 16 + Scale_sig( new_swb_speech_fx_16, input_frame, negate( q_new_swb_speech_buffer ) ); // Q0 /* SWB(FB) BWE encoder */ - swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, shb_speech_fx, Q_shb_spch, sub( Q_new[n], 1 ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st->hBWE_FD != NULL ) - { - fixedToFloat_arr( st->hBWE_FD->old_input_lp_fx, st->hBWE_FD->old_input_lp, Q_new[n] - 1, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); - fixedToFloat_arr( st->hBWE_FD->new_input_hp_fx, st->hBWE_FD->new_input_hp, Q_shb_spch, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); - fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); - } - for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) - { - st->hBWE_FD->old_input[ii] = (float) st->hBWE_FD->old_input_fx[ii]; - } -#endif + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, shb_speech_fx, sub( Q_shb_spch, Q16 ), sub( Q_new[n], 1 ) ); + Scale_sig( new_swb_speech_fx_16, input_frame, q_new_swb_speech_buffer ); // q_new_swb_speech_buffer } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 new_swb_speech_buffer_fx16[L_FRAME48k + STEREO_DFT_OVL_MAX]; - Word16 q_new_swb_speech_buffer = Q_factor_arr( new_swb_speech_buffer, input_frame ); - floatToFixed_arr16( new_swb_speech_buffer, new_swb_speech_buffer_fx16, q_new_swb_speech_buffer, input_frame ); - Word32 shb_speech_fx32[L_FRAME16k]; - Word32 voice_factors_fx32[CPE_CHANNELS][NB_SUBFR16k]; - Word16 q_shb_speech_fx32 = Q_factor_arrL( shb_speech, L_FRAME16k ); - floatToFixed_arrL( shb_speech, shb_speech_fx32, q_shb_speech_fx32, L_FRAME16k ); - 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 ); - } + Scale_sig( old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q1, Q_new[n] ) ); // Q0 - floatToFixed_arr( old_syn_12k8_16k[n], old_syn_12k8_16k_fx[n], 0, L_FRAME16k ); -#endif /*---------------------------------------------------------------------* * SWB DTX/CNG encoding *---------------------------------------------------------------------*/ @@ -1010,7 +806,7 @@ ivas_error ivas_core_enc( IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && ( GE_16( input_frame, L_FRAME32k ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) { /* SHB DTX/CNG encoder */ - Copy_Scale_sig_32_16( shb_speech_fx32, shb_speech_fx, L_FRAME16k, negate( q_shb_speech_fx32 ) ); + Copy_Scale_sig_32_16( shb_speech_fx32, shb_speech_fx, L_FRAME16k, negate( Q_shb_spch ) ); // Q0 swb_CNG_enc_ivas_fx( st, shb_speech_fx /* Unmodified */, old_syn_12k8_16k_fx[n] ); } @@ -1022,13 +818,14 @@ ivas_error ivas_core_enc( test(); IF( n == 0 && GE_32( input_Fs, 32000 ) && hStereoICBWE != NULL ) { - stereo_icBWE_preproc_fx( hCPE, input_frame, new_swb_speech_buffer_fx16 /*tmp buffer*/, q_new_swb_speech_buffer ); + Word32 voice_factors_fx32[CPE_CHANNELS][NB_SUBFR16k]; + stereo_icBWE_preproc_fx( hCPE, input_frame, new_swb_speech_buffer_fx_16 /*tmp buffer*/, q_new_swb_speech_buffer ); q_new_swb_speech_buffer = add( q_new_swb_speech_buffer, 16 ); - Copy_Scale_sig_16_32( new_swb_speech_buffer_fx16, new_swb_speech_buffer_fx, input_frame, Q16 ); // q_new_swb_speech_buffer - Copy_Scale_sig_16_32( voice_factors_fx[0], voice_factors_fx32[0], NB_SUBFR16k, Q16 ); // Q31 + Copy_Scale_sig_16_32( new_swb_speech_buffer_fx_16, new_swb_speech_buffer_fx, input_frame, Q16 ); // q_new_swb_speech_buffer + Copy_Scale_sig_16_32( voice_factors_fx[0], voice_factors_fx32[0], NB_SUBFR16k, Q16 ); // Q31 - stereo_icBWE_enc_ivas_fx( hCPE, shb_speech_fx32, sub( Q31, q_shb_speech_fx32 ), new_swb_speech_buffer_fx, sub( Q31, q_new_swb_speech_buffer ), voice_factors_fx32[0] ); + stereo_icBWE_enc_ivas_fx( hCPE, shb_speech_fx32, sub( Q31, Q_shb_spch ), new_swb_speech_buffer_fx, sub( Q31, q_new_swb_speech_buffer ), voice_factors_fx32[0] ); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { @@ -1061,6 +858,27 @@ ivas_error ivas_core_enc( updt_enc_common_ivas_fx( st ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + fixedToFloat_arrL32( &realBuffer_fx[0][0], &realBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); + fixedToFloat_arrL32( &imagBuffer_fx[0][0], &imagBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); + + if ( st->element_mode == IVAS_CPE_DFT ) + { + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); + } + if ( st->hBWE_FD != NULL ) + { + fixedToFloat_arr( st->hBWE_FD->old_input_lp_fx, st->hBWE_FD->old_input_lp, Q_new[n] - 1, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); + fixedToFloat_arr( st->hBWE_FD->new_input_hp_fx, st->hBWE_FD->new_input_hp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); + fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); + // fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); + for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) + { + st->hBWE_FD->old_input[ii] = (float) st->hBWE_FD->old_input_fx[ii]; + } + } fixedToFloat_arr( st->input_fx, st->input, 0 /* Q_input*/, L_FRAME48k ); 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 ); @@ -1070,18 +888,6 @@ ivas_error ivas_core_enc( 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( 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; - } - ELSE - { - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - } - } #endif } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 170ce67046457f897691f70d37ed70e7099fdd3a..7739e00a147615beec6a729c176f09af14d82e7a 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1087,7 +1087,7 @@ ivas_error ivas_compute_core_buffers_fx( shift = s_max( shift, 0 ); shift = s_min( shift, Q_MAX ); minimum_fx( st->Q_max, L_Q_MEM, &Q_min ); - *Q_new = s_min( shift, Q_min ); + *Q_new = s_min( 1, s_min( shift, Q_min ) ); move16(); IF( inp_max == 0 ) { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 9e306e67f807f3f9440ea7e73eb055ed7b21c285..5681ba628aa117af5a54515e5ddc47adb8b66fdb 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2494,13 +2494,8 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 res_cod_SNR_M_fx[STEREO_DFT_BAND_MAX]; Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; - Word16 tcx_mdct_window_fx[L_LOOK_16k]; Word16 wsp_fx_temp[L_WSP]; Word16 *wsp_fx_l; - if ( flag_16k_smc ) - floatToFixed_arr16( st->hTcxCfg->tcx_mdct_window_flt, tcx_mdct_window_fx, Q15, L_LOOK_16k ); - else - floatToFixed_arr16( st->hTcxCfg->tcx_mdct_window_flt, tcx_mdct_window_fx, Q15, L_LOOK_12k8 ); floatToFixed_arrL( st->hTcxEnc->spectrum_long, st->hTcxEnc->spectrum_long_fx, Q15, N_MAX ); #endif IF( flag_16k_smc ) @@ -2577,7 +2572,7 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr( st->speech_enc_flt - 560, st->speech_enc - 560, q_speech_enc, 2 * 560 ); floatToFixed_arr( st->wspeech_enc_flt - 560, st->wspeech_enc - 560, q_speech_enc, 2 * 560 ); #endif - smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, q_speech_enc, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, q_speech_enc, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < 7; i++ ) { @@ -2608,7 +2603,7 @@ ivas_error pre_proc_front_ivas_fx( wsp_fx_l = wsp_fx_temp + L_WSP_MEM; floatToFixed_arr( wsp, wsp_fx_l, Q_new, L_WSP - L_WSP_MEM ); #endif - smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < 7; i++ ) { diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 8d6c8003a846cfd8118a07f95f51d4c452c50e11..262c765d5ff61b898830b7c1e5e7ff66890da0a2 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -464,7 +464,6 @@ ivas_error ivas_cpe_enc_fx( IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_inp; f2me_buf_16( sts[n]->input, sts[n]->input_fx, &q_inp, input_frame ); q_inp = 15 - q_inp; #endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 262ad660e7090a891e15b00fb1f48238efc54c35..ed83eac99f38aac00271053152c95891a600d26e 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -639,7 +639,6 @@ ivas_error ivas_mct_enc_fx( { sts = hCPE->hCoreCoder; st = sts[ch]; - st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); } #endif ivas_mdct_quant_coder_fx( hCPE, hMCT->tnsBits[cpe_id], hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], 1 ); @@ -681,18 +680,6 @@ ivas_error ivas_mct_enc_fx( 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( 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; - } - ELSE - { - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - } - } #endif #else updt_enc_common( hCPE->hCoreCoder[n] ); diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 574d753ac3501ef798eb9280d6e9838a6a8dd859..fd59ab716e4e534f9e40887a7c3f82ee64f0ca67 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -515,27 +515,30 @@ void stereo_tcx_core_enc( #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Q_new = 0; - - // Word16 exp_exc; - // f2me_buf_16( st->hLPDmem->old_exc_flt, st->hLPDmem->old_exc, &exp_exc, L_EXC_MEM ); - floatToFixed_arr( st->hLPDmem->old_exc_flt, st->hLPDmem->old_exc, Q_new, L_EXC_MEM ); Q_exc = Q_new; st->prev_Q_new = Q_exc; - if ( st->hTdCngEnc != NULL ) - { - floatToFixed_arr( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, Q_exc, HO_HIST_SIZE * L_FFT ); - } #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->synth_flt, st->synth, st->Q_syn, st->L_frame ); - floatToFixed_arr( st->hLPDmem->syn_flt, st->hLPDmem->syn, st->Q_syn, M + 1 ); - if ( st->tcxonly == 0 ) { st->wspeech_enc[st->L_frame - 1] = (Word16) floatToFixed( st->wspeech_enc_flt[st->L_frame - 1], st->Q_syn ); } #endif // IVAS_FLOAT_FIXED_CONVERSIONS + IF( st->hTdCngEnc ) + { + FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) + { + Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( Q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); + st->hTdCngEnc->cng_Qexc_buf[ii] = Q_exc; + } + } + Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); + st->hLPDmem->q_lpd_old_exc = Q_new; + move16(); + Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); + st->hLPDmem->q_lpd_syn = st->Q_syn; + move16(); IF( !st->enableTcxLpc ) { @@ -820,22 +823,34 @@ void stereo_tcx_core_enc( { set16_fx( pitch_buf_fx, L_SUBFR * ONE_IN_Q6, NB_SUBFR16k ); } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Fixed to float + /* Memory scaling to keep everything in common q */ + Word16 curr_q_syn = sub( shl( Q_new, 1 ), 1 ); + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); + Scale_sig( st->hLPDmem->mem_syn, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); + Scale_sig( st->hLPDmem->mem_syn2, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); + st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( s_min( Q_new, st->hLPDmem->q_mem_syn ), Q_new ) ); + move16(); + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn3, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), st->hLPDmem->q_mem_syn ) ); + st->hLPDmem->q_mem_syn = sub( Q_new, 1 ); + move16(); + st->hLPDmem->q_lpd_syn = Q_new; + move16(); + st->hLPDmem->q_lpd_old_exc = Q_new; + move16(); IF( st->hTdCngEnc != NULL ) { - fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q_exc, HO_HIST_SIZE * L_FFT ); + FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) + { + Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( Q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); + st->hTdCngEnc->cng_Qexc_buf[ii] = Q_exc; + move16(); + } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // Fixed to float fixedToFloat_arr( st->synth, st->synth_flt, Q_new, st->L_frame ); - fixedToFloat_arr( st->hLPDmem->mem_syn_r, st->hLPDmem->mem_syn_r_flt, Q_new + ( Q_new - 1 ), L_SYN_MEM ); - fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, Q_new + ( Q_new - 1 ), M ); - fixedToFloat_arr( st->hLPDmem->mem_syn2, st->hLPDmem->mem_syn2_flt, Q_new + ( Q_new - 1 ), M ); - fixedToFloat_arr( st->hLPDmem->syn, st->hLPDmem->syn_flt, Q_new, M + 1 ); - fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, Q_new, L_EXC_MEM ); - st->hLPDmem->mem_w0_flt = fixedToFloat_16( st->hLPDmem->mem_w0, Q_new ); - fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); #endif @@ -1567,7 +1582,6 @@ Word16 ivas_acelp_tcx20_switching_fx( Word16 stab_fac, /* i : LP filter stability */ Word32 *res_cod_SNR_M, Word16 *res_cod_SNR_M_e, - Word16 *tcx_mdct_window_fx, const Word16 flag_16k_smc /* i : flag to compute parameters with 16kHz core */ ) { @@ -1593,7 +1607,7 @@ Word16 ivas_acelp_tcx20_switching_fx( Word16 window_fx[L_LOOK_16k]; PWord16 window_p_fx[L_LOOK_16k]; Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; - Word16 tcx_mdct_window_fx_local[L_LOOK_16k], scale; + Word16 scale; Word32 en[N_MAX / 4]; Word32 offset_tcx, target; Word32 y_fx[N_MAX]; @@ -1616,7 +1630,7 @@ Word16 ivas_acelp_tcx20_switching_fx( L_frame_tmp = L_frame; move16(); - Copy( tcx_mdct_window_fx, tcx_mdct_window_fx_local, L_LOOK_16k ); + x_fx = hTcxEnc->spectrum_long_fx; move32(); e_x = 31 - 15; @@ -1666,7 +1680,14 @@ Word16 ivas_acelp_tcx20_switching_fx( overlap = st->hTcxCfg->tcx_mdct_window_delay; move16(); - Copy( tcx_mdct_window_fx_local, window_fx, L_LOOK_16k ); // Q15 + + FOR( i = 0; i < L_LOOK_16k / 2; i++ ) + { + window_fx[L_LOOK_16k / 2 - 1 - i] = st->hTcxCfg->tcx_mdct_window[i].v.re; // Q15 + move16(); + window_fx[i] = st->hTcxCfg->tcx_mdct_window[i].v.im; // Q15 + move16(); + } } ELSE { @@ -1674,13 +1695,7 @@ Word16 ivas_acelp_tcx20_switching_fx( move16(); tcx_offset = shr( overlap, 1 ); move16(); - FOR( i = 0; i < shr( overlap, 1 ); i++ ) - { - st->hTcxCfg->tcx_mdct_window[i].v.re = tcx_mdct_window_fx_local[overlap - 1 - i]; - st->hTcxCfg->tcx_mdct_window[i].v.im = tcx_mdct_window_fx_local[i]; - move16(); - move16(); - } + mdct_window_sine_IVAS_updated( window_p_fx, INT_FS_12k8, overlap, FULL_OVERLAP, st->element_mode ); FOR( i = 0; i < shr( overlap, 1 ); i++ ) { diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index a8566fd5402b8885601d3c6a11381b0f9a3e0212..faee1c89cc6fdb6f51cbca81c6c83fa5e46c6e44 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -450,12 +450,14 @@ typedef struct td_cng_enc_structure Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging Q6 */ Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ #endif - Word16 burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ - Word16 cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ + Word16 burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ + Word16 cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ +#ifndef IVAS_FLOAT_FIXED float cng_exc2_buf_flt[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ - Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ - Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ - int32_t cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ +#endif + Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ + Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ + int32_t cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ #ifndef IVAS_FLOAT_FIXED float CNG_att; /* CNG and DTX - attenuation factor for CNG, in dB */ #else @@ -1058,28 +1060,31 @@ typedef struct lpd_state_structure #endif /* signal memory */ +#ifndef IVAS_FLOAT_FIXED float syn_flt[1 + M]; /* Synthesis memory (non-pe) */ /* ACELP memories*/ float old_exc_flt[L_EXC_MEM]; /* ACELP exc memory (Aq) */ - - Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ +#endif + Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ + Word16 q_lpd_syn; Word16 old_exc[L_EXC_MEM]; /* ACELP exc memory (Aq) */ - + Word16 q_lpd_old_exc; +#ifndef IVAS_FLOAT_FIXED float mem_w0_flt; float mem_syn_flt[M]; /* ACELP synthesis memory (pe) before post-proc */ float mem_syn1_flt[M]; float mem_syn2_flt[M]; /* ACELP synthesis memory (pe) after post-proc */ float mem_syn_r_flt[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ float mem_syn3_flt[M]; - +#endif Word16 mem_w0; /* weighting filter memory */ Word16 mem_syn[M]; /* ACELP synthesis memory (pe) before post-proc */ Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ Word16 mem_syn2[M]; /* ACELP synthesis memory (pe) after post-proc */ Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ Word16 mem_syn3[M]; - + Word16 q_mem_syn; /* common for all above buffers*/ #ifndef IVAS_FLOAT_FIXED float tilt_code_flt; float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ @@ -1582,7 +1587,9 @@ typedef struct fd_bwe_enc_structure #endif float old_input_lp[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; +#ifndef IVAS_FLOAT_FIXED float old_fdbwe_speech[L_FRAME48k]; +#endif float mem_deemph_old_syn; Word16 old_input_lp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; Word16 old_syn_12k8_16k_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; @@ -2472,9 +2479,9 @@ typedef struct enc_core_structure int16_t nb_bits_header_ace; /* number of bits for the header */ int16_t nb_bits_header_tcx; /* number of bits for the header */ - float preemph_fac_flt; /* Preemphasis factor */ - Word16 preemph_fac; /*Preemphasis factor Q15*/ + Word16 preemph_fac; /*Preemphasis factor Q15*/ #ifndef IVAS_FLOAT_FIXED + float preemph_fac_flt; /* Preemphasis factor */ float gamma_flt; #else Word16 gamma; /* Q15 */ diff --git a/lib_enc/swb_bwe_enc.c b/lib_enc/swb_bwe_enc.c index 8a9cf6cd1f17d8b0e38765683de8e3d94722a77c..f7890511b11a0d2f8dfec56f294a6e5f515caf8d 100644 --- a/lib_enc/swb_bwe_enc.c +++ b/lib_enc/swb_bwe_enc.c @@ -1885,7 +1885,11 @@ void fd_bwe_enc_init( hBWE_FD->mem_old_wtda_swb_fx = 0; #endif +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_FD->old_fdbwe_speech, 0.0f, L_FRAME48k ); +#else + set16_fx( hBWE_FD->old_fdbwe_speech_fx, 0, L_FRAME48k ); +#endif hBWE_FD->mem_deemph_old_syn = 0.0f; return;