diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 93ea0528df7005878bc12fe7267bda44f64dfc97..6439798740e2204c879eaf53fc731c8d21ccbab8 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -383,6 +383,8 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length ); + hFbMixer->q_ppFilterbank_prior_input_fx[i] = Q31; + move16(); } test(); diff --git a/lib_com/lerp.c b/lib_com/lerp.c index 17a39d53c62a1a3808eb33ef420e0a2cebf693cc..96c130491a706d62e0185f39f3ddd3dc75408cb2 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -617,6 +617,7 @@ static void L_lerp_proc_fx( Word32 pos_fx, shift_fx, diff_fx; Word32 buf_fx[2 * L_FRAME_MAX]; Word16 tmp; + Word32 ffxsub; IF( EQ_16( bufferNewSize, bufferOldSize ) ) { @@ -644,8 +645,15 @@ static void L_lerp_proc_fx( ELSE { idx = extract_l( L_shr( pos_fx, 21 ) ); - diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ - buf_fx[0] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[( idx + 1 )], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ + + diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); + ffxsub = L_sub( f_fx[idx + 1], f_fx[idx] ); + + Word64 f_fx64 = W_shl( f_fx[idx], 21 ); + Word64 mult64 = W_mult0_32_32( diff_fx, ffxsub ); + Word64 add64 = W_add( f_fx64, mult64 ); + + buf_fx[0] = W_extract_l( W_shr( add64, 21 ) ); move32(); } @@ -656,8 +664,15 @@ static void L_lerp_proc_fx( idx = extract_l( L_shr( pos_fx, 21 ) ); diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ - buf_fx[i] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ + ffxsub = L_sub( f_fx[idx + 1], f_fx[idx] ); + + Word64 f_fx64 = W_shl( f_fx[idx], 21 ); + Word64 mult64 = W_mult0_32_32( diff_fx, ffxsub ); + Word64 add64 = W_add( f_fx64, mult64 ); + + buf_fx[i] = W_extract_l( W_shr( add64, 21 ) ); move32(); + pos_fx = L_add( pos_fx, shift_fx ); /*Q21*/ } diff --git a/lib_com/prot.h b/lib_com/prot.h index 9bc20ad2d2a6bb72ce85e633f7acf5ea9cc815c2..63e1cd3924dbd9fe7561e24686c98e2fb2b02cdd 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2389,27 +2389,23 @@ ivas_error acelp_core_enc( ); #else ivas_error acelp_core_enc( - Encoder_State *st, /* i/o: encoder state structure */ - /*const*/ float inp[], /* i : input signal of the current frame */ - // const float ener, /* i : residual energy from Levinson-Durbin */ - float A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */ - const float epsP[M + 1], /* i : LP prediction errors */ - float lsp_new[M], /* i : LSPs at the end of the frame */ - float lsp_mid[M], /* i : LSPs in the middle of the frame */ - const int16_t vad_hover_flag, /* i : VAD hangover flag */ - const int16_t attack_flag, /* i : attack flag (GSC or TC) */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_new */ -#ifndef IVAS_FLOAT_FIXED - float *voice_factors, /* o : voicing factors */ -#else - Word16 *voice_factors_fx, /* o : voicing factors Q15 */ -#endif - float old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ - int16_t *unbits, /* o : number of unused bits */ + Encoder_State *st, /* i/o: encoder state structure */ + /*const*/ float inp[], /* i : input signal of the current frame */ + Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */ + const Word32 epsP[M + 1], /* i : LP prediction errors */ + Word16 lsp_new[M], /* i : LSPs at the end of the frame */ + Word16 lsp_mid[M], /* i : LSPs in the middle of the frame */ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 attack_flag, /* i : attack flag (GSC or TC) */ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_new */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 *q_old_syn_12k8_16, + Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ Word16 Q_new ); #endif diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index c2b32022f9f1e61379701f4e6922af314f539c8a..ab9697500ff495a5dcf0eb5b176e89e37b4335dc 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -62,55 +62,39 @@ *--------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error acelp_core_enc( - Encoder_State *st, /* i/o: encoder state structure */ - /*const*/ float inp[], /* i : input signal of the current frame */ - // const float ener, /* i : residual energy from Levinson-Durbin*/ - float A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/ - float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ - const float epsP[M + 1], /* i : LP prediction errors */ - float lsp_new[M], /* i : LSPs at the end of the frame */ - float lsp_mid[M], /* i : LSPs in the middle of the frame */ - const int16_t vad_hover_flag, /* i : VAD hangover flag */ - const int16_t attack_flag, /* i : attack flag (GSC or TC) */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ -#ifndef IVAS_FLOAT_FIXED - float *voice_factors, /* o : voicing factors */ -#else - Word16 *voice_factors_fx, /* o : voicing factors Q15 */ -#endif - float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ - int16_t *unbits, /* o : number of unused bits */ + Encoder_State *st, /* i/o: encoder state structure */ + /*const*/ float inp[], /* i : input signal of the current frame */ + Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ + const Word32 epsP[M + 1], /* i : LP prediction errors */ + Word16 lsp_new[M], /* i : LSPs at the end of the frame */ + Word16 lsp_mid[M], /* i : LSPs in the middle of the frame */ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 attack_flag, /* i : attack flag (GSC or TC) */ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 *q_old_syn_12k8_16, + Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + 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 */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fixed converstions - float old_exc_flt[L_EXC] = { 0 }, *exc; /* excitation signal buffer */ - float lsf_new[M] = { 0 }; /* ISFs at the end of the frame */ - float Aq[NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) quantized for the 4 subframes */ - float syn[L_FRAME16k] = { 0 }; /* synthesis signal buffer */ - float res[L_FRAME16k] = { 0 }; /* Residual signal for FER protection */ -#else - float old_exc_flt[L_EXC], *exc; /* excitation signal buffer */ - float lsf_new[M]; /* ISFs at the end of the frame */ - float Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ - float syn[L_FRAME16k]; /* synthesis signal buffer */ - float res[L_FRAME16k]; /* Residual signal for FER protection */ -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - float exc2[L_FRAME16k]; /* enhanced excitation */ - float Es_pred; /* predicited scaled innovation energy */ - // float tmp_noise; /* NB post-filter long-term noise energy*/ - Word16 tc_subfr; /* TC sub-frame indication */ + 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 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_MA[M], mem_AR[M], Bin_E[L_FFT], Bin_E_old[L_FFT / 2],*/ lsp_new_bck[M], lsp_mid_bck[M], mem_syn_bck[M]; + float mem_syn_bck[M]; float q_env[NUM_ENV_CNG]; Word16 sid_bw = -1; @@ -120,47 +104,30 @@ ivas_error acelp_core_enc( Word16 next_force_sf_bck; Word16 uc_two_stage_flag; Word16 position; - // float tmpF; Word16 ppp_mode, nelp_mode; Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - // float *tdm_Pri_pitch_buf; /* bitstream */ BSTR_ENC_HANDLE hBstr = st->hBstr; #if 1 - // Word16 Q_exc = 0; - move16(); - Word16 A_fx[85], Aw_fx[85]; - 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_fx[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ - Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ - Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ - Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ - Word16 Es_pred_fx; /* predicited scaled innovation energy */ - Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ - - // Word16 tc_subfr_fx; /* TC sub-frame indication */ + 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 */ + Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ + Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ + Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ + Word16 Es_pred_fx; /* predicited scaled innovation energy */ + Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer Q_new */ - // Word16 Q_old_bwe_exc; - Word16 *bwe_exc_fx; /* excitation for SWB TBE Q_new */ - // Word16 allow_cn_step_fx; - // Word16 int_fs_fx; - // Word32 L_epsP[2]; - /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - // Word16 mCb1_fx, pstreaklen_fx; + Word16 *bwe_exc_fx; /* excitation for SWB TBE Q_new */ Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], /*lsf_new_bck_fx[M],*/ lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2]; Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; - // Word16 indice; - // Word16 tmp16; - // Word16 enr_index; - // Word16 enr; #ifdef MSAN_FIX set16_fx( old_bwe_exc_fx, 0, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); set16_fx( old_exc_fx, 0, L_EXC ); - set16_fx( Aq_fx, 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( Aq, 0, NB_SUBFR16k * ( M + 1 ) ); #endif Word16 tilt_code_bck_fx; @@ -177,24 +144,9 @@ ivas_error acelp_core_enc( Word16 *tdm_Pri_pitch_buf_fx; Word16 att_fx; - - Word16 lsp_new_fx[M]; /* i : LSPs at the end of the frame */ - Word16 lsp_mid_fx[M]; /* i : LSPs in the middle of the frame */ - // Word16 old_syn_12k8_16k_fx[L_FRAME16k]; Word16 tmpF_fx; #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 pitch_buf_fx[NB_SUBFR16k] = { 0 }; /* To be removed once this is taken as input arg of function */ - Word16 tmp; - for ( i = 0; i < NB_SUBFR16k; i++ ) - { - // Array is getting modified in chunks of 17 inside. - // So each chunk might have a different Q which is predicted by 1st element. - f2me_buf_16( &A[i * ( M + 1 )], &A_fx[i * ( M + 1 )], &tmp, ( M + 1 ) ); - f2me_buf_16( &Aw[i * ( M + 1 )], &Aw_fx[i * ( M + 1 )], &tmp, ( M + 1 ) ); - } - floatToFixed_arr16( lsp_mid, lsp_mid_fx, 15, M ); - floatToFixed_arr16( lsp_new, lsp_new_fx, 15, M ); Word16 inp_buff[L_FRAME16k + M + 1]; Word16 *inp_fx; inp_fx = &inp_buff[M + 1]; @@ -237,7 +189,6 @@ ivas_error acelp_core_enc( hLPDmem = st->hLPDmem; - Es_pred = 0; Es_pred_fx = 0; move16(); @@ -314,11 +265,7 @@ ivas_error acelp_core_enc( move16(); /* channel-aware mode */ -#ifndef IVAS_FLOAT_FIXED - reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write ); -#else reset_rf_indices_fx( st ); -#endif /* VBR modes */ IF( st->Opt_SC_VBR ) @@ -398,11 +345,11 @@ ivas_error acelp_core_enc( IF( st->rate_switching_reset ) { /*extrapolation in case of unstable LSP*/ - int_lsp4_ivas_fx( st->L_frame, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); } ELSE { - int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, A, M, 0 ); } /* Reset LPC mem */ @@ -416,7 +363,7 @@ ivas_error acelp_core_enc( Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* update Aw[] coefficients */ - weight_a_subfr_fx( shr( st->L_frame, 6 ), A_fx, Aw_fx, st->gamma, M ); + weight_a_subfr_fx( shr( st->L_frame, 6 ), A, Aw, st->gamma, M ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( st->hLPDmem ) @@ -427,17 +374,8 @@ ivas_error acelp_core_enc( 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 ); } - // me2f_buf_16( &st->hLPDmem->old_exc[-M - 1], st->hLPDmem->e_old_exc, &st->hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ); fixedToFloat_arr( &st->hLPDmem->old_exc[-M - 1], &st->hLPDmem->old_exc_flt[-M - 1], Q_new, L_EXC_MEM + M + 1 ); - // me2f_buf_16( old_exc_fx, st->hLPDmem->e_old_exc, old_exc_flt, L_EXC_MEM ); fixedToFloat_arr( old_exc_fx, old_exc_flt, Q_new, L_EXC_MEM ); - for ( i = 0; i < NB_SUBFR16k; i++ ) - { - // Array is getting modified in chunks of 17 inside. - // So each chunk might have a different Q which is predicted by 1st element. - fixedToFloat_arr( &A_fx[i * ( M + 1 )], &A[i * ( M + 1 )], 14 - norm_s( A_fx[i * ( M + 1 )] ), ( M + 1 ) ); - fixedToFloat_arr( &Aw_fx[i * ( M + 1 )], &Aw[i * ( M + 1 )], 14 - norm_s( Aw_fx[i * ( M + 1 )] ), ( M + 1 ) ); - } #endif test(); @@ -466,31 +404,11 @@ ivas_error acelp_core_enc( } #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 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 ); - floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); - floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - for ( i = 0; i < M; i++ ) - { - lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); - } -#endif /* encode CNG parameters */ - CNG_enc_ivas_fx( st, Aq_fx, inp_fx, /*ener_fx,*/ lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); + 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_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - for ( i = 0; i < M; i++ ) - { - lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); - } #endif -#else - cng_params_postupd( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); - - /* encode CNG parameters */ - CNG_enc( st, Aq, inp, ener, lsp_mid, lsp_new, lsf_new, &allow_cn_step, q_env, &sid_bw ); #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -548,15 +466,8 @@ ivas_error acelp_core_enc( #endif 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_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); + 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( Aq_fx, Aq, Q12, ( st->L_frame / L_SUBFR ) * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - for ( i = 0; i < M; i++ ) - { - lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); - } - fixedToFloat_arr( exc_fx, exc, Q_new, st->L_frame ); fixedToFloat_arr( exc2_fx, exc2, Q_new, st->L_frame ); #endif @@ -572,11 +483,8 @@ ivas_error acelp_core_enc( // Word16 Q_exc_l = Q_factor_arr( exc, st->L_frame ); floatToFixed_arr( exc, exc_fx, Q_new, st->L_frame ); #endif - // tmpF = cng_energy( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att, exc, st->L_frame ); 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 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // tmpF = fix16_to_float( tmpfx, Q8 ); -#endif + /* calculate the energy quantization index */ enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ @@ -603,36 +511,21 @@ ivas_error acelp_core_enc( floatToFixed_arr( exc3, exc3_fx, Q_exc_l, st->L_frame ); floatToFixed_arr( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn3, st->Q_syn, M ); - - floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); #endif /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_exc_l, st->Q_syn ); + 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( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); 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 /* reset the encoder */ -#ifndef IVAS_FLOAT_FIXED - CNG_reset_enc( st, pitch_buf, voice_factors, 0 ); /* To be removed once the function is completely fixed */ -#else - CNG_reset_enc_fx( st, hLPDmem, pitch_buf_fx, voice_factors_fx, 0 ); + CNG_reset_enc_fx( st, hLPDmem, pitch_buf, voice_factors_fx, 0 ); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->hLPDmem->mem_w0_flt = 0.0f; - // Reset for st->hLPDmem->mem_syn_flt not needed as flag is 0 - if ( st->L_frame == L_FRAME ) - { - set_f( pitch_buf, (float) L_SUBFR, NB_SUBFR ); - } - else /* st->L_frame == L_FRAME16k */ - { - set_f( pitch_buf, (float) L_SUBFR16k, NB_SUBFR16k ); - } -#endif #endif /* update st->mem_syn1_flt for ACELP core switching */ @@ -648,17 +541,16 @@ ivas_error acelp_core_enc( if ( st->hBWE_FD != NULL ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_syn_12k8_16k_fx[L_FRAME16k]; 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( st->L_frame, syn1, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); - save_old_syn_fx( st->L_frame, syn1_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 ); + 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 ); - fixedToFloat_arr( old_syn_12k8_16k_fx, old_syn_12k8_16k, 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 ); @@ -671,7 +563,6 @@ ivas_error acelp_core_enc( st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif /*Update MODE2 core switching memory*/ - // deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); 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 ); @@ -687,27 +578,11 @@ ivas_error acelp_core_enc( { #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 tdm_lsfQ_PCh_fx[M]; - IF( tdm_lsfQ_PCh ) - { - for ( int ii = 0; ii < M; ii++ ) - { - tdm_lsfQ_PCh_fx[ii] = (Word16) ( ( tdm_lsfQ_PCh[ii] ) * 2.56f ); - } - } - 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( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); - FOR( Word16 idx = 0; idx < M; idx++ ) - { - IF( tdm_lsfQ_PCh ) - tdm_lsfQ_PCh_fx[idx] = (Word16) ( tdm_lsfQ_PCh[idx] * 2.56f ); - } 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 ); @@ -772,11 +647,11 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ - lsf_syn_mem_backup_ivas_fx( st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck, lsp_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen ); + lsf_syn_mem_backup_ivas_fx( st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen ); IF( !tdm_lp_reuse_flag ) { - lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh_fx, Q_new ); + lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new ); } ELSE { @@ -788,11 +663,11 @@ ivas_error acelp_core_enc( Word16 lsf_wgts_fx[M]; /* intra_frame prediction for the LSFs */ - lsp2lsf_fx( lsp_new_fx, lsf_new_fx, M, 12800 ); + lsp2lsf_fx( lsp_new, lsf_new_fx, M, 12800 ); Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], add( Q_new, ( QSCALE - 2 ) ), lsf_new_fx, lsf_wgts_fx, st->bwidth == NB, (Word16) EQ_16( st->coder_type, UNVOICED ), st->sr_core, M ); - tdm_SCh_lsf_reuse_fx( ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts_fx, &beta_index ); + tdm_SCh_lsf_reuse_fx( ENC, st->element_brate, lsf_new_fx, lsp_new, tdm_lsfQ_PCh, lsf_wgts_fx, &beta_index ); push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); } @@ -807,13 +682,13 @@ ivas_error acelp_core_enc( IF( EQ_16( st->active_cnt, 1 ) ) { - Copy( lsp_new_fx, st->lsp_old_fx, M ); // Q15 - lsp2lsf_fx( lsp_new_fx, st->lsf_old_fx, M, st->sr_core ); // Q x2.56 - lsp2lsf_fx( lsp_new_fx, lsf_new_fx, M, st->sr_core ); // Q x2.56 + Copy( lsp_new, st->lsp_old_fx, M ); // Q15 + lsp2lsf_fx( lsp_new, st->lsf_old_fx, M, st->sr_core ); // Q x2.56 + lsp2lsf_fx( lsp_new, lsf_new_fx, M, st->sr_core ); // Q x2.56 } /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 ); + int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new, Aq, M, pt_interp_2_fx, 0 ); /* Check LSF stability (distance between old LSFs and current LSFs) */ st->stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); // Q15 @@ -827,7 +702,7 @@ ivas_error acelp_core_enc( // hLPDmem->e_mem_syn = hLPDmem->e_old_exc; Copy( hLPDmem->old_exc + sub( st->L_frame, M ), hLPDmem->mem_syn, M ); // Copy_Scale_sig( hLPDmem->old_exc + sub( st->L_frame, M ), hLPDmem->mem_syn, M, sub( Q_new, st->prev_Q_new ) ); - Residu3_fx( Aq_fx, hLPDmem->old_exc, old_exc_fx, st->L_frame, 0 ); + Residu3_fx( Aq, hLPDmem->old_exc, old_exc_fx, st->L_frame, 0 ); } test(); @@ -850,7 +725,7 @@ ivas_error acelp_core_enc( * Calculation of LP residual (filtering through A[z] filter) *---------------------------------------------------------------*/ - calc_residu_fx( st, inp_fx, res_fx, Aq_fx ); + calc_residu_fx( st, inp_fx, res_fx, Aq ); calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) ) @@ -894,34 +769,32 @@ ivas_error acelp_core_enc( { IF( LE_16( st->coder_type, UNVOICED ) ) { - tdm_low_rate_enc( st, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new ); + tdm_low_rate_enc( st, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new ); } ELSE /* GENERIC */ { - encod_gen_2sbfr( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new ); + encod_gen_2sbfr( st, inp_fx, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new ); } } ELSE IF( nelp_mode ) { /* SC-VBR - NELP frames */ - encod_nelp_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ); + encod_nelp_ivas_fx( st, inp_fx, Aw, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); } #endif ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ - // encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); - encod_unvoiced_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ); + encod_unvoiced_ivas_fx( st, inp_fx, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); } ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { - // encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); - encod_tran_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new ); + encod_tran_ivas_fx( st, inp_fx, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new ); } ELSE IF( ppp_mode ) { /* SC-VBR - PPP frames */ - IF( ( error = encod_ppp_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) + IF( ( error = encod_ppp_ivas_fx( st, inp_fx, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) { return error; } @@ -929,62 +802,45 @@ ivas_error acelp_core_enc( IF( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ - lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); + lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new, lsp_mid, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); /* Configure ACELP bit allocation */ config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); /* redo LSF quantization */ - lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, 0, NULL, Q_new ); + 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_fx ); + calc_residu_fx( st, inp_fx, res_fx, Aq ); st->hTdCngEnc->burst_ho_cnt = 0; /* VOICED frames in SC-VBR */ - // encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); - encod_gen_voic_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); + encod_gen_voic_ivas_fx( st, inp_fx, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); } } ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ - // encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); - encod_audio_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, shift ); + encod_audio_ivas_fx( st, inp_fx, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, shift ); } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - // encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); - - encod_gen_voic_ivas_fx( st, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); + encod_gen_voic_ivas_fx( st, inp_fx, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); } + FOR( i = 0; i < NB_SUBFR16k; i++ ) + { + Scale_sig( &Aq[i * ( M + 1 )], ( M + 1 ), sub( Q12, sub( Q14, norm_s( Aq[i * ( M + 1 )] ) ) ) ); + } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->mem_deemp_preQ = fixedToFloat( st->mem_deemp_preQ_fx, -1 ); - - fixedToFloat_arr( lsp_new_bck_fx, lsp_new_bck, Q15, M ); - fixedToFloat_arr( lsp_mid_bck_fx, lsp_mid_bck, Q15, M ); fixedToFloat_arr( mem_syn_bck_fx, mem_syn_bck, Q_new, M ); - fixedToFloat_arr( lsp_new_fx, lsp_new, 15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, 15, M ); - for ( i = 0; i < M; i++ ) - { - - lsf_new[i] = lsf_new_fx[i] / 2.56f; - } 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 ); - for ( i = 0; i < NB_SUBFR16k; i++ ) - { - // Array is getting modified in chunks of 17 inside. - // So each chunk might have a different Q which is predicted by 1st element. - fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) ); - } 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 ); - Es_pred = fix16_to_float( Es_pred_fx, Q8 ); 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 ); @@ -992,7 +848,6 @@ ivas_error acelp_core_enc( 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 ); - fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k ); #endif /* update mem_syn1_flt for ACELP core switching */ @@ -1017,11 +872,10 @@ ivas_error acelp_core_enc( 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( st->L_frame, syn, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); 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; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( syn_fx, syn, Q_syn_l, st->L_frame ); - fixedToFloat_arr( old_syn_12k8_16k_fx, old_syn_12k8_16k, 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 ); @@ -1063,29 +917,12 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from float to fix Word16 Q_exc2 = Q_factor_arr( exc2, L_FRAME ); -#ifndef MSAN_FIX - floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME16k ); -#else floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME ); #endif - floatToFixed_arr( Aq, Aq_fx, 12, NB_SUBFR16k * ( M + 1 ) ); - Word32 LepsP[2]; - Word32 epsP_fx[M + 1]; - Word16 e_epsP; - f2me_buf( epsP, epsP_fx, &e_epsP, M + 1 ); - // st->exc_pe_fx = float_to_fix16_thrld( st->exc_pe, st->Q_stat_noise ); - floatToFixed_arr( lsp_new, lsp_new_fx, 15, 16 ); - floatToFixed_arr( lsp_mid, lsp_mid_fx, 15, 16 ); -#endif - LepsP[0] = epsP_fx[2]; - move32(); - LepsP[1] = epsP_fx[16]; - move32(); - stat_noise_uv_enc_ivas_fx( st, LepsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag, Q_exc2 ); + stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_exc2 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from fix to float fixedToFloat_arr( exc2_fx, exc2, Q_exc2, L_FRAME16k ); - fixedToFloat_arr( Aq_fx, Aq, 12, NB_SUBFR16k * ( M + 1 ) ); st->exc_pe = fix16_to_float( st->exc_pe_fx, st->Q_stat_noise ); #endif #endif @@ -1096,36 +933,24 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - -#ifndef MSAN_FIX - Word16 q_syn = Q_factor_arr( syn, L_FRAME16k ); -#else Word16 q_syn = Q_factor_arr( syn, L_FRAME ); -#endif q_syn = min( q_syn, Q_factor_arr( res, L_FRAME16k ) ); -#ifndef MSAN_FIX - floatToFixed_arr16( syn, syn_fx, q_syn, L_FRAME16k ); -#else floatToFixed_arr16( syn, syn_fx, q_syn, L_FRAME ); -#endif - floatToFixed_arr( pitch_buf, pitch_buf_fx, Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float 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_fx, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, q_syn ); -#else - FEC_encode( hBstr, st->acelp_cfg, syn, st->coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate ); + 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 - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - if ( st->L_frame == L_FRAME ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + Copy( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } - else + ELSE { - mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + Copy( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } } @@ -1156,13 +981,8 @@ ivas_error acelp_core_enc( { if ( ( st->last_Opt_SC_VBR == 1 && st->Opt_SC_VBR == 0 ) || ( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag ) ) { -#ifndef IVAS_FLOAT_FIXED - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; - set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); -#else st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); -#endif } if ( !st->Opt_SC_VBR && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) @@ -1173,19 +993,12 @@ ivas_error acelp_core_enc( 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 - -#else - non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED } if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) { -#ifndef IVAS_FLOAT_FIXED - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; -#else st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif } } @@ -1194,17 +1007,6 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( pitch_buf, pitch_buf_fx, Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float - - Es_pred_fx = float_to_fix16( Es_pred, Q8 ); - floatToFixed_arr16( Aq, Aq_fx, 12, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr16( lsp_new, lsp_new_fx, 15, M ); - for ( i = 0; i < M; i++ ) - { - - lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); - }; - floatToFixed_arr( old_exc_flt, old_exc_fx, Q_new, L_EXC ); IF( st->hBWE_TD != NULL ) @@ -1213,7 +1015,7 @@ ivas_error acelp_core_enc( } #endif // IVAS_FLOAT_FIXED_CONVERSIONS - updt_enc_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); + updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->hLPDmem->old_exc, st->hLPDmem->old_exc_flt, Q_new, L_EXC_MEM ); @@ -1223,8 +1025,6 @@ ivas_error acelp_core_enc( } fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Q12 #endif -#else - updt_enc( st, old_exc_flt, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, old_bwe_exc ); #endif // IVAS_FLOAT_FIXED if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && st->core_brate > SID_2k40 ) @@ -1237,7 +1037,7 @@ ivas_error acelp_core_enc( 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 - cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, + 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 ); @@ -1245,33 +1045,13 @@ ivas_error acelp_core_enc( fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q6, HO_HIST_SIZE * L_FFT ); #endif #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Restore - st->hTdCngEnc->ho_circ_ptr = ho_circ_ptr; - st->hTdCngEnc->ho_circ_size = ho_circ_size; - st->hTdCngEnc->cng_buf_cnt = cng_buf_cnt; - for ( int j = 0; j < HO_HIST_SIZE; j++ ) - { - st->hTdCngEnc->cng_brate_buf[j] = cng_brate_buf[j]; - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - - cng_params_upd( lsp_new, exc, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ, ENC, st->hTdCngEnc->ho_env_circ, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); #endif // IVAS_FLOAT_FIXED -#ifndef IVAS_FLOAT_FIXED - if ( st->L_frame == L_FRAME ) - { - /* store LSPs@16k, potentially to be used in CNG@16k */ - mvr2r( st->lsp_old16k, &( st->hTdCngEnc->ho_lsp_circ2[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); - } -#else IF( EQ_16( st->L_frame, L_FRAME ) ) { /* store LSPs@16k, potentially to be used in CNG@16k */ Copy( st->lsp_old16k_fx, &( st->hTdCngEnc->ho_lsp_circ2_fx[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); } -#endif /* set LSP@16k flag for the first buffer */ st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); @@ -1279,11 +1059,7 @@ ivas_error acelp_core_enc( /* efficient DTX hangover control */ if ( st->hTdCngEnc->burst_ho_cnt > 1 ) { -#ifndef IVAS_FLOAT_FIXED - dtx_hangover_control( st, lsp_new ); -#else - dtx_hangover_control_fx( st, lsp_new_fx ); -#endif + dtx_hangover_control_fx( st, lsp_new ); } } @@ -1293,11 +1069,7 @@ ivas_error acelp_core_enc( /* reset in case of bitrate switching in EVS */ if ( st->hSC_VBR != NULL ) { -#ifndef IVAS_FLOAT_FIXED - update_average_rate( st->hSC_VBR, st->core_brate ); -#else update_average_rate_fx( st->hSC_VBR, st->core_brate ); -#endif } } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 2b7f40ce769b5bf8e76167e079179b58799305f1..ef19e31b16495643281449f0ba136f3cd1d06a92 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -18,7 +18,7 @@ *-------------------------------------------------------------------*/ static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); -#ifdef IVAS_FLOAT_FIXED1 +#ifdef IVAS_FLOAT_FIXED static void ivas_find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); #endif #ifdef IVAS_CODE_CPE @@ -291,15 +291,23 @@ static void find_enr_dft_fx( c_fx = L_shr( c_fx, guarded_bits ); WHILE( LE_32( freq, crit_bands_fx[i] ) ) { - BinE_fx[bin_cnt] = W_extract_l( W_shr( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ), 31 ) ); // /* energy */ + Word64 te = ( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ) ); + Word16 te_exp = W_norm( te ); + te = W_shl( te, te_exp ); // 2 * Q_inp_dmx + te_exp + BinE_fx[bin_cnt] = W_extract_h( te ); // 2 * Q_inp_dmx + te_exp - 32 + move32(); g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); tmp_fx = L_sub( Mpy_32_32( c_fx, c_1_fx ), Mpy_32_32( s_fx, s_1_fx ) ); s_fx = L_add( Mpy_32_32( s_fx, c_1_fx ), Mpy_32_32( c_fx, s_1_fx ) ); c_fx = tmp_fx; move32(); - BinE_fx[bin_cnt] = Mpy_32_32( Mpy_32_32( BinE_fx[bin_cnt], norm_val_fx ), g_fx ); /* normalization - corresponds to FFT normalization by 2/L_FFT */ + + Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q31 - gaurded_bits + Word16 ngmult_exp = W_norm( ngmult ); + ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp + BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); - BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], guarded_bits ); // 2 * Q_inp_dmx - 32 - 1 + BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); move32(); @@ -313,8 +321,6 @@ static void find_enr_dft_fx( c_fx = L_shl( c_fx, guarded_bits ); band_fx[i] = Mpy_32_16_r( band_fx[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ move32(); - band_fx[i] = L_shl( band_fx[i], sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); - move32(); band_ener_fx[i] = band_fx[i]; /* per band energy without E_MIN */ move32(); if ( LT_32( band_fx[i], L_shl( E_MIN_Q11_FX, sub( Qout, Q11 ) ) ) ) @@ -351,12 +357,19 @@ static void find_enr_dft_fx( c_fx = L_shr( c_fx, guarded_bits ); WHILE( LT_32( freq, 6399 ) ) { - BinE_fx[bin_cnt] = W_extract_l( W_shr( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ), 31 ) ); + Word64 te = ( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ) ); + Word16 te_exp = W_norm( te ); + te = W_shl( te, te_exp ); // 2 * Q_inp_dmx + te_exp + BinE_fx[bin_cnt] = W_extract_h( te ); // 2 * Q_inp_dmx + te_exp - 32 move32(); g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); - BinE_fx[bin_cnt] = Mpy_32_32( Mpy_32_32( BinE_fx[bin_cnt], norm_val_fx ), g_fx ); + + Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q31 - gaurded_bits + Word16 ngmult_exp = W_norm( ngmult ); + ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp + BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); - BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], guarded_bits ); // Q11 + BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); move32(); @@ -368,7 +381,7 @@ static void find_enr_dft_fx( } c_fx = L_shl( c_fx, guarded_bits ); band_fx[i] = Mpy_32_16_r( band_fx[i], inv_tbl_fx[cnt] ); - band_fx[i] = L_shl( band_fx[i], sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); + move32(); band_ener_fx[i] = band_fx[i]; move32(); if ( LT_32( band_fx[i], L_shl( E_MIN_Q11_FX, sub( Qout, Q11 ) ) ) ) @@ -381,13 +394,11 @@ static void find_enr_dft_fx( /* put bin energies from BinE into Bin_E[L_FFT/2-1] (interpolate 40 Hz bin values to fit into 50 Hz bins) */ /* Last value of Bin_E is handled outside this function*/ assert( bin_cnt == ( STEREO_DFT_N_12k8_ENC / 2 - 1 ) ); - Scale_sig32( BinE_fx, 256, sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 2]; move32(); L_lerp_fx( BinE_fx, Bin_E_fx, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2, &Qout ); MVR2R_WORD32( Bin_E_fx, ptE_fx, VOIC_BINS ); // Qout - /* find the total log energy */ tmp_fx = *Etot_fx; move32(); @@ -396,6 +407,9 @@ static void find_enr_dft_fx( tmp_fx = L_add( tmp_fx, band_fx[i] ); // Qout } *Etot_fx = tmp_fx; + + scale_sig32( band_fx, NB_BANDS, 2 ); + scale_sig32( band_ener_fx, NB_BANDS, 2 ); move32(); return; } @@ -494,8 +508,8 @@ void ivas_analy_sp_fx( r_fft_fx_lc( FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1 ); Scale_sig( pt_fft, L_FFT, -1 ); // Q(-1) /*e_min_scaled = Q_new + QSCALE + 2*/ - find_enr( pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, - add( Q_new, Scale_fac2 ), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); + ivas_find_enr( pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, + add( Q_new, Scale_fac2 ), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); pt_bands += NB_BANDS; pt_fft += L_FFT; } @@ -550,6 +564,168 @@ void ivas_analy_sp_fx( } + return; +} + +void ivas_analy_sp_fx_front( + const Word16 element_mode, /* i : element mode */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 input_Fs, /* i : input sampling rate */ + Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ + const Word16 Q_new, /* i : current scaling exp Q0 */ + Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ + Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ + Word16 *Etot, /* o : total input energy Q8 */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ + Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ + Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ + Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ + Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE */ + Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE + 2)*/ + Word16 *fft_buff /* o : FFT coefficients (Q_new + QSCALE + 2) */ +) +{ + Word16 *pt; + Word16 i_subfr, i; + Word32 *pt_bands; + Word32 Ltmp, LEtot; + Word16 *pt_fft; + Word16 Min_val, Max_val; + Word16 Scale_fac2; + Word16 fft_temp[L_FFT]; + + /*-----------------------------------------------------------------* + * Compute spectrum + * find energy per critical frequency band and total energy in dB + *-----------------------------------------------------------------*/ + + pt_bands = fr_bands; + pt_fft = fft_buff; + LEtot = L_deposit_l( 0 ); + IF( NE_16( element_mode, IVAS_CPE_DFT ) ) + { + FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) + { + pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; + IF( i_subfr != 0 ) + { + pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; + } + + /* Clear 1st value of 1st part, copy 1st value of 2nd part */ + fft_temp[0] = 0; + move16(); + fft_temp[L_FFT / 2] = pt[L_FFT / 2]; + move16(); + Max_val = s_max( fft_temp[0], fft_temp[L_FFT / 2] ); + Min_val = s_min( fft_temp[0], fft_temp[L_FFT / 2] ); + + FOR( i = 1; i < L_FFT / 2; i++ ) + { + /* 1st windowed part */ + fft_temp[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); + move16(); + if ( fft_temp[i] > 0 ) + Max_val = s_max( Max_val, fft_temp[i] ); + if ( fft_temp[i] < 0 ) + Min_val = s_min( Min_val, fft_temp[i] ); + + /* 2nd windowed part */ + fft_temp[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); + move16(); + if ( fft_temp[L_FFT - i] > 0 ) + Max_val = s_max( Max_val, fft_temp[L_FFT - i] ); + if ( fft_temp[L_FFT - i] < 0 ) + Min_val = s_min( Min_val, fft_temp[L_FFT - i] ); + } + + /* Combine -Min_val and Max_val into one */ + Max_val = s_max( negate( Min_val ), Max_val ); + + Scale_fac[i_subfr] = s_min( sub( norm_s( Max_val ), 1 ), 6 ); + move16(); + Scale_fac2 = shl( Scale_fac[i_subfr], 1 ); + Scale_sig( fft_temp, L_FRAME_12k8, Scale_fac[i_subfr] ); + + r_fft_fx_lc( FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1 ); + Scale_sig( pt_fft, L_FFT, -1 ); // Q(-1) + /*e_min_scaled = Q_new + QSCALE + 2*/ + ivas_find_enr( pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, + add( Q_new, Scale_fac2 ), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); + pt_bands += NB_BANDS; + pt_fft += L_FFT; + } + LEtot = L_shl_sat( LEtot, 2 ); // Q_new + Q_SCALE - 2 + } + ELSE + { + Word16 Q_inp_dmx = Q_factor_arrL( hCPE->hStereoDft->DFT[0], STEREO_DFT_N_MAX_ENC ); + floatToFixed_arrL( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], Q_inp_dmx, STEREO_DFT_N_MAX_ENC ); + Word16 Qout = add( Q_new, QSCALE - 2 ); + find_enr_dft_fx( hCPE, input_Fs, hCPE->hStereoDft->DFT_fx[0], pt_bands, lf_E, &LEtot, min_band, max_band, Bin_E, band_energies, Q_inp_dmx, Qout ); + MVR2R_WORD32( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); + MVR2R_WORD32( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); + MVR2R_WORD32( band_energies, band_energies + NB_BANDS, NB_BANDS ); + MVR2R_WORD32( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); + LEtot = L_shl( LEtot, 1 ); + } + Word32 temp32_log; + temp32_log = L_add( BASOP_Util_Log2( L_shr( LEtot, 1 ) ), L_shl( sub( Q31, add( Q_new, QSCALE - Q2 - 1 ) ), Q25 ) ); + temp32_log = Mpy_32_32( temp32_log, 1616142483 ); // log10(x) = log2(x)/log2(10) + /* 10.0 * log10( (float) tmp )*/ + /* 10.0/log2(10) in Q29 = 1616142483*/ + *Etot = extract_l( L_shr( temp32_log, 23 - 8 ) ); // Q8 + + Bin_E[L_FFT / 2 - 1] = Bin_E[L_FFT / 2 - 2]; + move32(); + Bin_E[L_FFT - 1] = Bin_E[L_FFT - 2]; + move32(); + + /* Per-bin log-energy spectrum */ + + FOR( i = 0; i < L_FFT / 2; i++ ) + { + Bin_E_old[i] = Bin_E[i]; + move32(); + /* tmp = (input[i] + input[i+Len]+0.001f)/2.0f */ + // Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE ) ) ), L_add( L_shr( Bin_E[i], 1 ), L_shr( Bin_E[i + L_FFT / 2], 1 ) ) ); + Ltmp = L_shr( L_add( Bin_E[i], Bin_E[i + L_FFT / 2] ), 1 ); // average + if ( Ltmp == 0 ) + { + // Ltmp = L_min( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); + Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); + + if ( EspecdB != NULL ) + { + // temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE ), Q25 ) ); + // EspecdB[i] = -1474; /* log(1e-5) in Q7 */ + EspecdB[i] = -14736; /* log(1e-5) in Q7 */ + move16(); + } + } + else + { + if ( EspecdB != NULL ) + { + temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE - 2 - 1 ), Q25 ) ); + EspecdB[i] = extract_l( L_shr( Mpy_32_32( temp32_log, 1860652798 ), Q22 - Q7 ) ); /*log(x) = log2(x)*logf(2)*/ + /* 10.0*log((float)tmp) */ + /* 10.0*logf(2) in Q28 = 1860652798 */ + + move16(); + } + } + if ( PS != NULL ) + { + PS[i] = Ltmp; + move32(); + } + } + + return; } #endif @@ -561,6 +737,249 @@ void ivas_analy_sp_fx( * The energy is normalized by the number of frequency bins in a channel *------------------------------------------------------------------------*/ +static void ivas_find_enr( + Word16 data[], /* i : fft result */ + Word32 band[], /* o : per band energy Q_new + QSCALE */ + Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ + Word32 *LEtot, /* o : total energy Q_new + QSCALE */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word16 Q_new2, /* i : scaling factor Q0 */ + const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ + Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ + Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ + Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ +) +{ + Word16 i, cnt, shift_to_norm; + Word16 freq, wtmp; + Word16 *ptR, *ptI, diff_scaleP1, diff_scaleM2; + Word16 exp_band; + Word32 Ltmp, Ltmp1; + Word16 voic_band; + Word32 etot; + Word16 exp_etot; + Word32 *tmpptr; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move16(); +#endif + + + ptR = &data[1]; /* first real */ + ptI = &data[L_FFT - 1]; /* first imaginary */ + + /*-----------------------------------------------------------------------------------* + * Scaling needed by band and ptE output + * Wants all energies scaled by Q_new + QSCALE to maintain maximum + * precision on bckr noise in clean speech + * First shift left by Q_new + QSCALE than shift right by 2*Q_new-1 + * shift left (Q_new + QSCALE - (2*Q_new -1)) + * shift left (QSCALE - Q_new + 1) == shift left by (QSCALE+1) - Q_new + *-----------------------------------------------------------------------------------*/ + + diff_scaleP1 = sub( QSCALE + 1 + 1, Q_new2 ); + diff_scaleM2 = sub( QSCALE + 1 - 2, Q_new2 ); + + voic_band = VOIC_BAND_8k; + move16(); + assert( VOIC_BAND == VOIC_BAND_8k ); + + etot = L_deposit_l( 0 ); + exp_etot = 0; + move16(); + + /*-----------------------------------------------------------------* + * For low frequency bins, save per bin energy for the use + * in NS and find_tilt() + *-----------------------------------------------------------------*/ + + freq = BIN_FREQ_FX; + move16(); + FOR( i = 0; i < voic_band; i++ ) /* up to maximum allowed voiced critical band */ + { + tmpptr = Bin_E; + move16(); + Ltmp1 = L_deposit_l( 0 ); + + FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) + { + /*ptE = *ptR * *ptR + *ptI * *ptI */ /* energy */ + Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); // 2 * Qfft + Word16 te_exp = W_norm( te ); + te = W_shl( te, te_exp ); // 2 * Qfft + te_exp + Ltmp = W_extract_h( te ); // 2 * Qfft + te_exp - 32 + + Ltmp = L_shr( Ltmp, sub( te_exp, 32 ) ); + /* *ptE *= 4.0 / (L_FFT*L_FFT) */ + /* normalization - corresponds to FFT normalization by 2/L_FFT */ + BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef BASOP_NOGLOB + *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); +#else /* BASOP_NOGLOB */ + *ptE = L_shl( Ltmp, diff_scaleM2 ); +#endif /* BASOP_NOGLOB */ + move32(); /* scaled by Q_new + QSCALE - 2 */ + BASOP_SATURATE_WARNING_ON_EVS; + /*band[i] += *ptE++;*/ + *Bin_E = *ptE; + move32(); + Bin_E++; + Ltmp1 = L_add( Ltmp1, Ltmp ); + + ptE++; + ptR++; + ptI--; + } + + exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ + wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); + + /* band[i] /= cnt */ /* normalization per frequency bin */ + cnt = (Word16) ( Bin_E - tmpptr ); + shift_to_norm = norm_s( cnt ); + wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); + Ltmp1 = L_deposit_l( wtmp ); + + exp_band = sub( exp_band, shift_to_norm ); + exp_band = sub( diff_scaleP1, exp_band ); + BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef BASOP_NOGLOB + band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); +#else /* BASOP_NOGLOB */ + band[i] = L_shl( Ltmp1, exp_band ); +#endif /* BASOP_NOGLOB */ + move32(); /* band scaled by Q_new + QSCALE */ + BASOP_SATURATE_WARNING_ON_EVS; + + test(); + IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) + { + IF( LT_32( band[i], e_min ) ) + { + Ltmp1 = L_shl( e_min, 0 ); + exp_band = 0; + move16(); + } + + wtmp = sub( exp_band, exp_etot ); + if ( wtmp > 0 ) + { + etot = L_shr( etot, wtmp ); + } + exp_etot = s_max( exp_etot, exp_band ); + etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); + } + + band_energies[i] = band[i]; + move32(); + + band[i] = L_max( band[i], e_min ); + move32(); + } + + IF( EQ_16( BIN_FREQ_FX, 50 ) ) + { + /*-----------------------------------------------------------------* + * Continue compute the E per critical band for high frequencies + *-----------------------------------------------------------------*/ + + FOR( i = voic_band; i < NB_BANDS; i++ ) + { + tmpptr = Bin_E; + move16(); + Ltmp1 = L_deposit_l( 0 ); + + FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) + { + /* *ptE = *ptR * *ptR + *ptI * *ptI */ + Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); + Word16 te_exp = W_norm( te ); + te = W_shl( te, te_exp ); + Ltmp = W_extract_h( te ); + Ltmp = L_shr( Ltmp, sub( te_exp, 32 ) ); + + /* *ptE *= 4.0 / (L_FFT*L_FFT) */ + /* normalization - corresponds to FFT normalization by 2/L_FFT */ + BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef BASOP_NOGLOB + *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); +#else /* BASOP_NOGLOB */ + *Bin_E = L_shl( Ltmp, diff_scaleM2 ); +#endif /* BASOP_NOGLOB */ + move32(); /* scaled by Q_new + QSCALE - 2 */ + BASOP_SATURATE_WARNING_ON_EVS; + Bin_E++; + Ltmp1 = L_add( Ltmp1, Ltmp ); + + ptR++; + ptI--; + } + + exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ + wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); + + /* band[i] /= cnt */ /* normalization per frequency bin */ + cnt = (Word16) ( Bin_E - tmpptr ); + shift_to_norm = norm_s( cnt ); + wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); + Ltmp1 = L_deposit_l( wtmp ); + + exp_band = sub( exp_band, shift_to_norm ); + exp_band = sub( diff_scaleP1, exp_band ); + BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef BASOP_NOGLOB + band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); +#else /* BASOP_NOGLOB */ + band[i] = L_shl( Ltmp1, exp_band ); +#endif + move32(); /* band scaled by Q_new + QSCALE */ + BASOP_SATURATE_WARNING_ON_EVS; + + test(); + IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) + { + IF( LT_32( band[i], e_min ) ) + { + Ltmp1 = L_shl( e_min, 0 ); + exp_band = 0; + move16(); + } + + wtmp = sub( exp_band, exp_etot ); + if ( wtmp > 0 ) + { + etot = L_shr( etot, wtmp ); + } + exp_etot = s_max( exp_etot, exp_band ); + + etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); + } + + band_energies[i] = band[i]; + move32(); + + band[i] = L_max( band[i], e_min ); + move32(); + } + } + + /*-----------------------------------------------------------------* + * Find the total energy over the input bandwidth + *-----------------------------------------------------------------*/ + +#ifdef BASOP_NOGLOB + etot = L_add_sat( *LEtot, L_shl_sat( etot, sub( exp_etot, 4 ) ) ); +#else + etot = L_add( *LEtot, L_shl( etot, sub( exp_etot, 4 ) ) ); +#endif + *LEtot = etot; + move32(); + + + return; +} + static void find_enr( Word16 data[], /* i : fft result */ Word32 band[], /* o : per band energy Q_new + QSCALE */ @@ -797,6 +1216,7 @@ static void find_enr( return; } + #ifdef IVAS_FLOAT_FIXED1 /*------------------------------------------------------------------------* * ivas_find_enr() diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 069bfdd45c793df47b9e3fb02eef727031bac7a4..ffb8c6e0e09782d0cc40ef05b91af1a55c309601 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -409,12 +409,13 @@ void init_coder_ace_plus( #ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); st->hBWE_TD->prev_tilt_para = 0.0f; + set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); #else set16_fx( st->hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); st->hBWE_TD->prev_tilt_para_fx = 0; + set16_fx( st->hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); move16(); #endif - set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); } st->currEnergyHF_fx = 0; diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 6fd08cb57415e36d6c088ad8a2bea1adfed89577..684e9c63179d493574a753524376e2ad80d09525 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -209,12 +209,6 @@ void core_coder_mode_switch_ivas_fx( hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; } } - - IF( st->hBWE_TD != NULL ) - { - set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); - } - st->currEnergyHF_fx = 0; move32(); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 538c7f834fc795c08bd3bb7dbf7a262d771a34ce..9abd16f2e3b3686b8cacaf92d5047097dc25c7d9 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -2264,12 +2264,6 @@ ivas_error init_encoder_ivas_fx( hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; } } - - IF( st->hBWE_TD != NULL ) - { - set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); - } - st->currEnergyHF_fx = 0; move32(); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index e7c55494d3bac123808a02c00635c4ffe0fef455..87a63bf4a074ec570abeca44444e51b03464fe9d 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -124,7 +124,7 @@ ivas_error ivas_core_enc( Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q6 */ #endif int16_t unbits[CPE_CHANNELS]; - float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; + float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M] = { 0 }; #ifdef IVAS_FLOAT_FIXED Word16 tdm_lspQ_PCh_fx[M], tdm_lsfQ_PCh_fx[M]; /* 1 : Q15, 2 : Q2.56 */ #endif @@ -378,14 +378,50 @@ ivas_error ivas_core_enc( if ( st->core == ACELP_CORE ) { /* ACELP core encoder */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 Q_old_syn_12k8_16k; + for ( int ii = 0; ii < M; ii++ ) + { + tdm_lsfQ_PCh_fx[ii] = (Word16) ( ( tdm_lsfQ_PCh[ii] ) * 2.56f ); + } + floatToFixed_arr( lsp_new[n], lsp_new_fx[n], Q15, M ); + floatToFixed_arr( lsp_mid[n], lsp_mid_fx[n], Q15, M ); + Word32 epsP_fx[CPE_CHANNELS][M + 1]; + Word16 e_epsP; + f2me_buf( epsP[n], epsP_fx[n], &e_epsP, M + 1 ); + Word16 tmp; + Word16 A_fx[CPE_CHANNELS][( M + 1 ) * NB_SUBFR16k], Aw_fx[CPE_CHANNELS][( M + 1 ) * NB_SUBFR16k]; + for ( i = 0; i < NB_SUBFR16k; i++ ) + { + // Array is getting modified in chunks of 17 inside. + // So each chunk might have a different Q which is predicted by 1st element. + f2me_buf_16( &A[n][i * ( M + 1 )], &A_fx[n][i * ( M + 1 )], &tmp, ( M + 1 ) ); + f2me_buf_16( &Aw[n][i * ( M + 1 )], &Aw_fx[n][i * ( M + 1 )], &tmp, ( M + 1 ) ); + } +#endif #ifndef IVAS_FLOAT_FIXED if ( ( error = acelp_core_enc( st, inp[n], /*ener[n],*/ A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK ) #else - if ( ( error = acelp_core_enc( st, inp[n], /*ener[n],*/ A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh, Q_new[n] ) ) != IVAS_ERR_OK ) + if ( ( error = acelp_core_enc( st, inp[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ) != IVAS_ERR_OK ) #endif { return error; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( old_syn_12k8_16k_fx[n], old_syn_12k8_16k[n], Q_old_syn_12k8_16k, st->L_frame ); + FOR( Word16 idx = 0; idx < M; idx++ ) + { + tdm_lsfQ_PCh_fx[idx] = (Word16) ( tdm_lsfQ_PCh[idx] * 2.56f ); + } + fixedToFloat_arr( pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); + for ( i = 0; i < NB_SUBFR16k; i++ ) + { + // Array is getting modified in chunks of 17 inside. + // So each chunk might have a different Q which is predicted by 1st element. + fixedToFloat_arr( &A_fx[n][i * ( M + 1 )], &A[n][i * ( M + 1 )], 14 - norm_s( A_fx[n][i * ( M + 1 )] ), ( M + 1 ) ); + fixedToFloat_arr( &Aw_fx[n][i * ( M + 1 )], &Aw[n][i * ( M + 1 )], 14 - norm_s( Aw_fx[n][i * ( M + 1 )] ), ( M + 1 ) ); + } +#endif } if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) @@ -858,10 +894,6 @@ ivas_error ivas_core_enc( } } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st->hBWE_TD != NULL ) - { - floatToFixed_arr16( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); - } 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 @@ -1029,10 +1061,6 @@ ivas_error ivas_core_enc( updt_enc_common_ivas_fx( st ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st->hBWE_TD != NULL ) - { - fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); - } 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 ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 6f4116f2383cc60adfa8822b68297fe4d6b1512a..9e306e67f807f3f9440ea7e73eb055ed7b21c285 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -86,6 +86,20 @@ static Word16 get_zero_flag( Word32 arr[], Word16 len ) } return 0; } +static Word16 norm_arr( + Word16 *arr, + Word16 size /* Q0 */ +) +{ + Word16 q = 15; + move16(); + FOR( Word16 i = 0; i < size; i++ ) + IF( arr[i] != 0 ) + { + q = s_min( q, norm_s( arr[i] ) ); + } + return q; +} #endif #ifndef IVAS_FLOAT_FIXED @@ -1317,7 +1331,8 @@ ivas_error pre_proc_front_ivas_fx( * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) *----------------------------------------------------------------*/ - Word16 scale_factor = sub( getScaleFactor16( st->input_fx - (Word16) ( st->input_Fs / 50 ), (Word16) ( st->input_Fs / 25 ) ), 1 ); + // Word16 scale_factor = sub( getScaleFactor16( st->input_fx - (Word16) ( st->input_Fs / 50 ), (Word16) ( st->input_Fs / 25 ) ), 1 ); + Word16 scale_factor = sub( norm_arr( st->input_fx - (Word16) ( st->input_Fs / 50 ), (Word16) ( st->input_Fs / 25 ) ), 1 ); Word16 q_input = s_min( add( -1, scale_factor ), sub( 16, old_inp_12k8_e ) ); Copy_Scale_sig32_16( st->input32_fx - (Word16) ( st->input_Fs / 50 ), st->input_fx - (Word16) ( st->input_Fs / 50 ), (Word16) ( st->input_Fs / 25 ), add( 16 - 11, q_input ) ); /*scaling down from q11 to q_input*/ Scale_sig( st->mem_decim_fx, 90, sub( q_input, 15 - mem_decim_e ) ); /*scaling from q(15-mem_decim_e) to q_input*/ @@ -1535,29 +1550,59 @@ ivas_error pre_proc_front_ivas_fx( /*-------------------------------------------------------------------------* * Spectral analysis *--------------------------------------------------------------------------*/ -#if 1 /*Fixed implementation disabled due to wrong values*/ +#ifndef IVAS_FLOAT_FIXED analy_sp( element_mode, hCPE, input_Fs, inp_12k8, st->Bin_E, st->Bin_E_old, fr_bands, lf_E, &Etot, st->min_band, st->max_band, band_energies, PS, fft_buff ); #else - Word16 Q_inp_dmx = Q_factor_arrL( hCPE->hStereoDft->DFT[0], STEREO_DFT_N_MAX_ENC ) - 1; - floatToFixed_arrL( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], Q_inp_dmx, STEREO_DFT_N_MAX_ENC ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 *lgBin_E_fx; + Word32 PS_fx[128]; + Word32 band_energies_fx[2 * NB_BANDS] = { 0 }; + lgBin_E_fx = NULL; + if ( st != NULL ) + { + lgBin_E_fx = &st->lgBin_E_fx[0]; + } + if ( hCPE != NULL && hCPE->hStereoDft != NULL ) + { + Word16 Q_inp_dmx = Q_factor_arrL( hCPE->hStereoDft->DFT[0], STEREO_DFT_N_MAX_ENC ) - 1; + floatToFixed_arrL( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], Q_inp_dmx, STEREO_DFT_N_MAX_ENC ); + } Word16 Q_new; Word16 Scale_fac[2]; Q_new = 15 - old_inp_12k8_e; - Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); - ivas_analy_sp_fx( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, Q_new, fr_bands_fx, lf_E_fx, &Etot_16fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx, Q_inp_dmx ); + Word16 tmp16, scale = 0; + if ( hCPE != NULL && hCPE->hStereoDft != NULL ) + { + tmp16 = BASOP_Util_Divide3216_Scale( input_Fs, hCPE->hStereoDft->NFFT, &scale ); + tmp16 = shr( tmp16, negate( add( 1, scale ) ) ); + Word16 gb = find_guarded_bits_fx( tmp16 ); + Q_new -= gb; + } + + floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + QSCALE - 2 - 1, 256 ); + floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_new + QSCALE - 2 - 1, 128 ); +#endif + + Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); + ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ ); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( fr_bands_fx, fr_bands, Q_new + QSCALE + 2, 40 ); - fixedToFloat_arrL( band_energies_fx, band_energies, Q_new + QSCALE + 2, 40 ); - fixedToFloat_arrL( lf_E_fx, lf_E, Q_new + QSCALE, 148 ); - fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, Q_new + QSCALE, 256 ); + fixedToFloat_arrL( fr_bands_fx, fr_bands, Q_new + QSCALE - 1, 40 ); + fixedToFloat_arrL( band_energies_fx, band_energies, Q_new + QSCALE - 1, 40 ); + fixedToFloat_arrL( lf_E_fx, lf_E, Q_new + QSCALE - 2 - 1, 148 ); + fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, Q_new + QSCALE - 2 - 1, 256 ); IF( lgBin_E_fx != NULL ) { fixedToFloat_arr( lgBin_E_fx, st->Bin_E, Q7, 128 ); } - fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, Q_new + QSCALE, 128 ); - fixedToFloat_arrL( PS_fx, PS, Q_new + QSCALE, 128 ); - Etot = fixedToFloat( Etot_16fx, Q8 ); - fixedToFloat_arr( fft_buff_fx, fft_buff, Q_new + QSCALE + Scale_fac[0] - 14, 512 ); + fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, Q_new + QSCALE - 2 - 1, 128 ); + fixedToFloat_arrL( PS_fx, PS, Q_new + QSCALE - 2 - 1, 128 ); + Etot = fixedToFloat( Etot_fx, Q8 ); + // fixedToFloat_arr( fft_buff_fx, fft_buff, Q_new + QSCALE + Scale_fac[0] - 14 -1, 512 ); + for ( int i_sbfr = 0; i_sbfr < 2; i_sbfr++ ) + { + fixedToFloat_arr( fft_buff_fx + i_sbfr * L_FFT, fft_buff + i_sbfr * L_FFT, Q_new + QSCALE + Scale_fac[i_sbfr] - 14 - 1, L_FFT ); + } #endif #endif @@ -1565,7 +1610,7 @@ ivas_error pre_proc_front_ivas_fx( Etot_fx = (Word16) ( Etot * ( 1 << 8 ) ); /*float to fix conversions for wb_vad_ivas_fx*/ - Word16 Q_new = Q_factor_arr( fr_bands, 40 ) + 3; + Q_new = Q_factor_arr( fr_bands, 40 ) + 3; floatToFixed_arrL( fr_bands, fr_bands_fx, Q_new + QSCALE, 40 ); floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); @@ -1703,7 +1748,7 @@ ivas_error pre_proc_front_ivas_fx( * Correlation correction as a function of total noise level *----------------------------------------------------------------*/ - Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); + Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); @@ -1810,8 +1855,7 @@ ivas_error pre_proc_front_ivas_fx( else { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 band_energies_fx[2 * NB_BANDS] = { 0 }; /* energy in critical bands without minimum noise floor E_MIN */ - Word16 band_energies_fx_exp; /* energy in critical bands without minimum noise floor E_MIN */ + Word16 band_energies_fx_exp; /* energy in critical bands without minimum noise floor E_MIN */ Word32 enerBuffer_fx_loc[CLDFB_NO_CHANNELS_MAX] = { 0 }; Word16 enerBuffer_fx_exp; @@ -2372,7 +2416,6 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; - Word32 PS_fx[128]; Word16 Q_esp; Word16 Qfact_PS = Q_factor_arrL( PS, 128 ); floatToFixed_arr32( PS, PS_fx, Qfact_PS, 128 ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 43096d1717d459f8efd6a6684062a5576c04a5c2..d530cbe1df243545bd01a5640f05609275a470ca 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2174,6 +2174,27 @@ void ivas_analy_sp_fx( Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE + 2)*/ Word16 *fft_buff /* o : FFT coefficients (Q_new + QSCALE + 2) */ ); + +void ivas_analy_sp_fx_front( + const Word16 element_mode, /* i : element mode */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 input_Fs, /* i : input sampling rate */ + Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ + const Word16 Q_new, /* i : current scaling exp Q0 */ + Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ + Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ + Word16 *Etot, /* o : total input energy Q8 */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ + Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ + Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ + Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ + Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE */ + Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE + 2)*/ + Word16 *fft_buff /* o : FFT coefficients (Q_new + QSCALE + 2) */ +); #endif void find_wsp_fx( const Word16 Az[], diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 407e2e31c74f671adca7d714196063969493b2f6..ffa8e3a4c0d7866b4e4fb9fbda379acf816d9bbb 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -2062,7 +2062,7 @@ Word16 ivas_smc_gmm_fx( dotp_exp = -17; move16(); } - temp32_log = L_add( BASOP_Util_Log2( L_add( L_shr( temp32, 1 ), L_shr( 10737 /*1e-5f q30*/, dotp_exp ) ) ), L_shl( add( dotp_exp, 1 ), Q25 ) ); + temp32_log = L_add_sat( BASOP_Util_Log2( L_add_sat( L_shr( temp32, 1 ), L_shr( 10737 /*1e-5f q30*/, dotp_exp ) ) ), L_shl( add( dotp_exp, 1 ), Q25 ) ); temp32_log = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ melS_fx[i] = temp32_log; move32(); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 6578311d22f5bb9b1cea4d7c59a9390c4530a77c..a8566fd5402b8885601d3c6a11381b0f9a3e0212 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1510,15 +1510,15 @@ typedef struct td_bwe_enc_structure Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; Word16 prev_Q_bwe_exc_fb; Word16 fb_tbe_demph_fx; - Word16 tilt_mem_fx; /* Q12 */ + Word16 tilt_mem_fx; /* Q12 */ #endif int16_t prev_coder_type; #ifndef IVAS_FLOAT_FIXED float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; -#else float cur_sub_Aq[M + 1]; +#else Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ Word16 prev_tilt_para_fx; /* Q10 */ #endif diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index e8d28590366fa62de56fc8efce3f49362f86f4e5..b62b00be1b412bb3f2ce1aa2aae80b7bb0f486e9 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -189,12 +189,13 @@ void InitSWBencBuffer( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para = 0.0f; + set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 ); #else set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); move16(); #endif - set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 ); /* TD BWE post-processing */ #ifndef IVAS_FLOAT_FIXED