From 249f18ac3dfd654fe658001faa19c06dad5ae8c4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 25 Nov 2024 21:38:45 +0530 Subject: [PATCH] Fix for LTV crashes and float code clean up --- lib_com/ivas_prot.h | 61 ++- lib_com/ivas_spar_com.c | 147 ++++--- lib_com/lpc_tools_fx.c | 91 ++++ lib_com/prot.h | 4 +- lib_com/prot_fx.h | 21 + lib_dec/jbm_pcmdsp_apa.c | 4 +- lib_dec/jbm_pcmdsp_similarityestimation.c | 44 ++ lib_dec/jbm_pcmdsp_similarityestimation.h | 1 + lib_enc/acelp_core_enc.c | 281 ++++++------ lib_enc/cod4t64_fast.c | 7 +- lib_enc/core_enc_init.c | 24 +- lib_enc/core_enc_init_fx.c | 4 + lib_enc/core_enc_switch.c | 6 - lib_enc/core_switching_enc.c | 266 ++++++------ lib_enc/enc_higher_acelp.c | 4 +- lib_enc/gs_enc.c | 6 +- lib_enc/gs_enc_fx.c | 3 +- lib_enc/init_enc.c | 54 ++- lib_enc/init_enc_fx.c | 5 +- lib_enc/ivas_core_enc.c | 159 ++----- lib_enc/ivas_core_pre_proc.c | 495 ++++++++++++++++++++-- lib_enc/ivas_core_pre_proc_front.c | 33 +- lib_enc/ivas_cpe_enc.c | 69 +-- lib_enc/ivas_front_vad.c | 16 +- lib_enc/ivas_ism_enc.c | 43 +- lib_enc/ivas_mdct_core_enc.c | 3 +- lib_enc/ivas_sce_enc.c | 28 +- lib_enc/ivas_stereo_dft_td_itd.c | 2 +- lib_enc/ivas_stereo_mdct_core_enc.c | 8 +- lib_enc/ivas_stereo_switching_enc.c | 12 +- lib_enc/ivas_stereo_td_analysis.c | 10 +- lib_enc/ivas_tcx_core_enc.c | 10 +- lib_enc/multi_harm_fx.c | 2 +- lib_enc/pitch_ol2.c | 17 +- lib_enc/stat_enc.h | 49 ++- lib_enc/swb_bwe_enc.c | 9 +- lib_enc/swb_tbe_enc.c | 6 +- 37 files changed, 1258 insertions(+), 746 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 893defd4e..4aec876ef 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -274,6 +274,7 @@ ivas_error pre_proc_front_ivas_fx( const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ ); +#ifdef IVAS_FLOAT_FIXED ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ const int16_t last_element_mode, /* i : last element mode */ @@ -285,11 +286,11 @@ ivas_error pre_proc_ivas( float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float **inp, /* o : ptr. to inp. signal in the current frame*/ float *ener, /* o : residual energy from Levinson-Durbin */ - float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + Word16 A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ float epsP[M + 1], /* i/o: LP prediction errors */ - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ + Word16 lsp_new[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid[M], /* i/o: LSPs in the middle of the frame */ float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ float old_wsp[], /* i : weighted input signal buffer */ @@ -310,12 +311,39 @@ ivas_error pre_proc_ivas( Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], Word16 e_enerBuffer, Word16 fft_buff_fx[2 * L_FFT], - Word32 cor_map_sum_fx, - Word16 exp_cor_map_sum, + Word16 cor_map_sum_fx, //Q8 Word16 *Q_new #endif ); - +#else +ivas_error pre_proc_ivas( + Encoder_State *st, /* i/o: encoder state structure */ + const int16_t last_element_mode, /* i : last element mode */ + const int32_t element_brate, /* i : element bitrate */ + const int32_t last_element_brate, /* i : last element bitrate */ + const int16_t input_frame, /* i : frame length */ + float old_inp_12k8[], /* i/o: buffer of old input signal */ + float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + float **inp, /* o : ptr. to inp. signal in the current frame*/ + float *ener, /* o : residual energy from Levinson-Durbin */ + float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* i/o: LP prediction errors */ + float lsp_new[M], /* i/o: LSPs at the end of the frame */ + float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ + float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ + const float old_wsp[], /* i : weighted input signal buffer */ + const int16_t loc_harm, /* i : harmonicity flag */ + const float cor_map_sum, /* i : speech/music clasif. parameter */ + const int16_t vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ + const float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ + const float fft_buff[2 * L_FFT], /* i : FFT buffer */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t vad_hover_flag, /* i : VAD hangover flag */ + const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ +); +#endif /*! r: number of clipped samples */ uint32_t ivas_syn_output( float *synth[], /* i/o: float synthesis signal */ @@ -498,18 +526,18 @@ ivas_error ivas_core_enc( float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */ float old_inp_16k[][L_INP], /* i : buffer of old input signal */ 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) unquantized for subframes*/ + Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes*/ 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 */ + Word16 lsp_new[][M], /* i : LSPs at the end of the frame Q15 */ + Word16 lsp_mid[][M], /* i : LSPs in the middle of the frame Q15 */ const int16_t vad_hover_flag[], /* i : VAD hanglover flag */ int16_t attack_flag[], /* i : attack flag (GSC or TC) */ float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ float old_wsp[][L_WSP], /* i : weighted input signal buffer */ const int16_t loc_harm[], /* i : harmonicity flag */ - const float cor_map_sum[], /* i : speech/music clasif. parameter */ + const Word16 cor_map_sum[], /* i : speech/music clasif. parameter Q8 */ const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ float enerBuffer[][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ float fft_buff[][2 * L_FFT], /* i : FFT buffer */ @@ -2449,12 +2477,21 @@ void InternalTCXDecoder( int16_t *gain_tcx_q /* o : quantized global gain (at low bitrates) */ ); +#ifndef IVAS_FLOAT_FIXED void stereo_mdct_core_enc( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ float new_samples[CPE_CHANNELS][L_INP], /* i : new samples */ float old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */ float pitch_buf[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */ ); +#else +void stereo_mdct_core_enc( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + float new_samples[CPE_CHANNELS][L_INP], /* i : new samples */ + float old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */ + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */ +); +#endif void initMdctStereoEncData( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index a79d05945..11ee4b3d6 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -677,11 +677,10 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - Word64 dm_alpha64[IVAS_MAX_NUM_BANDS]; Word64 real64[IVAS_SPAR_MAX_CH - 1]; Word64 re, dm_y; Word16 dm_beta_re_q; - Word16 dm_alpha64_q[IVAS_MAX_NUM_BANDS]; + Word16 dm_alpha_q[IVAS_MAX_NUM_BANDS]; Word16 dm_v_re_q[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_g[IVAS_MAX_NUM_BANDS]; @@ -693,6 +692,7 @@ static void ivas_get_pred_coeffs_enc_fx( Word32 L_tmp1, L_tmp2; Word16 L_tmp1_q, L_tmp2_q; Word16 den_f_e, s_dm_f; + Word16 guard_bits; IF( EQ_16( dyn_active_w_flag, 1 ) ) { @@ -706,67 +706,82 @@ static void ivas_get_pred_coeffs_enc_fx( } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 - set32_fx( dm_alpha, 0, IVAS_MAX_NUM_BANDS ); - set64_fx( dm_alpha64, 0, IVAS_MAX_NUM_BANDS ); - set16_fx( dm_alpha64_q, 31, IVAS_MAX_NUM_BANDS ); - - FOR( i = 1; i < in_chans; i++ ) + guard_bits = sub( find_guarded_bits_fx( in_chans ), 1 ); + FOR( k = start_band; k < end_band; k++ ) { - FOR( k = start_band; k < end_band; k++ ) + IF( cov_real[1][0][k] == 0 ) + { + tmp64 = 0; + move64(); + dm_alpha_q[k] = 127; + move16(); + } + ELSE + { + tmp64 = W_shr( W_mult0_32_32( cov_real[1][0][k], cov_real[1][0][k] ), guard_bits ); // Q = 2 * q_cov_real[1][0][k] - guard_bits + dm_alpha_q[k] = sub( shl( q_cov_real[1][0][k], 1 ), guard_bits ); + move16(); + } + FOR( i = 2; i < in_chans; i++ ) { // IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); - abs_value64 = W_mult0_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q = 2 * q_cov_real[i][0][k] - tmp_shift = W_norm( abs_value64 ); - IF( abs_value64 != 0 ) - { - q_tmp = sub( add( shl( q_cov_real[i][0][k], 1 ), tmp_shift ), 32 ); - } - ELSE - { - q_tmp = 31; - move16(); - } - IF( LT_16( q_tmp, dm_alpha64_q[k] ) ) - { - dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); // Q=q_tmp - move64(); - dm_alpha64_q[k] = q_tmp; - move16(); - } - ELSE + IF( cov_real[i][0][k] != 0 ) { - tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_alpha64_q[k] ); - IF( LT_16( tmp_shift, 63 ) ) + abs_value64 = W_shr( W_mult0_32_32( cov_real[i][0][k], cov_real[i][0][k] ), guard_bits ); // Q = 2 * q_cov_real[i][0][k] - guard_bits + q_tmp = sub( shl( q_cov_real[i][0][k], 1 ), guard_bits ); + tmp_shift = sub( q_tmp, dm_alpha_q[k] ); + + IF( tmp_shift < 0 ) { - dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); // Q=dm_alpha64_q[k] - move64(); + IF( LE_16( tmp_shift, -63 ) ) + { + tmp64 = abs_value64; + move64(); + } + ELSE + { + tmp64 = W_add( W_shl( tmp64, tmp_shift ), abs_value64 ); // Q=q_tmp + } + dm_alpha_q[k] = q_tmp; + move16(); + } + ELSE + { + IF( LE_16( tmp_shift, 63 ) ) + { + tmp64 = W_add( tmp64, W_shr( abs_value64, tmp_shift ) ); // Q=dm_alpha_q[k] + } } } } - } - - FOR( k = start_band; k < end_band; k++ ) - { - tmp_shift = W_norm( dm_alpha64[k] ); - IF( dm_alpha64[k] != 0 ) + IF( tmp64 != 0 ) { - e_tmp = sub( 31, sub( add( dm_alpha64_q[k], tmp_shift ), 32 ) ); + tmp_shift = W_norm( tmp64 ); + e_tmp = sub( 63, add( dm_alpha_q[k], tmp_shift ) ); + dm_alpha[k] = Sqrt32( W_extract_h( W_shl( tmp64, tmp_shift ) ), &e_tmp ); // Q=31-e_tmp + move32(); + dm_alpha_q[k] = sub( 31, e_tmp ); + move16(); + + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 Q31*/, dm_alpha[k], &s_div ); // Q=15-(dm_alpha_q[k]+ s_div-31) + move16(); + + div_factor_e[k] = sub( add( dm_alpha_q[k], s_div ), 31 ); + move16(); } ELSE { - e_tmp = 0; + dm_alpha[k] = 0; + move32(); + dm_alpha_q[k] = 31; move16(); - } - dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp - move32(); - dm_alpha64_q[k] = sub( 31, e_tmp ); - move16(); - div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 Q31*/, L_max( dm_alpha[k], 1 ), &s_div ); // Q=15-(dm_alpha64_q[k]+ s_div-31) - move16(); + div_factor[k] = 22204; + move16(); - div_factor_e[k] = sub( add( dm_alpha64_q[k], s_div ), 31 ); - move16(); + div_factor_e[k] = -37; + move16(); + } } FOR( i = 0; i < pred_dim; i++ ) @@ -903,16 +918,16 @@ static void ivas_get_pred_coeffs_enc_fx( dm_w = cov_real[0][0][b]; // q_cov_real[0][0][b] move32(); den_f = L_max( dm_w, 1 ); // q_cov_real[0][0][b] - passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha64_q[b] - q_cov_real[0][0][b] + 15 - s_div + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha_q[b] - q_cov_real[0][0][b] + 15 - s_div - div_shift = sub( Q29, add( sub( dm_alpha64_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); + div_shift = sub( Q29, add( sub( dm_alpha_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); passive_g = L_shl_sat( passive_g, div_shift ); // Q = 29 IF( EQ_16( dyn_active_w_flag, 1 ) ) { dm_alpha[b] = 0; move32(); - dm_alpha64_q[b] = 0; + dm_alpha_q[b] = 0; move16(); dm_w = 0; move32(); @@ -985,10 +1000,10 @@ static void ivas_get_pred_coeffs_enc_fx( den_f = L_max( den_f, 1 ); // q_tmp + tmp_shift - 32 - DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha64_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div + DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div move32(); - DM_F_q[b] = add( sub( sub( dm_alpha64_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); + DM_F_q[b] = add( sub( sub( dm_alpha_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); move16(); IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) // q30 @@ -1025,7 +1040,7 @@ static void ivas_get_pred_coeffs_enc_fx( L_tmp2 = W_extract_h( tmp64 ); // Q=q_tmp+tmp_shift-32 L_tmp2_q = sub( add( q_tmp, tmp_shift ), 32 ); - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); // Q=dm_alpha64_q[b]+DM_F_q[b] + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); // Q=dm_alpha_q[b]+DM_F_q[b] tmp_shift = sub( W_norm( tmp64 ), 2 ); IF( tmp64 == 0 ) { @@ -1034,10 +1049,10 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q[b]+DM_F_q[b]+tmp_shift + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha_q[b]+DM_F_q[b]+tmp_shift } - L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); + L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha_q[b] ), tmp_shift ), 32 ); IF( LT_16( L_tmp2_q, L_tmp1_q ) ) { @@ -1083,15 +1098,15 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( norm_l( dm_alpha[b] ), 1 ); - IF( LT_16( L_tmp2_q, add( dm_alpha64_q[b], tmp_shift ) ) ) + IF( LT_16( L_tmp2_q, add( dm_alpha_q[b], tmp_shift ) ) ) { - L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q + L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha_q[b], L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q L_tmp1_q = L_tmp2_q; move16(); } ELSE { - L_tmp1_q = add( dm_alpha64_q[b], tmp_shift ); + L_tmp1_q = add( dm_alpha_q[b], tmp_shift ); L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp1_q } @@ -1107,7 +1122,7 @@ static void ivas_get_pred_coeffs_enc_fx( Word16 num_f_e; /* quadratic activeW */ - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); // Q=dm_alpha64_q[b]+29 + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); // Q=dm_alpha_q[b]+29 tmp_shift = sub( W_norm( tmp64 ), 1 ); IF( tmp64 == 0 ) { @@ -1116,15 +1131,15 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q+29+tmp_shift + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha_q+29+tmp_shift } - L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); // Q=dm_alpha64_q+29+1+tmp_shift-32 + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha_q[b] ), tmp_shift ), 32 ); // Q=dm_alpha_q+29+1+tmp_shift-32 num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); // Q=31-num_f_e - sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 - val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); // q=31-val_e sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ) /* reducing the Q by 2 instead of multiplication by 4*/, &val_e ); // q=31-val_e // val_e = norm_l( sqrt_val ); diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index b1bbbae7b..b23dcc9b2 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -163,6 +163,97 @@ void autocorr_fx( *Q_r = sub( norm, shl( shift, 1 ) ); move16(); } + +void autocorr_ivas_fx( + const Word16 x[], /* i : Input signal Qx */ + const Word16 Qx, /* i : Q facor of Input signal Q0 */ + const Word16 m, /* i : LPC order Q0 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ + const Word16 len, /* i : Frame lenght */ + const Word16 *wind, /* i : Window used */ + const Word16 rev_flag, /* i : flag to reverse window */ + const Word16 sym_flag, /* i : symmetric window flag */ + const Word16 no_thr /* i : flag to avoid thresholding */ +) +{ + Word16 i, j, norm, y[MAX_LEN_LP]; + Word64 W_sum, W_temp; + + IF( EQ_16( rev_flag, 1 ) ) + { + /* Windowing of signal */ + FOR( i = 0; i < len; i++ ) + { + y[i] = mult_r( x[i], wind[len - i - 1] ); // Qx + move16(); + } + } + ELSE IF( EQ_16( sym_flag, 1 ) ) + { + /* symmetric window of even length */ + FOR( i = 0; i < len / 2; i++ ) + { + y[i] = mult_r( x[i], wind[i] ); // Qx + move16(); + } + FOR( ; i < len; i++ ) + { + y[i] = mult_r( x[i], wind[len - i - 1] ); // Qx + move16(); + } + } + ELSE /* assymetric window */ + { + FOR( i = 0; i < len; i++ ) + { + y[i] = mult_r( x[i], wind[i] ); // Qx + move16(); + } + } + + /* calculate energy of signal */ + /* Compute and normalize r[0] */ + W_sum = W_mult0_16_16( y[0], y[0] ); + FOR( i = 1; i < len; i++ ) + { + W_sum = W_mac0_16_16( W_sum, y[i], y[i] ); // 2*Qx + } + /*if (r[0] < 100.0f && no_thr == 0) + { + r[0] = 100.0f; + }*/ + W_temp = W_shl( 1000, shl( Qx, 1 ) ); // 2*Qx + IF( LE_64( W_sum, W_temp ) && no_thr == 0 ) + { + W_sum = W_temp; // 1000.0f in 2*Qx + } + + norm = W_norm( W_sum ); + W_sum = W_shl( W_sum, norm ); // 2*Qx+norm + + *Q_r = add( shl( Qx, 1 ), sub( norm, 32 ) ); // 2*Qx+norm-32 + move16(); + + L_Extract( W_extract_h( W_sum ), &r_h[0], &r_l[0] ); /* Put in DPF format (see oper_32b) */ // *Q_r + + /* Compute r[1] to r[m] */ + FOR( i = 1; i <= m; i++ ) + { + W_sum = W_mult0_16_16( y[0], y[i] ); + FOR( j = 1; j < len - i; j++ ) + { + W_sum = W_mac0_16_16( W_sum, y[j], y[j + i] ); + } + + W_sum = W_shl( W_sum, norm ); // 2*Qx+norm-32 + L_Extract( W_extract_h( W_sum ), &r_h[i], &r_l[i] ); /* Put in DPF format (see oper_32b) */ // *Q_r + } + + return; +} + #ifdef IVAS_FLOAT_FIXED void autocorr_fx_32( const Word16 x[], /* i : Input signal Q(q_x) */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 63e1cd392..17abc65e8 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2390,7 +2390,7 @@ 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 Word16 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 */ @@ -6020,7 +6020,7 @@ void core_switching_post_enc( // const float *old_inp_16k, /* i : old input signal @16kHz */ float *old_inp_16k, /* i : old input signal @16kHz */ // const float A[] /* i : unquant. LP filter coefs. */ - float A[], /* i : unquant. LP filter coefs. */ + Word16 A_fx[], /* i : unquant. LP filter coefs. */ Word16 Q_new ); #endif ivas_error core_switching_post_dec( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index efb1ff681..64650f629 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1102,6 +1102,20 @@ void autocorr_fx( const Word16 sym_flag /* i : symmetric window flag */ ); +void autocorr_ivas_fx( + const Word16 x[], /* i : Input signal Qx */ + const Word16 Qx, /* i : Q facor of Input signal Q0 */ + const Word16 m, /* i : LPC order Q0 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ + const Word16 len, /* i : Frame lenght */ + const Word16 *wind, /* i : Window used */ + const Word16 rev_flag, /* i : flag to reverse window */ + const Word16 sym_flag, /* i : symmetric window flag */ + const Word16 no_thr /* i : flag to avoid thresholding */ +); + void autocorr_fx_32( const Word16 x[], /* i : Input signal Q(q_x) */ const Word16 m, /* i : LPC order Q0 */ @@ -11128,4 +11142,11 @@ void configureCldfb_ivas_enc_fx( const Word32 sampling_rate /* i : sampling rate */ ); +void core_switching_post_enc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 *old_inp_12k8_fx, /* i : old input signal @12.8kHz */ + Word16 *old_inp_16k_fx, /* i : old input signal @16kHz */ + Word16 A_fx[], /* i : unquant. LP filter coefs. */ + Word16 Q_new ); + #endif diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 4eff4ad5e..92aee035e 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -1769,7 +1769,7 @@ static bool shrink_frm_ivas_fx( } /* calculate overlap position */ - IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) + IF( isSilence_ivas_fx( frm_in_fx, Q_frm_in, l_seg, 10 ) ) { /* maximum scaling */ energy_fx = -65 * ( 1 << 8 ); // Q8 @@ -2304,7 +2304,7 @@ static bool extend_frm_ivas_fx( IF( over[n] ) { /* calculate overlap position */ - IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) + IF( isSilence_ivas_fx( frm_in_fx, Q_frm_in, l_seg, 10 ) ) { /* maximum scaling */ energy_fx = -65 * ( 1 << 8 ); // Q8 diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.c b/lib_dec/jbm_pcmdsp_similarityestimation.c index 6bf8c5c90..259213dac 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.c +++ b/lib_dec/jbm_pcmdsp_similarityestimation.c @@ -361,4 +361,48 @@ Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ) } return ret; } + +Word8 isSilence_ivas_fx( const Word16 *signal, Word16 q_sig, Word16 len, Word16 segments ) +{ + Word16 i, j, samplesPerSegment; + Word64 energy, maxEnergy; + Word16 sig_shift = shl( q_sig, 1 ); + + assert( len > 0 ); + assert( segments > 0 ); + + /* Every segment is checked using the following formula: + * 10 * log10(sum_i(signal[i] / 32768.0 *signal[i] / 32768.0)) / samples_per_segment) > -65 + * For simplification/complexity, this is replaced by: + * sum_i(signal[i] / 32768.0 * signal[i] / 32768.0) / samples_per_segment > 10^(-65 / 10) + * sum_i(signal[i] * signal[i]) > 10^(-65 / 10) * 32768.0 * 32768.0 * samples_per_segment + */ + + energy = 0; + move64(); + samplesPerSegment = idiv1616U( len, segments ); + maxEnergy = W_shl( W_mac0_16_16( 0, samplesPerSegment, 340 ), sig_shift ); /* 340 = 10^(-65.0 / 10) * 32768 * 32768.0 */ + j = samplesPerSegment; + move16(); + /* check all but last segment */ + FOR( i = 0; i < len; i++ ) + { + /* division by 32768 is done later */ + energy = W_mac0_16_16( energy, signal[i], signal[i] ); + /* check energy of current segment + * => energy > samplesPerSegment * 10 ^ (-65 / 10) * 32768 * 32768.0*/ + IF( GT_64( energy, maxEnergy ) ) + { + return 0; + } + IF( EQ_16( i, j ) ) + { + energy = 0; + move64(); + j = add( j, samplesPerSegment ); + } + } + + return 1; +} #endif diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 7e18c3394..1ce86fc9a 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -179,6 +179,7 @@ Word32 cross_correlation_self_fx( const Word16 *signal, Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ); +Word8 isSilence_ivas_fx( const Word16 *signal, Word16 q_sig, Word16 len, Word16 segments ); #endif /* IVAS_FLOAT_FIXED */ #endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 1bfffd102..d77d4b42b 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -63,7 +63,7 @@ #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 Word16 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 */ @@ -133,39 +133,37 @@ ivas_error acelp_core_enc( Word16 att_fx; Word16 tmpF_fx; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 inp_buff[L_FRAME16k + M + 1]; - Word16 *inp_fx; - inp_fx = &inp_buff[M + 1]; - Word16 q_comm_Bin /*, Q_new*/ /* Q_new will be later passed from parent function as arg */; - q_comm_Bin = Q_new + QSCALE - 2; - + test(); + IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) + { + Scale_sig( st->hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2, sub( Q_new, st->prev_Q_new ) ); // Q_new + } IF( st->hLPDmem ) { - Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); + Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); // Q_new st->hLPDmem->q_lpd_old_exc = Q_new; move16(); - Scale_sig( st->hLPDmem->syn, M + 1, sub( Q_new, st->hLPDmem->q_lpd_syn ) ); + Scale_sig( st->hLPDmem->syn, M + 1, sub( Q_new, st->hLPDmem->q_lpd_syn ) ); // Q_new 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 ) ); + Scale_sig( st->hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 + st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 move16(); st->hLPDmem->q_mem_syn = sub( Q_new, 1 ); move16(); } - IF( st->hBWE_TD ) - { - floatToFixed_arr( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, Q_new, PIT16k_MAX * 2 ); - } - floatToFixed_arr( &inp[-M - 1], &inp_fx[-M - 1], Q_new - 1, L_FRAME16k + M + 1 ); - floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_new + Q_SCALE - 2, 128 ); - floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, 256 ); -#endif + + Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); // Q_new + Q_scale - 2 + st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 ); + move16(); + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); // Q_new + Q_scale - 2 + st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); + move16(); + ivas_error error; error = IVAS_ERR_OK; @@ -190,7 +188,7 @@ ivas_error acelp_core_enc( 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 ) ); + Scale_sig( old_exc_fx, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); // Q_new IF( st->hBWE_TD != NULL ) { bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ @@ -307,7 +305,6 @@ ivas_error acelp_core_enc( test(); test(); - IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { /* in case of switching, do not apply BPF (flag employed also in updt_enc()) */ @@ -328,7 +325,7 @@ ivas_error acelp_core_enc( { st->rate_switching_reset = st->rate_switching_reset_16kHz; move16(); - Copy( st->lsp_old16k_fx, st->lsp_old_fx, M ); + Copy( st->lsp_old16k_fx, st->lsp_old_fx, M ); // Q15 } /* convert old quantized LSF vector */ @@ -379,18 +376,16 @@ ivas_error acelp_core_enc( /*----------------------------------------------------------------* * Encoding of CNG frames *----------------------------------------------------------------*/ - + test(); IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { - if ( st->cng_type == LP_CNG ) + IF( EQ_16( st->cng_type, LP_CNG ) ) { /* Run CNG post parameter update */ -#ifdef IVAS_FLOAT_FIXED - 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 ); -#endif + CNG_enc_ivas_fx( st, Aq, inp, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate, @@ -430,18 +425,15 @@ ivas_error acelp_core_enc( move16(); generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq_flt, Q_new, ( L_FRAME32k / 2 + 64 ) ); -#endif - + st->hTcxEnc->q_Txnq = Q_new; + move16(); 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 ); Copy( exc2_fx, exc3_fx, st->L_frame ); - if ( st->core_brate == SID_2k40 ) + IF( EQ_32( st->core_brate, SID_2k40 ) ) { - if ( st->hTdCngEnc != NULL ) + IF( st->hTdCngEnc != NULL ) { Word16 enr, enr_index; 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 ); @@ -466,18 +458,18 @@ ivas_error acelp_core_enc( move16(); } - 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 ) ); + Scale_sig( st->hLPDmem->mem_syn, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( st->hLPDmem->mem_syn2, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( st->hLPDmem->mem_syn3, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn + st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn move16(); st->hLPDmem->q_mem_syn = st->Q_syn; move16(); /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_new - 1, st->Q_syn ); + syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, sub( Q_new, 1 ), st->Q_syn ); /* reset the encoder */ CNG_reset_enc_fx( st, hLPDmem, pitch_buf, voice_factors_fx, 0 ); @@ -492,19 +484,16 @@ ivas_error acelp_core_enc( 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 ) + 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( 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 ) ); -#endif + st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); + move16(); + Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); 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 - 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 ) ); -#endif + st->hBWE_FD->q_mem_deemph_old_syn = st->Q_syn; + move16(); } Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); @@ -513,7 +502,7 @@ ivas_error acelp_core_enc( /*Update MODE2 core switching memory*/ deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); - Copy( syn1_fx + st->L_frame - M - 1, hLPDmem->syn, M + 1 ); + Copy( syn1_fx + add( st->L_frame, -M - 1 ), hLPDmem->syn, M + 1 ); } /*----------------------------------------------------------------* @@ -521,12 +510,7 @@ ivas_error acelp_core_enc( *----------------------------------------------------------------*/ ELSE { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->mem_deemp_preQ_fx = (Word16) floatToFixed( st->mem_deemp_preQ, -1 ); - 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 + /*-----------------------------------------------------------------* * Configure ACELP bit allocation *-----------------------------------------------------------------*/ @@ -549,6 +533,7 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ test(); + test(); #ifdef NON_BE_FIX_807_MASA_DTX_BRSW IF( st->hDtxEnc != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) ) #else @@ -635,9 +620,7 @@ ivas_error acelp_core_enc( /* Prepare ACB memory from last HQ frame */ tmpF_fx = hLPDmem->old_exc[0]; PREEMPH_FX( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF_fx ); - // 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, hLPDmem->old_exc, old_exc_fx, st->L_frame, 0 ); } @@ -653,15 +636,13 @@ ivas_error acelp_core_enc( { lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); } - // Q_old_bwe_exc = Q_exc; - move16(); } /*---------------------------------------------------------------* * Calculation of LP residual (filtering through A[z] filter) *---------------------------------------------------------------*/ - calc_residu_fx( st, inp_fx, res_fx, Aq ); + calc_residu_fx( st, inp, res_fx, Aq ); calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) ) @@ -694,11 +675,6 @@ ivas_error acelp_core_enc( /*------------------------------------------------------------* * Encode excitation according to coding type *------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 shift; - shift = 0; - move16(); -#endif test(); test(); IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ @@ -709,28 +685,28 @@ ivas_error acelp_core_enc( } ELSE /* GENERIC */ { - 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 ); + encod_gen_2sbfr( st, inp, 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, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); + encod_nelp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ); } -#endif + ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ - 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 ); + encod_unvoiced_ivas_fx( st, inp, 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, 0 ); } ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { - 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 ); + encod_tran_ivas_fx( st, inp, 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, 0, Q_new ); } ELSE IF( ppp_mode ) { /* SC-VBR - PPP frames */ - 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 ) + IF( ( error = encod_ppp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -746,34 +722,28 @@ 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_fx( st, inp_fx, res_fx, Aq ); + calc_residu_fx( st, inp, res_fx, Aq ); st->hTdCngEnc->burst_ho_cnt = 0; - + move16(); /* VOICED frames in SC-VBR */ - 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 ); + encod_gen_voic_ivas_fx( st, inp, 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, 0, 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_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 ); + encod_audio_ivas_fx( st, inp, 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, 0 ); } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - 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 ); + encod_gen_voic_ivas_fx( st, inp, 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, 0, 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 )] ) ) ) ); + Scale_sig( &Aq[i * ( M + 1 )], ( M + 1 ), sub( Q12, sub( Q14, norm_s( Aq[i * ( M + 1 )] ) ) ) ); // Q12 } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->mem_deemp_preQ = fixedToFloat( st->mem_deemp_preQ_fx, -1 ); - 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 ); - 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 ); -#endif /* update mem_syn1_flt for ACELP core switching */ Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); @@ -783,26 +753,18 @@ ivas_error acelp_core_enc( 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 ) + IF( st->hBWE_FD != NULL ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_syn_12k8_16k_fx[L_FRAME16k]; - 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( 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 ) ); -#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 - 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 ) ); -#endif + st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); + move16(); + Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); + + save_old_syn_fx( st->L_frame, syn_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 = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); + move16(); + st->hBWE_FD->q_mem_deemph_old_syn = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); + move16(); + Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ) ); } /*Update MODE2 core switching memory*/ @@ -815,29 +777,30 @@ ivas_error acelp_core_enc( /*Update MODE2 core switching memory*/ deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); - Copy( syn1_fx + st->L_frame - M - 1, hLPDmem->syn, M + 1 ); + Copy( syn1_fx + add( 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 ); - fixedToFloat_arr( syn1_fx + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->Q_syn, st->L_frame / 2 ); + Copy( syn1_fx + shr( st->L_frame, 1 ), st->hTcxEnc->Txnq, shr( st->L_frame, 1 ) ); + Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 2 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) ); + st->hTcxEnc->q_Txnq = st->Q_syn; + move16(); } /*--------------------------------------------------------------------------------------* * Modify the excitation signal when the noise is stationary *--------------------------------------------------------------------------------------*/ - - if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + test(); + test(); + test(); + test(); + IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ 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 - st->exc_pe = fix16_to_float( st->exc_pe_fx, st->Q_stat_noise ); -#endif } /*-----------------------------------------------------------------* @@ -865,16 +828,17 @@ ivas_error acelp_core_enc( /*-----------------------------------------------------------------* * Write ACELP unused bits *-----------------------------------------------------------------*/ - - if ( st->core_brate != SID_2k40 && st->core_brate != FRAME_NO_DATA && st->core_brate != PPP_NELP_2k80 ) + test(); + test(); + IF( NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, PPP_NELP_2k80 ) ) { nBits = st->acelp_cfg.ubits; - - while ( nBits > 0 ) + move16(); + WHILE( nBits > 0 ) { - i = min( nBits, 16 ); + i = s_min( nBits, 16 ); push_indice( hBstr, IND_UNUSED, 0, i ); - nBits -= i; + nBits = sub( nBits, i ); } } @@ -882,56 +846,68 @@ ivas_error acelp_core_enc( * Apply non linearity in case of SWB TBE *-----------------------------------------------------------------*/ - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - 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 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->last_Opt_SC_VBR, 1 ) && st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move16(); set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } - 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 ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( !st->Opt_SC_VBR && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) { /* Apply a non linearity to the SHB excitation */ -#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 ); 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 } - if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + test(); + if ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move16(); } } /*-----------------------------------------------------------------* * Updates *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( st->hBWE_TD != NULL ) { st->Q_exc = Q_new; + move16(); } -#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 - 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 ); - } - fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Q12 -#endif -#endif // IVAS_FLOAT_FIXED + move16(); - if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && st->core_brate > SID_2k40 ) + test(); + test(); + IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && GT_32( st->core_brate, SID_2k40 ) ) { /* update CNG parameters in active frames */ Word16 q_exc = st->hTdCngEnc->cng_Qexc_buf[0]; + move16(); FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) { q_exc = s_min( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ); @@ -943,6 +919,7 @@ ivas_error acelp_core_enc( { 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(); } 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, @@ -956,17 +933,24 @@ ivas_error acelp_core_enc( } /* 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 ); - + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = 0; + } + ELSE + { + st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = 1; + } + move16(); /* efficient DTX hangover control */ - if ( st->hTdCngEnc->burst_ho_cnt > 1 ) + IF( GT_16( st->hTdCngEnc->burst_ho_cnt, 1 ) ) { dtx_hangover_control_fx( st, lsp_new ); } } /* SC-VBR update of average data rate */ - if ( st->vad_flag == 1 ) + IF( EQ_16( st->vad_flag, 1 ) ) { /* reset in case of bitrate switching in EVS */ if ( st->hSC_VBR != NULL ) @@ -974,9 +958,8 @@ ivas_error acelp_core_enc( update_average_rate_fx( st->hSC_VBR, st->core_brate ); } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->prev_Q_new = Q_new; -#endif + move16(); pop_wmops(); return error; diff --git a/lib_enc/cod4t64_fast.c b/lib_enc/cod4t64_fast.c index 51cc780c3..3b68230f5 100644 --- a/lib_enc/cod4t64_fast.c +++ b/lib_enc/cod4t64_fast.c @@ -1017,8 +1017,11 @@ void acelp_fast_fx( FOR( i = 0; i < L_subfr; i += nb_tracks ) { - cncn_track[q] = BASOP_Util_Add_Mant32Exp( cncn_track[q], cncn_track_e[q], L_mult0( cn[i + q], cn[i + q] ), exp1, &cncn_track_e[q] ); // Q(cncn_track_e[q]) - move16(); + Word32 L_tmp = L_mult0( cn[i + q], cn[i + q] ); + shift = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, shift ); + cncn_track[q] = BASOP_Util_Add_Mant32Exp( cncn_track[q], cncn_track_e[q], L_tmp, sub( exp1, shift ), &cncn_track_e[q] ); // Q(cncn_track_e[q]) + move32(); } cncn_fx = BASOP_Util_Add_Mant32Exp( cncn_fx, cncn_e, cncn_track[q], cncn_track_e[q], &cncn_e ); // Q(cncn_e) } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 0f8a533f3..02f6a2ad8 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -122,6 +122,8 @@ void init_coder_ace_plus_ivas_fx( { set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); hTcxEnc->acelp_zir = hTcxEnc->Txnq + L_FRAME / 2; + hTcxEnc->q_Txnq = Q15; + move16(); hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14; move16(); } @@ -364,9 +366,9 @@ void init_coder_ace_plus( if ( st->ini_frame == 0 ) { +#ifndef IVAS_FLOAT_FIXED set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; -#ifndef IVAS_FLOAT_FIXED hTcxEnc->tcx_target_bits_fac_flt = 1.0f; #else hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14; @@ -375,6 +377,8 @@ void init_coder_ace_plus( #ifdef IVAS_FLOAT_FIXED set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); hTcxEnc->acelp_zir = hTcxEnc->Txnq + L_FRAME / 2; + hTcxEnc->q_Txnq = Q15; + move16(); #endif } } @@ -1223,17 +1227,17 @@ static void init_acelp( if ( st->hTcxEnc != NULL ) { - set_zero( st->hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); - st->hTcxEnc->acelp_zir_flt = st->hTcxEnc->Txnq_flt + ( st->L_frame / 2 ); - #ifdef IVAS_FLOAT_FIXED set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 ); + st->hTcxEnc->q_Txnq = Q15; + move16(); #endif } } else /*Rate switching*/ { +#ifndef IVAS_FLOAT_FIXED if ( st->hTcxEnc != NULL ) { if ( st->last_core == ACELP_CORE ) @@ -1250,7 +1254,7 @@ static void init_acelp( st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 ); #endif } - +#endif /* Rate switching */ if ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO ) { @@ -1264,7 +1268,13 @@ static void init_acelp( if ( st->hTcxEnc != NULL ) { +#ifndef IVAS_FLOAT_FIXED set_zero( st->hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); +#else + set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); + st->hTcxEnc->q_Txnq = Q15; + move16(); +#endif } } @@ -1565,6 +1575,8 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh IF( st->hTcxEnc != NULL ) { set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); + st->hTcxEnc->q_Txnq = Q15; + move16(); st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + shr( st->L_frame, 1 ); } } @@ -1593,6 +1605,8 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh IF( st->hTcxEnc != NULL ) { set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); + st->hTcxEnc->q_Txnq = Q15; + move16(); } } diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 06eb4fc5b..e13bae9d4 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -613,6 +613,8 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old, const Word16 s set16_fx( hLPDmem->syn, 0, 1 + M ); set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); + st->hTcxEnc->q_Txnq = Q15; + move16(); hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr( st->L_frame, 1 ); set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); } @@ -633,6 +635,8 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old, const Word16 s { Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); + st->hTcxEnc->q_Txnq = Q15; + move16(); set16_fx( hLPDmem->syn, 0, M ); } diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 89d8685a8..ba14a213c 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -202,12 +202,6 @@ void core_coder_mode_switch_ivas_fx( { hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ move16(); - - IF( st->ini_frame == 0 ) - { - set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); - hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; - } } st->currEnergyHF_fx = 0; move32(); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index e18735c84..1c408062d 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -87,15 +87,10 @@ void core_switching_pre_enc( { if ( st->last_core != ACELP_CORE ) { - set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); -#ifndef IVAS_FLOAT_FIXED - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; -#else + set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif } - - set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) @@ -280,21 +275,17 @@ void core_switching_pre_enc( #endif } - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); + set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); /* reset BWE memories */ -#ifndef IVAS_FLOAT_FIXED - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; -#else st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif } if ( st->hBWE_FD != NULL ) { - set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } @@ -342,20 +333,16 @@ void core_switching_pre_enc( #endif /* Reset old TD BWE buffers */ - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); -#ifndef IVAS_FLOAT_FIXED - st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; -#else + set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif } /* reset BWE memories */ if ( st->hBWE_TD != NULL ) { - set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } @@ -867,17 +854,12 @@ void core_switching_pre_enc_ivas_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void core_switching_post_enc( - Encoder_State *st, /* i/o: encoder state structure */ - // const float *old_inp_12k8, /* i : old input signal @12.8kHz */ - float *old_inp_12k8, /* i : old input signal @12.8kHz */ - // const float *old_inp_16k, /* i : old input signal @16kHz */ - float *old_inp_16k, /* i : old input signal @16kHz */ - // const float A[] /* i : unquant. LP filter coefs. */ - float A[], /* i : unquant. LP filter coefs. */ -#ifdef IVAS_FLOAT_FIXED - Word16 Q_new -#endif + Encoder_State *st, /* i/o: encoder state structure */ + const float *old_inp_12k8, /* i : old input signal @12.8kHz */ + const float *old_inp_16k, /* i : old input signal @16kHz */ + const float A[] /* i : unquant. LP filter coefs. */ ) { if ( st->core == HQ_CORE ) @@ -886,44 +868,10 @@ void core_switching_post_enc( if ( ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) && st->element_mode == EVS_MONO ) /* core switching ==> ACELP subframe encoding */ { -#ifndef IVAS_FLOAT_FIXED acelp_core_switch_enc( st, old_inp_12k8 + L_INP_MEM - NS2SA( INT_FS_12k8, ACELP_LOOK_NS ), old_inp_16k + L_INP_MEM - NS2SA( INT_FS_16k, ACELP_LOOK_NS ), A ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from float to fix - Word16 old_inp_12k8_fx[L_INP_12k8]; - Word16 old_inp_16k_fx[L_INP]; - Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; - floatToFixed_arr( st->old_input_signal, st->old_input_signal_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_new - 1, L_INP_12k8 ); - 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 ); -#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 ) ); -#endif -#endif } -#ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; -#else - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif st->hBWE_FD->mem_deemph_old_syn = 0.0f; } else @@ -936,123 +884,191 @@ void core_switching_post_enc( /* reset SWB TBE buffers */ if ( st->extl == WB_TBE && st->last_extl != WB_TBE ) { -#ifdef IVAS_FLOAT_FIXED - wb_tbe_extras_reset_fx( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); -#else wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 ); -#endif -#ifndef IVAS_FLOAT_FIXED if ( st->last_extl != WB_BWE ) { set_f( st->hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( st->hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); } -#else - IF( st->last_extl != WB_BWE ) - { - set16_fx( st->hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( st->hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - } -#endif -#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); set_f( st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); set_f( st->hBWE_TD->mem_csfilt, 0, 2 ); -#else - set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); - set16_fx( st->hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st->hBWE_TD->mem_csfilt_fx, 0, 2 ); -#endif } if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && ( st->last_core == HQ_CORE || st->L_frame != st->last_L_frame || ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) ) ) { -#ifdef IVAS_FLOAT_FIXED - set16_fx( st->hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#else set_f( st->hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#endif -#ifdef IVAS_FLOAT_FIXED - InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); - swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); -#else InitSWBencBufferStates( st->hBWE_TD, NULL ); swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); -#endif -#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->dec_2_over_3_mem, 0.0f, L_FILT_2OVER3 ); set_f( st->hBWE_TD->dec_2_over_3_mem_lp, 0.0f, L_FILT_2OVER3_LP ); -#else - set16_fx( st->hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); - set16_fx( st->hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); -#endif } else if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && ( ( st->element_mode == IVAS_CPE_TD && st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) || ( st->element_mode != IVAS_CPE_TD && st->last_total_brate != st->total_brate ) || ( st->last_bwidth != st->bwidth ) || ( st->last_codec_mode != MODE1 ) || ( st->rf_mode_last != st->rf_mode ) ) ) { -#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); -#else - set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); -#endif -#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); st->hBWE_TD->gain_prec_swb = 1.0f; -#else - set16_fx( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st->hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; -#endif } else if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) { -#ifdef IVAS_FLOAT_FIXED - TBEreset_enc_fx( st, st->bwidth ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - TBEreset_enc( st->hBWE_TD, st->last_core, st->bwidth ); -#endif -#else TBEreset_enc( st->hBWE_TD, st->last_core, st->bwidth ); -#endif } /* Interp_3_2 CNG buffers reset */ if ( st->extl == FB_TBE && ( ( st->last_extl != FB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) || st->L_frame != st->last_L_frame ) ) { -#ifdef IVAS_FLOAT_FIXED - set16_fx( st->hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st->hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - fb_tbe_reset_enc_fx( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx, &st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &st->hBWE_TD->prev_fb_energy_fx_Q ); -#else set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); st->hBWE_TD->fb_tbe_demph = 0; fb_tbe_reset_enc( st->hBWE_TD->elliptic_bpf_2_48k_mem, &st->hBWE_TD->prev_fb_energy ); -#endif } /* Fade towards init value for non HQ_CORE */ if ( st->hHQ_core != NULL ) { -#ifndef IVAS_FLOAT_FIXED st->hHQ_core->crest_lp = HQ_CREST_FAC_SM * ( st->hHQ_core->crest_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_THRESHOLD; st->hHQ_core->crest_mod_lp = HQ_CREST_FAC_SM * ( st->hHQ_core->crest_mod_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_MOD_THRESHOLD; + } + } + + return; +} #else +void core_switching_post_enc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 *old_inp_12k8_fx, /* i : old input signal @12.8kHz Q_new-1 */ + Word16 *old_inp_16k_fx, /* i : old input signal @16kHz Q_new-1 */ + Word16 A_fx[], /* i : unquant. LP filter coefs. Q12 */ + Word16 Q_new ) +{ + IF( EQ_16( st->core, HQ_CORE ) ) + { + st->use_acelp_preq = 0; + move16(); + test(); + test(); + IF( ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) && st->element_mode == EVS_MONO ) /* core switching ==> ACELP subframe encoding */ + { + /* 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 ) ); /* Q_new-1 */ + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ + Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ + Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ + st->hLPDmem->mem_w0 = shl( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ + 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 ) ); + } + + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + st->hBWE_FD->mem_deemph_old_syn_fx = 0; + move16(); + st->hBWE_FD->q_mem_deemph_old_syn = 0; + move16(); + } + ELSE + { + IF( st->hBWE_TD == NULL ) + { + return; + } + + test(); + /* reset SWB TBE buffers */ + IF( EQ_16( st->extl, WB_TBE ) && NE_16( st->last_extl, WB_TBE ) ) + { + wb_tbe_extras_reset_fx( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + + IF( NE_16( st->last_extl, WB_BWE ) ) + { + set16_fx( st->hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( st->hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + } + + set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); + set16_fx( st->hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( st->hBWE_TD->mem_csfilt_fx, 0, 2 ); + } + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && + ( EQ_16( st->last_core, HQ_CORE ) || NE_16( st->L_frame, st->last_L_frame ) || ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) ) ) + { + set16_fx( st->hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + + InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); + swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); + + set16_fx( st->hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); + set16_fx( st->hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); + } + ELSE IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && ( ( EQ_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_32( st->last_total_brate, st->total_brate ) ) || ( NE_16( st->last_bwidth, st->bwidth ) ) || ( NE_16( st->last_codec_mode, MODE1 ) ) || ( NE_16( st->rf_mode_last, st->rf_mode ) ) ) ) + { + set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx( st->hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; + move16(); + } + ELSE IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) + { + TBEreset_enc_fx( st, st->bwidth ); + } + + test(); + test(); + test(); + test(); + /* Interp_3_2 CNG buffers reset */ + IF( EQ_16( st->extl, FB_TBE ) && ( ( NE_16( st->last_extl, FB_TBE ) && NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) || NE_16( st->L_frame, st->last_L_frame ) ) ) + { + set16_fx( st->hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + st->hBWE_TD->fb_tbe_demph_fx = 0; + move16(); + fb_tbe_reset_enc_fx( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx, &st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &st->hBWE_TD->prev_fb_energy_fx_Q ); + } + /* Fade towards init value for non HQ_CORE */ + IF( st->hHQ_core != NULL ) + { st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_THRESHOLD_FX ) ); /*Q28*/ + move32(); st->hHQ_core->crest_lp_q = Q28; + move16(); st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_MOD_THRESHOLD_FX ) ); /*Q29*/ + move32(); st->hHQ_core->crest_mod_lp_q = Q29; -#endif + move16(); } } return; } - +#endif /*---------------------------------------------------------------------* * core_switching_hq_prepare_enc() diff --git a/lib_enc/enc_higher_acelp.c b/lib_enc/enc_higher_acelp.c index c9f1a7b85..d1eff11a2 100644 --- a/lib_enc/enc_higher_acelp.c +++ b/lib_enc/enc_higher_acelp.c @@ -45,7 +45,7 @@ /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void find_cn( const float xn[], const float Ap[], const float *p_Aq, float cn[] ); @@ -344,7 +344,7 @@ static void find_cn( return; } - +#endif /*---------------------------------------------------------------* * gain_quant() * diff --git a/lib_enc/gs_enc.c b/lib_enc/gs_enc.c index 1a068ff68..e53617798 100644 --- a/lib_enc/gs_enc.c +++ b/lib_enc/gs_enc.c @@ -649,7 +649,7 @@ static float edyn( * * Initialize GSC encoder state structure *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void GSC_enc_init( GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */ ) @@ -657,10 +657,11 @@ void GSC_enc_init( /* AC mode */ hGSCEnc->seed_tcx = 15687; hGSCEnc->cor_strong_limit = 1; - set_f( hGSCEnc->last_exc_dct_in, 0, L_FRAME16k ); #ifndef IVAS_FLOAT_FIXED + set_f( hGSCEnc->last_exc_dct_in, 0, L_FRAME16k ); hGSCEnc->last_ener = 0.0f; #else + set16_fx( hGSCEnc->last_exc_dct_in_fx, 0, L_FRAME16k ); hGSCEnc->last_ener_fx = 0; #endif set_s( hGSCEnc->last_bitallocation_band, 0, 6 ); @@ -695,3 +696,4 @@ void GSC_enc_init( return; } +#endif diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 4e1d5ef30..6fd9ae3d8 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -1397,7 +1397,8 @@ void GSC_enc_init_fx( hGSCEnc->cor_strong_limit = 1; move16(); set16_fx( hGSCEnc->last_exc_dct_in_fx, 0, L_FRAME16k ); - // hGSCEnc->last_ener = 0.0f; IVAS_CODE + hGSCEnc->Q_last_exc_dct_in = Q15; + move16(); set16_fx( hGSCEnc->last_bitallocation_band, 0, 6 ); hGSCEnc->mem_last_pit_band = BAND1k2 + 1; diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index b9e8f5bea..bea9bec38 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -186,10 +186,10 @@ ivas_error init_encoder( st->mem_preemph_fx = 0; st->mem_preemph16k_fx = 0; st->mem_preemph_enc = 0; + st->mem_deemp_preQ_fx = 0; #endif /* AVQ pre-quantizer memory */ st->mem_preemp_preQ = 0.0f; - st->mem_deemp_preQ = 0.0f; st->last_nq_preQ = 0; st->last_code_preq = 0; st->use_acelp_preq = 0; @@ -200,11 +200,14 @@ ivas_error init_encoder( st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); - set_f( st->Bin_E, 0, L_FFT ); #ifndef IVAS_FLOAT_FIXED + set_f( st->Bin_E, 0, L_FFT ); st->ee_old = 10.0f; #else + set32_fx( st->Bin_E_fx, 0, L_FFT ); + st->q_Bin_E = Q31; + move16(); st->ee_old_fx = 640; #endif st->Nb_ACELP_frames = 0; @@ -327,7 +330,6 @@ ivas_error init_encoder( #else st->min_alpha_fx = 32767; #endif - st->exc_pe = 0; #ifdef IVAS_FLOAT_FIXED st->exc_pe_fx = 0; move16(); @@ -360,11 +362,19 @@ ivas_error init_encoder( /* mode1 core switching */ #ifndef IVAS_FLOAT_FIXED st->old_Es_pred = 0; + set_f( st->old_Aq_12_8 + 1, 0, M ); + st->old_Aq_12_8[0] = 1; #else st->old_Es_pred_fx = 0; + set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); + st->old_Aq_12_8_fx[0] = ONE_IN_Q12; + move16(); #endif + +#ifndef IVAS_FLOAT_FIXED set_f( st->old_Aq_12_8 + 1, 0, M ); st->old_Aq_12_8[0] = 1; +#endif /* stable short pitch detection */ #ifndef IVAS_FLOAT_FIXED @@ -402,7 +412,6 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n" ) ); } - st->Bin_E_old = st->hSignalBuf->Bin_E_old_flt; #ifdef IVAS_FLOAT_FIXED st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; #endif @@ -428,16 +437,15 @@ ivas_error init_encoder( st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; #endif /* initializations */ - set_f( st->Bin_E_old, 0, L_FFT / 2 ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); -#endif + set_f( st->mem_decim, 0, 2 * L_FILT_MAX ); set_f( st->mem_decim16k, 0, 2 * L_FILT_MAX ); set_f( st->old_inp_12k8, 0, L_INP_MEM ); set_f( st->old_inp_16k, 0, L_INP_MEM ); #ifdef IVAS_FLOAT_FIXED set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); + st->q_Bin_E_old = Q31; + move16(); set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); set16_fx( st->mem_decim_fx, 0, 2 * L_FILT_MAX ); @@ -475,9 +483,9 @@ ivas_error init_encoder( else { st->hSignalBuf = NULL; - st->Bin_E_old = NULL; st->mem_decim = NULL; #ifdef IVAS_FLOAT_FIXED + st->Bin_E_old_fx = NULL; st->mem_decim_fx = NULL; #endif st->mem_decim16k = NULL; @@ -805,8 +813,11 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - +#ifdef IVAS_FLOAT_FIXED + GSC_enc_init_fx( st->hGSCEnc ); +#else GSC_enc_init( st->hGSCEnc ); +#endif } else { @@ -1337,17 +1348,13 @@ ivas_error init_encoder_ivas_fx( st->mem_preemph16k = 0.0f; st->mem_preemph_enc_flt = 0.0; st->mem_preemp_preQ = 0.0f; - st->mem_deemp_preQ = 0.0f; st->mem_wsp_enc_flt = 0.0; st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); - set_f( st->Bin_E, 0, L_FFT ); st->mem_preemph_DFT = 0.0f; set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); st->mem_preemph16k_DFT = 0.0f; set_f( st->inp_16k_mem_stereo_sw, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - set_f( st->old_Aq_12_8 + 1, 0, M ); - st->old_Aq_12_8[0] = 4096; st->active_cnt = 0; #ifndef IVAS_FLOAT_FIXED st->old_hpfilt_in = 0.0f; @@ -1384,7 +1391,8 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->mem_decim2_fx, 0, 3 ); set32_fx( st->Bin_E_fx, 0, L_FFT ); - + st->q_Bin_E = Q31; + move16(); st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); st->Nb_ACELP_frames = 0; @@ -1477,8 +1485,6 @@ ivas_error init_encoder_ivas_fx( move16(); st->min_alpha_fx = 32767; move16(); - st->exc_pe = 0; - move16(); #ifdef IVAS_FLOAT_FIXED st->exc_pe_fx = 0; move16(); @@ -1550,6 +1556,8 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->hSignalBuf->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); /* initializations */ set32_fx( st->Bin_E_old_fx, 0, shr( L_FFT, 2 ) ); + st->q_Bin_E_old = Q31; + move16(); set16_fx( st->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); set16_fx( st->mem_decim16k_fx, 0, shl( L_FILT_MAX, 1 ) ); set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); @@ -1574,7 +1582,6 @@ ivas_error init_encoder_ivas_fx( st->input_fx = st->input_buff_fx + frame_length; } #if 1 // TODO: To be removed later - st->Bin_E_old = st->hSignalBuf->Bin_E_old_flt; st->mem_decim = st->hSignalBuf->mem_decim_flt; st->mem_decim16k = st->hSignalBuf->mem_decim16k_flt; st->old_inp_12k8 = st->hSignalBuf->old_inp_12k8_flt; @@ -1583,7 +1590,6 @@ ivas_error init_encoder_ivas_fx( st->buf_synth_flt = st->hSignalBuf->buf_synth_flt; st->buf_speech_enc_flt = st->hSignalBuf->buf_speech_enc_flt; st->buf_wspeech_enc_flt = st->hSignalBuf->buf_wspeech_enc_flt; - set_f( st->Bin_E_old, 0, L_FFT / 2 ); set_f( st->mem_decim, 0, 2 * L_FILT_MAX ); set_f( st->mem_decim16k, 0, 2 * L_FILT_MAX ); set_f( st->old_inp_12k8, 0, L_INP_MEM ); @@ -1617,7 +1623,6 @@ ivas_error init_encoder_ivas_fx( st->buf_wspeech_enc = NULL; st->input_buff_fx = NULL; #if 1 - st->Bin_E_old = NULL; st->mem_decim = NULL; st->mem_decim16k = NULL; st->old_inp_12k8 = NULL; @@ -1960,9 +1965,6 @@ ivas_error init_encoder_ivas_fx( } GSC_enc_init_fx( st->hGSCEnc ); -#if 1 - GSC_enc_init( st->hGSCEnc ); -#endif } ELSE { @@ -2257,12 +2259,6 @@ ivas_error init_encoder_ivas_fx( { hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ move16(); - - IF( st->ini_frame == 0 ) - { - set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); - hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; - } } st->currEnergyHF_fx = 0; move32(); diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index e21e08225..d73173121 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -61,7 +61,8 @@ ivas_error init_encoder_fx( set16_fx( st_fx->mem_decim16k_fx, 0, 2 * L_FILT_MAX ); set16_fx( st_fx->mem_decim_fx, 0, 2 * L_FILT_MAX ); set32_fx( st_fx->Bin_E_old_fx, 0, L_FFT / 2 ); - + st_fx->q_Bin_E_old = Q31; + move16(); st_fx->input_buff_fx = st_fx->hSignalBuf->input_buff; set16_fx( st_fx->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); @@ -215,6 +216,8 @@ ivas_error init_encoder_fx( st_fx->mem_wsp_fx = 0; move16(); set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); + st_fx->q_Bin_E = Q31; + move16(); set16_fx( st_fx->mem_decim2_fx, 0, 3 ); set16_fx( st_fx->lgBin_E_fx, 0, L_FFT / 2 ); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 28ff1567f..976bcc67d 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -64,18 +64,18 @@ ivas_error ivas_core_enc( float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */ float old_inp_16k[][L_INP], /* i : buffer of old input signal */ 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) unquantized for subframes */ + Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */ 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 */ + Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15 */ const int16_t vad_hover_flag[], /* i : VAD hanglover flag */ int16_t attack_flag[], /* i : attack flag (GSC or TC) */ float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ float old_wsp[][L_WSP], /* i : weighted input signal buffer */ const int16_t loc_harm[], /* i : harmonicity flag */ - const float cor_map_sum[], /* i : speech/music clasif. parameter */ + const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8 */ const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ float enerBuffer[][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ float fft_buff[][2 * L_FFT], /* i : FFT buffer */ @@ -93,11 +93,7 @@ ivas_error ivas_core_enc( 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 */ Word16 Q_new[CPE_CHANNELS] = { 0 }; -#ifndef IVAS_FLOAT_FIXED - float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; -#else Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ -#endif #ifdef IVAS_FLOAT_FIXED Word32 *new_swb_speech_fx; Word16 shb_speech_fx[L_FRAME16k]; // Q_shb_spch @@ -111,31 +107,15 @@ ivas_error ivas_core_enc( Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; #endif int16_t Voicing_flag[CPE_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions - float pitch_buf[CPE_CHANNELS][NB_SUBFR16k] = { 0 }; -#else - float pitch_buf[CPE_CHANNELS][NB_SUBFR16k]; -#endif -#ifdef IVAS_FLOAT_FIXED Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q6 */ -#endif int16_t unbits[CPE_CHANNELS]; - 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 int16_t last_element_mode, tdm_Pitch_reuse_flag; int32_t element_brate, last_element_brate, input_Fs; int16_t diff_nBits; ivas_error error; int16_t max_num_indices_BWE; -#ifdef IVAS_FLOAT_FIXED Word16 i; -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 lsp_new_fx[CPE_CHANNELS][M], lsp_mid_fx[CPE_CHANNELS][M]; -#endif set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); @@ -220,13 +200,9 @@ ivas_error ivas_core_enc( Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX]; Word16 fft_buff_fx[2 * L_FFT]; - Word32 cor_map_sum_fx = 0; - Word16 exp_cor_map_sum = 0; Word16 e_fft_buff; Word16 e_enerBuffer; - 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 ) ); Scale_sig( fft_buff_fx, ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum e_fft_buff += 1; @@ -235,15 +211,18 @@ ivas_error ivas_core_enc( Word16 tmp_shift = find_guarded_bits_fx( 5 ); // Computing guraded bits necessary in the energyBuffer scale_sig32( enerBuffer_fx, CLDFB_NO_CHANNELS_MAX, -tmp_shift ); // Computing the shift as per guarded bits in the energyBuffer e_enerBuffer += tmp_shift; // Shifting the exponent of energyBuffer with the tmp_shift - floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_factor_arrL( st->Bin_E_old, 129 ), 129 ); - #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 old_inp_12k8_fx[L_INP_12k8]; floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, -1, L_INP_12k8 ); #endif + FOR( i = 0; i < st->nb_subfr; i++ ) + { + Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 + Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 + } if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_12k8_fx, old_inp_16k[n], - &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], + &inp[n], &ener[n], A_fx[n], Aw_fx[n], epsP[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], #ifndef IVAS_FLOAT_FIXED cor_map_sum[n], #endif @@ -258,8 +237,7 @@ ivas_error ivas_core_enc( enerBuffer_fx, e_enerBuffer, fft_buff_fx, - cor_map_sum_fx, - exp_cor_map_sum, + cor_map_sum_fx[n], &Q_new[n] #endif ) ) != IVAS_ERR_OK ) @@ -368,47 +346,24 @@ ivas_error ivas_core_enc( /* 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 ) ); - } + Word16 inp_buff[CPE_CHANNELS][L_FRAME16k + M + 1]; + Word16 *inp_fx[CPE_CHANNELS]; + inp_fx[n] = &inp_buff[n][M + 1]; + floatToFixed_arr( &inp[n][-M - 1], &inp_fx[n][-M - 1], Q_new[n] - 1, L_FRAME16k + 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_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 ) + if ( ( error = acelp_core_enc( st, inp_fx[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 } @@ -416,14 +371,11 @@ ivas_error ivas_core_enc( { #ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < st->nb_subfr; i++ ) + { + Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 + } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Aw_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; - float Aw_flt[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; - 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 ) ); - - 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; floatToFixed_arr( st->hTcxEnc->old_out, st->hTcxEnc->old_out_fx, st->hTcxEnc->Q_old_out, L_FRAME32k ); Word16 nSubframes; @@ -446,9 +398,6 @@ ivas_error ivas_core_enc( hTcxEnc->spectrum_e[1] = 31 - q_spectrum; floatToFixed_arrL32( hTcxEnc->spectrum[1], hTcxEnc->spectrum_fx[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); } - - floatToFixed_arr( lsp_new[n], lsp_new_fx[n], Q15, M ); - floatToFixed_arr( lsp_mid[n], lsp_mid_fx[n], Q15, M ); #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // q_old_inp_12k8_fx = Q_factor_arr( old_inp_12k8[n], L_INP_12k8 ); @@ -457,24 +406,19 @@ ivas_error ivas_core_enc( floatToFixed_arr( old_inp_12k8[n], old_inp_12k8_fx, 0, L_INP_12k8 ); floatToFixed_arr( old_inp_16k[n], old_inp_16k_fx, 0, L_INP ); #endif - + Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( -1, st->hTcxEnc->q_Txnq ) ); + st->hTcxEnc->q_Txnq = -Q1; + move16(); /* TCX core encoder */ stereo_tcx_core_enc( st, old_inp_12k8_fx + L_INP_MEM, old_inp_16k_fx + L_INP_MEM, Aw_fx[n], lsp_new_fx[n], lsp_mid_fx[n], pitch_buf_fx[n], last_element_mode, vad_hover_flag[0], 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( lsp_new_fx[n], lsp_new[n], Q15, M ); - fixedToFloat_arr( lsp_mid_fx[n], lsp_mid[n], Q15, M ); -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); - fixedToFloat_arr( st->hTcxEnc->old_out_fx, st->hTcxEnc->old_out, st->hTcxEnc->Q_old_out, L_FRAME32k ); for ( int k = 0; k < 2; k++ ) { fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], 720 ); } - fixedToFloat_arr( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq_flt, -1, L_FRAME32k / 2 + 64 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #endif } @@ -503,12 +447,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 ); - - - FOR( i = 0; i < L_FRAME32k / 2 + 64; i++ ) - { - st->hTcxEnc->Txnq[i] = float_to_fix16( st->hTcxEnc->Txnq_flt[i], 0 ); - } } ELSE { @@ -520,7 +458,9 @@ ivas_error ivas_core_enc( floatToFixed_arr( st->input, st->input_fx, 0, 960 ); #endif - + Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( 0, st->hTcxEnc->q_Txnq ) ); + st->hTcxEnc->q_Txnq = 0; + move16(); hq_core_enc_ivas_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); #endif } @@ -532,19 +472,7 @@ ivas_error ivas_core_enc( if ( st->element_mode == IVAS_CPE_TD && n == 0 ) { #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // lsp_old - Q15, lsf_old - Qlog2(2.56), pitch_buf - Q6 - floatToFixed_arr16( pitch_buf[0], pitch_buf_fx[0], Q6, NB_SUBFR ); -#endif td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, pitch_buf_fx[0], tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // tdm_lspQ_PCh - Q15, tdm_lsfQ_PCh - Qlog2(2.56), hStereoTD->tdm_Pri_pitch_buf - Q6 - fixedToFloat_arr( tdm_lspQ_PCh_fx, tdm_lspQ_PCh, Q15, M ); - for ( i = 0; i < M; i++ ) - { - tdm_lsfQ_PCh[i] = tdm_lsfQ_PCh_fx[i] / 2.56f; - } -#endif #endif } } @@ -577,13 +505,12 @@ ivas_error ivas_core_enc( for ( i = 0; i < CPE_CHANNELS; i++ ) { fixedToFloat_arr( old_wsp_fx[i], old_wsp[i], q_fac[i], L_WSP ); - fixedToFloat_arr( pitch_buf_fx_new[i], pitch_buf[i], Q6, NB_SUBFR16k ); } #endif } else { - stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf ); + stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf_fx ); } } else if ( sts[0]->core_brate == SID_2k40 && sts[1]->core_brate == SID_2k40 ) @@ -621,24 +548,15 @@ ivas_error ivas_core_enc( /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - - core_switching_post_enc( st, old_inp_12k8[n], old_inp_16k[n], A[n], Q_new[n] ); - - /*---------------------------------------------------------------------* - * WB TBE encoding - * WB BWE encoding - *---------------------------------------------------------------------*/ - #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - + // conv params from float to fix 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]; - + Word16 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8], old_inp_16k_fx[CPE_CHANNELS][L_INP]; + floatToFixed_arr( st->old_input_signal, st->old_input_signal_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); 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 // prev_lsp_wb_temp_fx, prev_lsp_wb_fx and prev_lpc_wb_fx in Q15. No float counterparts if ( st->hBWE_FD != NULL ) @@ -679,8 +597,8 @@ ivas_error ivas_core_enc( 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 ); + floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx[n], Q_new[n] - 1, L_INP_12k8 ); + floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx[n], Q_new[n] - 1, L_INP ); if ( st->hBWE_FD != NULL ) @@ -692,6 +610,13 @@ ivas_error ivas_core_enc( floatToFixed_arr( old_syn_12k8_16k[n], old_syn_12k8_16k_fx[n], Q_new[n] - 1, L_FRAME16k ); #endif + core_switching_post_enc_ivas_fx( st, old_inp_12k8_fx[n], old_inp_16k_fx[n], A_fx[n], Q_new[n] ); + + /*---------------------------------------------------------------------* + * WB TBE encoding + * WB BWE encoding + *---------------------------------------------------------------------*/ + test(); test(); IF( GE_32( input_Fs, 16000 ) && LT_16( st->bwidth, SWB ) && st->hBWE_TD != NULL ) @@ -791,7 +716,7 @@ ivas_error ivas_core_enc( 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, sub( Q_shb_spch, Q16 ), sub( Q_new[n], 1 ) ); + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx[n], old_inp_16k_fx[n], 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 } @@ -858,7 +783,7 @@ ivas_error ivas_core_enc( updt_enc_common_ivas_fx( st ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - + fixedToFloat_arr( st->old_input_signal_fx, st->old_input_signal, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); 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 ); diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 7739e00a1..7610e5cb8 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -50,38 +50,37 @@ * Pre-processing (Selection of internal Fs, classification, SC VBR decision, * Decision matrix, Preprocessing at other Fs, core switching decision, ...) *--------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error pre_proc_ivas( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 input_frame, /* i : frame length */ - float old_inp_12k8[], /* i/o: buffer of old input signal */ - Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ - float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ - float **inp, /* o : ptr. to inp. signal in the current frame*/ - float *ener, /* o : residual energy from Levinson-Durbin */ - float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ - float epsP[M + 1], /* i/o: LP prediction errors */ - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ - float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - float old_wsp[], /* i : weighted input signal buffer */ - const Word16 loc_harm, /* i : harmonicity flag */ - const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 vad_hover_flag, /* i : VAD hangover flag */ - const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 input_frame, /* i : frame length */ + float old_inp_12k8[], /* i/o: buffer of old input signal */ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ + float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + float **inp, /* o : ptr. to inp. signal in the current frame*/ + float *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* i/o: LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ + float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ + float old_wsp[], /* i : weighted input signal buffer */ + const Word16 loc_harm, /* i : harmonicity flag */ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ #ifdef IVAS_FLOAT_FIXED , Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], Word16 e_enerBuffer, Word16 fft_buff_fx[2 * L_FFT], - Word32 cor_map_sum_fx, - Word16 exp_cor_map_sum, + Word16 cor_map_sum_fx, // Q8 Word16 *Q_new #endif ) @@ -105,18 +104,6 @@ ivas_error pre_proc_ivas( element_mode = st->element_mode; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )]; - Word16 lsp_new_fx[M]; - Word16 lsp_mid_fx[M]; - - floatToFixed_arr16( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr16( Aw, Aw_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr16( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); -#endif - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ inp_12k8 = new_inp_12k8 - L_LOOK_12k8; @@ -431,8 +418,7 @@ ivas_error pre_proc_ivas( test(); test(); test(); - Word16 flag = BASOP_Util_Cmp_Mant32Exp( cor_map_sum_fx, exp_cor_map_sum, 50, 31 ); - IF( EQ_16( loc_harm, 1 ) && flag && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) + IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << 8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) { st->last_harm_flag_acelp = add( st->last_harm_flag_acelp, 1 ); move16(); @@ -713,18 +699,435 @@ ivas_error pre_proc_ivas( } } + pop_wmops(); + return error; +} +#else +ivas_error pre_proc_ivas( + Encoder_State *st, /* i/o: encoder state structure */ + const int16_t last_element_mode, /* i : last element mode */ + const int32_t element_brate, /* i : element bitrate */ + const int32_t last_element_brate, /* i : last element bitrate */ + const int16_t input_frame, /* i : frame length */ + float old_inp_12k8[], /* i/o: buffer of old input signal */ + float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + float **inp, /* o : ptr. to inp. signal in the current frame*/ + float *ener, /* o : residual energy from Levinson-Durbin */ + float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* i/o: LP prediction errors */ + float lsp_new[M], /* i/o: LSPs at the end of the frame */ + float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ + float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ + const float old_wsp[], /* i : weighted input signal buffer */ + const int16_t loc_harm, /* i : harmonicity flag */ + const float cor_map_sum, /* i : speech/music clasif. parameter */ + const int16_t vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ + const float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ + const float fft_buff[2 * L_FFT], /* i : FFT buffer */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t vad_hover_flag, /* i : VAD hangover flag */ + const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ +) +{ + int16_t L_look, element_mode, lMemRecalc_12k8; + float *inp_12k8, *new_inp_12k8, *inp_16k; /* pointers to current frame and new data */ + const float *wsp; /* weighted input signal buffer */ + int32_t sr_core_tmp, total_brate_tmp; + ivas_error error; + + push_wmops( "pre_proc" ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( Aw_fx, Aw, Q14 - norm_s( Aw_fx[0] ), NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); + error = IVAS_ERR_OK; + + /*----------------------------------------------------------------* + * Initialization + *----------------------------------------------------------------*/ + + element_mode = st->element_mode; + + new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8 = new_inp_12k8 - L_LOOK_12k8; + + if ( element_mode != IVAS_CPE_DFT ) + { + new_inp_12k8 -= L_FILT; + } + + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + + lMemRecalc_12k8 = 0; + if ( element_mode == IVAS_CPE_TD ) + { + lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS ); + } + + /*----------------------------------------------------------------* + * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) + *----------------------------------------------------------------*/ + + if ( st->core_brate == FRAME_NO_DATA ) + { + /* prevent "L_frame" changes in CNG segments */ + st->L_frame = st->last_L_frame; + } + else if ( st->core_brate == SID_2k40 && st->bwidth >= WB && st->hDtxEnc->first_CNG && ( st->hTdCngEnc != NULL && st->hTdCngEnc->act_cnt2 < MIN_ACT_CNG_UPD ) ) + { + /* prevent "L_frame" changes in SID frame after short segment of active frames */ + st->L_frame = st->hDtxEnc->last_CNG_L_frame; + } + else if ( ( ( st->element_mode == IVAS_CPE_MDCT && st->element_brate >= IVAS_64k && st->bwidth >= SWB ) || ( element_mode == IVAS_SCE && st->total_brate > MAX_ACELP_BRATE && st->bwidth >= SWB ) ) && st->core_brate != SID_2k40 ) + { + st->L_frame = L_FRAME32k; + } + else if ( st->bwidth >= SWB && st->total_brate > MAX_ACELP_BRATE_ISM && st->total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && st->is_ism_format && st->tcxonly && st->core_brate != SID_2k40 ) + { + st->L_frame = L_FRAME25_6k; + } + else if ( st->flag_ACELP16k ) + { + st->L_frame = L_FRAME16k; + } + else + { + st->L_frame = L_FRAME; + } + + if ( st->hFdCngEnc != NULL && st->element_mode != IVAS_CPE_MDCT && ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->input_bwidth ) ) ) + { + configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); + } + + if ( st->ini_frame == 0 ) + { + /* avoid switching of internal ACELP Fs in the very first frame */ + st->last_L_frame = st->L_frame; + } + + if ( st->L_frame == L_FRAME ) + { + st->gamma = GAMMA1; + st->preemph_fac = PREEMPH_FAC; + } + else if ( st->L_frame == L_FRAME32k ) + { + st->gamma = GAMMA16k; + st->preemph_fac = PREEMPH_FAC_SWB; + } + else + { + st->gamma = GAMMA16k; + st->preemph_fac = PREEMPH_FAC_16k; + } + + st->sr_core = st->L_frame * FRAMES_PER_SEC; + st->encoderLookahead_enc = NS2SA( st->sr_core, ACELP_LOOK_NS ); + st->encoderPastSamples_enc = ( st->L_frame * 9 ) >> 4; + + + /*-----------------------------------------------------------------* + * coder_type rewriting in case of switching + * IC frames selection + * enforce TC frames in case of switching + *-----------------------------------------------------------------*/ + + /* enforce TRANSITION frames */ + if ( !( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) && st->last_L_frame != st->L_frame && st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 && st->last_core_brate != FRAME_NO_DATA && st->last_core_brate != SID_2k40 && st->coder_type_raw != VOICED ) + { + /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ + st->coder_type = TRANSITION; + } + else if ( st->last_core == HQ_CORE && st->coder_type_raw != VOICED ) + { + /* enforce TC frame in case of HQ -> ACELP core switching */ + st->coder_type = TRANSITION; + } + else if ( st->last_core_brate <= SID_2k40 && st->cng_type == FD_CNG && !( element_mode == IVAS_CPE_TD ) ) + { + /* enforce TC frame in case of FD_CNG -> ACELP switching (past excitation not available) */ + st->coder_type = TRANSITION; + } + /* select INACTIVE frames */ + else if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE && st->vad_flag == 0 && st->element_mode != IVAS_CPE_MDCT ) + { + /* inactive frames will be coded by GSC technology */ + /* except for the VBR mode. VBR mode uses NELP for that */ + if ( !( st->Opt_SC_VBR && vad_flag_dtx ) && ( st->idchan == 0 || element_mode != IVAS_CPE_TD ) ) + { + st->coder_type = INACTIVE; + st->hGSCEnc->noise_lev = NOISE_LEVEL_SP3; + } + } + else if ( st->total_brate > MAX_GSC_INACTIVE_BRATE && ( ( st->vad_flag == 0 && st->bwidth >= SWB && st->max_bwidth >= SWB ) || ( st->localVAD == 0 && ( st->bwidth <= WB || st->max_bwidth <= WB ) ) ) ) + { + /* inactive frames will be coded by AVQ technology */ + st->coder_type = INACTIVE; + } + + + /*---------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *---------------------------------------------------------------------*/ + + st->mdct_sw = MODE1; + st->mdct_sw_enable = MODE1; + if ( ( st->total_brate <= MIN_BRATE_GSC_NOISY_FLAG || st->bwidth < SWB || st->flag_ACELP16k ) && st->GSC_IVAS_mode == 0 ) + { + st->GSC_noisy_speech = 0; + } + + /* core selection */ + ivas_decision_matrix_enc( st, element_brate, fft_buff, enerBuffer, last_element_mode ); + + if ( st->L_frame == L_FRAME16k && ( st->coder_type == VOICED || st->coder_type == UNVOICED ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ + { + st->coder_type = GENERIC; + } + + if ( st->core == TCX_20_CORE || st->core == HQ_CORE ) + { + st->Nb_ACELP_frames = 0; + /* Configure TCX with the same bitrate as given when (re-)initializing TCX */ + total_brate_tmp = st->total_brate; + st->total_brate = st->bits_frame_nominal * FRAMES_PER_SEC; + SetModeIndex( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, MCT_flag ); + + st->sr_core = getCoreSamplerateMode2( element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); + st->total_brate = total_brate_tmp; + + st->L_frame = (int16_t) ( st->sr_core / FRAMES_PER_SEC ); + st->encoderLookahead_enc = NS2SA( st->sr_core, ACELP_LOOK_NS ); + st->encoderPastSamples_enc = ( st->L_frame * 9 ) >> 4; + + if ( st->sr_core == INT_FS_12k8 ) + { + st->preemph_fac = PREEMPH_FAC; + st->gamma = GAMMA1; + } + else if ( st->sr_core == INT_FS_16k ) + { + st->preemph_fac = PREEMPH_FAC_16k; + st->gamma = GAMMA16k; + } + else /* st->sr_core >=25600 */ + { + st->preemph_fac = PREEMPH_FAC_SWB; + st->gamma = GAMMA16k; + } + + if ( st->vad_flag == 0 ) + { + st->coder_type = INACTIVE; + } + else if ( st->coder_type > GENERIC ) + { + st->coder_type = GENERIC; + } + if ( st->element_mode != IVAS_CPE_MDCT ) + { + SetTCXModeInfo( st, st->hTranDet, &st->hTcxCfg->tcx_curr_overlap_mode ); + } + } + else if ( st->element_mode == IVAS_CPE_MDCT ) + { + st->hTcxEnc->tfm_mem = 0.75f; + } + else if ( element_brate != last_element_brate ) + { + if ( st->core_brate != FRAME_NO_DATA ) + { + SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); + } + + if ( st->extl != -1 && st->extl != IGF_BWE && st->igf == 1 ) + { + st->igf = 0; + } + } + + + /*-----------------------------------------------------------------* + * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) + *-----------------------------------------------------------------*/ + + if ( loc_harm == 1 && cor_map_sum > 50 && st->clas == VOICED_CLAS && st->coder_type == GENERIC ) + { + st->last_harm_flag_acelp++; + + if ( st->last_harm_flag_acelp > 10 ) + { + st->last_harm_flag_acelp = 10; + } + } + else + { + st->last_harm_flag_acelp = 0; + } + + /*-----------------------------------------------------------------* + * Update audio frames counter (used for UV decision) + *-----------------------------------------------------------------*/ + + if ( st->coder_type == AUDIO ) + { + st->audio_frame_cnt += AUDIO_COUNTER_STEP; + } + else if ( st->coder_type != INACTIVE ) + { + st->audio_frame_cnt--; + } + + if ( st->audio_frame_cnt > AUDIO_COUNTER_MAX ) + { + st->audio_frame_cnt = AUDIO_COUNTER_MAX; + } + + if ( st->audio_frame_cnt < 0 ) + { + st->audio_frame_cnt = 0; + } + + /*-----------------------------------------------------------------* + * Set formant sharpening flag + *-----------------------------------------------------------------*/ + + st->sharpFlag = 0; + + if ( st->coder_type == GENERIC || st->coder_type == VOICED || st->coder_type == TRANSITION ) + { + if ( element_brate >= FRMT_SHP_MIN_BRATE_IVAS && st->lp_noise > FORMANT_SHARPENING_NOISE_THRESHOLD ) + { + st->sharpFlag = 0; + } + else + { + st->sharpFlag = 1; + } + } + + /* channel-aware mode - due to lack of signaling bit, sharpFlag is 1 always in RF mode */ + if ( st->rf_mode && ( st->coder_type == VOICED || st->coder_type == GENERIC ) ) + { + st->sharpFlag = 1; + } + + /* TD stereo, secondary channel - due to lack of signaling bits, sharpFlag is always 1 */ + if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) + { + st->sharpFlag = 0; + if ( st->coder_type == GENERIC || st->coder_type == VOICED ) + { + st->sharpFlag = 1; + } + } + + /*-----------------------------------------------------------------* + * Set voicing flag for HQ FEC + *-----------------------------------------------------------------*/ + + if ( st->sp_aud_decision1 == 0 && ( st->coder_type == VOICED || st->coder_type == GENERIC ) ) + { + *Voicing_flag = 1; + } + else + { + *Voicing_flag = 0; + } + + /*-----------------------------------------------------------------* + * Compute core-coder buffers at internal sampling rate + *-----------------------------------------------------------------*/ + + sr_core_tmp = ( st->tcxonly == 0 ) ? INT_FS_16k : max( INT_FS_16k, st->sr_core ); /* indicates the ACELP sampling rate */ + + L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ + + inp_16k = old_inp_16k + L_INP_MEM - L_look; + + if ( !flag_16k_smc ) + { + error = ivas_compute_core_buffers( st, &inp_16k, old_inp_16k, new_inp_resamp16k, input_frame, last_element_mode, sr_core_tmp, ener, A, Aw, epsP, lsp_new, lsp_mid ); + if ( error != IVAS_ERR_OK ) + { + return error; + } + } + + if ( !( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) ) + { + /* update signal buffers */ + mvr2r( new_inp_12k8, st->buf_speech_enc_pe + st->L_frame, L_FRAME ); + mvr2r( st->buf_speech_enc + L_FRAME32k, st->buf_speech_enc + st->L_frame, L_FRAME ); + + if ( element_mode == IVAS_CPE_DFT ) + { + mvr2r( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, st->buf_speech_enc + st->L_frame - STEREO_DFT_OVL_12k8, STEREO_DFT_OVL_12k8 ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + mvr2r( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, st->buf_speech_enc + st->L_frame - lMemRecalc_12k8 - L_FILT, lMemRecalc_12k8 + L_FILT ); + } + else if ( element_mode == IVAS_SCE ) + { + mvr2r( st->buf_speech_enc + L_FRAME32k - L_FILT, st->buf_speech_enc + st->L_frame - L_FILT, L_FILT ); + } + + if ( st->tcxonly == 0 ) + { + mvr2r( wsp, st->wspeech_enc, L_FRAME + L_LOOK_12k8 ); + } + } + + if ( flag_16k_smc ) + { + mvr2r( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k, L_FRAME16k ); + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + /* update old weighted speech buffer - for OL pitch analysis */ + mvr2r( &old_wsp[L_FRAME], st->old_wsp, L_WSP_MEM ); + + + /* set the pointer of the current frame for the ACELP core */ + if ( st->L_frame == L_FRAME ) + { + *inp = inp_12k8; + } + else + { + *inp = inp_16k; + } + + /* Update VAD hangover frame counter in active frames */ + if ( !( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) && st->tcxonly == 0 ) + { + if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && vad_hover_flag ) + { + st->hTdCngEnc->burst_ho_cnt++; + if ( st->hTdCngEnc->burst_ho_cnt > HO_HIST_SIZE ) + { + st->hTdCngEnc->burst_ho_cnt = HO_HIST_SIZE; + } + } + else if ( st->hTdCngEnc != NULL && vad_flag_dtx ) + { + st->hTdCngEnc->burst_ho_cnt = 0; + } + } + +#ifdef DEBUG_MODE_ACELP + dbgwrite( inp_12k8, sizeof( float ), L_FRAME, 1, fname( debug_dir, "inp_12k8", st->idchan, st->id_element, ENC ) ); + dbgwrite( inp_16k, sizeof( float ), L_FRAME, 1, fname( debug_dir, "inp_16k", st->idchan, st->id_element, ENC ) ); #endif pop_wmops(); return error; } - +#endif /*-------------------------------------------------------------------* * ivas_compute_core_buffers() diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 5681ba628..44a01b6fb 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1578,24 +1578,25 @@ ivas_error pre_proc_front_ivas_fx( 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 - + Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 - 1 ), st->q_Bin_E_old ) ); + st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 - 1 ); + move16(); + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 - 1 ), st->q_Bin_E ) ); + st->q_Bin_E = add( Q_new, Q_SCALE - 2 - 1 ); + move16(); 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*/ ); + IF( lgBin_E_fx != NULL ) + { + Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); + } + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS 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 - 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 ); @@ -2193,9 +2194,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 q_wsp = Q_factor_arr( old_wsp, L_WSP ) - 3; floatToFixed_arr16( old_wsp, old_wsp_fx, q_wsp, L_WSP ); - - floatToFixed_arr16( st->Bin_E, st->lgBin_E_fx, Q7, L_FFT / 2 ); // Function StableHighPitchDetect_fx excepts st->lgBin_E_fx to be in Q7 - Word16 q_fr_bands = Q30; q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpN, NB_BANDS ) ); q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpE, NB_BANDS ) ); @@ -2268,6 +2266,7 @@ ivas_error pre_proc_front_ivas_fx( } #endif // IVAS_FLOAT_FIXED_CONVERSIONS + Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); /* Detection of very short stable pitch period */ StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, q_wsp, st->lgBin_E_fx ); @@ -2338,9 +2337,10 @@ ivas_error pre_proc_front_ivas_fx( st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, q_inp_12k8, q_fr_bands ); + Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); - fixedToFloat_arr( st->lgBin_E_fx, st->Bin_E, Q7, L_FFT / 2 ); if ( lr_vad_enabled && st->idchan == 0 ) { @@ -2679,8 +2679,11 @@ ivas_error pre_proc_front_ivas_fx( } } floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_new, ATT_NSEG * ATT_SEG_LEN ); - floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS + + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); + st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); + move16(); /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); #else diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 262c765d5..8020d8b9e 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -84,8 +84,8 @@ ivas_error ivas_cpe_enc_fx( float old_inp_12k8[CPE_CHANNELS][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ float old_inp_16k[CPE_CHANNELS][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ #else - float old_inp_12k8[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ - float old_inp_16k[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ + float old_inp_12k8[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ + float old_inp_16k[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ #endif #ifdef IVAS_FLOAT_FIXED Word32 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ @@ -94,21 +94,11 @@ ivas_error ivas_cpe_enc_fx( Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ Word16 fft_exp; #endif - float ener[CPE_CHANNELS]; /* residual energy from Levinson-Durbin */ - float relE[CPE_CHANNELS]; /* frame relative energy */ - Word16 relE_fx[CPE_CHANNELS]; /* frame relative energy Q8 */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float A[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ - float Aw[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ -#else - float A[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ - float Aw[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ -#endif + float ener[CPE_CHANNELS]; /* residual energy from Levinson-Durbin */ + Word16 relE_fx[CPE_CHANNELS]; /* frame relative energy Q8 */ Word16 A_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes Q12 */ Word16 Aw_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes Q12 */ float epsP[CPE_CHANNELS][M + 1]; /* LP prediction errors */ - float lsp_new[CPE_CHANNELS][M]; /* LSPs at the end of the frame */ - float lsp_mid[CPE_CHANNELS][M]; /* ISPs in the middle of the frame */ Word16 lsp_new_fx[CPE_CHANNELS][M]; /* LSPs at the end of the frame Q15 */ Word16 lsp_mid_fx[CPE_CHANNELS][M]; /* ISPs in the middle of the frame Q15 */ Word16 vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ @@ -120,12 +110,9 @@ ivas_error ivas_cpe_enc_fx( Word16 q_re_im_buf = 0; move16(); float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ - float pitch_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch values */ - float voicing_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch gains */ Word16 pitch_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q6, fractional pitch values */ Word16 voicing_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q15, fractional pitch gains */ Word16 loc_harm[CPE_CHANNELS]; /* harmonicity flag */ - float cor_map_sum[CPE_CHANNELS]; /* speech/music clasif. parameter */ Word16 cor_map_sum_fx[CPE_CHANNELS]; /* speech/music clasif. parameter Q8 */ Word16 vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ @@ -144,7 +131,6 @@ ivas_error ivas_cpe_enc_fx( float band_energies_LR[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ float orig_input[CPE_CHANNELS][L_FRAME48k]; Word16 orig_input_fx[CPE_CHANNELS][L_FRAME48k]; - float Etot_last[CPE_CHANNELS]; Word16 Etot_last_fx[CPE_CHANNELS]; Word32 tmp, input_Fs; Word16 max_bwidth, ivas_format; @@ -715,10 +701,6 @@ ivas_error ivas_cpe_enc_fx( Etot_last_fx[1] = sts[1]->hNoiseEst->Etot_last_fx; move16(); move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Etot_last[0] = fix16_to_float( Etot_last_fx[0], Q8 ); - Etot_last[1] = fix16_to_float( Etot_last_fx[1], Q8 ); -#endif } else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { @@ -860,23 +842,16 @@ ivas_error ivas_cpe_enc_fx( FOR( n = 0; n < n_CoreChannels; n++ ) { #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr16( A[0], A_fx[0], Q12, M + 1 ); -#endif + FOR( Word16 i = 0; i < hCPE->hCoreCoder[n]->nb_subfr; i++ ) + { + Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 + } error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf, old_wsp[n], pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer[n], fft_buff[n], fft_buff_fx[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( A_fx[n], A[n], 14 - norm_s( A_fx[n][0] ), NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( Aw_fx[n], Aw[n], 14 - norm_s( Aw_fx[n][0] ), NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx[n], lsp_new[n], Q15, M ); - fixedToFloat_arr( lsp_mid_fx[n], lsp_mid[n], Q15, M ); - fixedToFloat_arr( pitch_fr_fx[n], pitch_fr[n], Q6, NB_SUBFR ); - fixedToFloat_arr( voicing_fr_fx[n], voicing_fr[n], Q15, NB_SUBFR ); - relE[n] = fix16_to_float( relE_fx[n], Q8 ); - cor_map_sum[n] = fix16_to_float( cor_map_sum_fx[n], Q8 ); for ( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) { for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) @@ -1042,29 +1017,11 @@ ivas_error ivas_cpe_enc_fx( if ( hCPE->element_mode == IVAS_CPE_TD ) { #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( pitch_fr[0], pitch_fr_fx[0], Q6, NB_SUBFR ); - floatToFixed_arr( pitch_fr[1], pitch_fr_fx[1], Q6, NB_SUBFR ); - floatToFixed_arr( voicing_fr[0], voicing_fr_fx[0], Q15, NB_SUBFR ); - floatToFixed_arr( voicing_fr[1], voicing_fr_fx[1], Q15, NB_SUBFR ); -#endif - tdm_ol_pitch_comparison_fx( hCPE, pitch_fr_fx, voicing_fr_fx ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( pitch_fr_fx[0], pitch_fr[0], Q6, NB_SUBFR ); - fixedToFloat_arr( pitch_fr_fx[1], pitch_fr[1], Q6, NB_SUBFR ); - fixedToFloat_arr( voicing_fr_fx[0], voicing_fr[0], Q15, NB_SUBFR ); - fixedToFloat_arr( voicing_fr_fx[1], voicing_fr[1], Q15, NB_SUBFR ); -#endif #else tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); #endif #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Etot_last_fx[0] = float_to_fix16( Etot_last[0], Q8 ); - Etot_last_fx[1] = float_to_fix16( Etot_last[1], Q8 ); -#endif tdm_configure_enc_fx( ivas_format, st_ivas->ism_mode, hCPE, Etot_last_fx, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); IF( hEncoderConfig->Opt_DTX_ON ) @@ -1082,12 +1039,14 @@ ivas_error ivas_cpe_enc_fx( } /* modify the coder_type depending on the total_brate per channel */ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { - if ( ( hCPE->element_mode != IVAS_CPE_DFT && hCPE->element_mode != IVAS_CPE_TD ) || n == 0 ) /* modify coder_type of primary channel */ + test(); + test(); + IF( ( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) && NE_16( hCPE->element_mode, IVAS_CPE_TD ) ) || n == 0 ) /* modify coder_type of primary channel */ { /* limit coder_type depending on the bitrate */ - coder_type_modif( sts[n], relE[n] ); + coder_type_modif_ivas_fx( sts[n], relE_fx[n] ); } } @@ -1224,7 +1183,7 @@ ivas_error ivas_cpe_enc_fx( * Core Encoder *----------------------------------------------------------------*/ - if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, ener, A_fx, Aw_fx, epsP, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 085d10777..e42195b67 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -874,14 +874,13 @@ ivas_error front_vad_spar_fx( } Scale_sig( hFrontVad->buffer_12k8_fx + 384, 3 * L_FRAME / 2 - 384, sub( Q_buffer, hFrontVad->q_buffer_12k8 ) ); hFrontVad->q_buffer_12k8 = Q_buffer; - + IF( st->lgBin_E_fx != NULL ) + { + Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); + } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( fr_bands_fx[0], fr_bands[0], Q_buffer + QSCALE + 2, 40 ); fixedToFloat_arrL( lf_E_fx[0], lf_E[0], Q_buffer + QSCALE, 148 ); - if ( st->lgBin_E_fx != NULL ) - { - fixedToFloat_arr( st->lgBin_E_fx, st->Bin_E, Q7, 128 ); - } fixedToFloat_arrL( PS_fx, PS, Q_buffer + QSCALE, 128 ); Etot[0] = fixedToFloat( Etot_fx[0], Q8 ); fixedToFloat_arrL( &band_energies_fx[0], &band_energies[0], Q_buffer + QSCALE + 2 - band_ener_guardbits, 40 ); @@ -993,9 +992,12 @@ ivas_error front_vad_spar_fx( #else // StableHighPitchDetect( &flag_spitch, st->pitch, st->voicing, st->Bin_E, wsp, st->localVAD, &st->voicing_sm, &st->voicing0_sm, &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); floatToFixed_arr( wsp, wsp_fx, Q9, 368 ); - floatToFixed_arr( st->Bin_E, st->lgBin_E_fx, Q7, 128 ); + + Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); + StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q12, st->lgBin_E_fx ); - fixedToFloat_arr( st->lgBin_E_fx, st->Bin_E, Q7, 128 ); + + Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); #endif if ( st->hSpMusClas != NULL ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 708b5e88b..4087e6786 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -436,26 +436,16 @@ ivas_error ivas_ism_enc_fx( float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ #else - float old_inp_12k8[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ - float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 16kHz */ + float old_inp_12k8[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ + float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 16kHz */ #endif Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */ float ener[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin */ - float relE[MAX_NUM_OBJECTS][1]; /* frame relative energy */ Word16 relE_fx[MAX_NUM_OBJECTS][1]; /* frame relative energy, Q8 */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ - float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ -#else - float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ - float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ -#endif Word16 A_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ Word16 Aw_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ float epsP[MAX_NUM_OBJECTS][1][M + 1]; /* LP prediction errors */ - float lsp_new[MAX_NUM_OBJECTS][1][M]; /* LSPs at the end of the frame */ - float lsp_mid[MAX_NUM_OBJECTS][1][M]; /* ISPs in the middle of the frame */ Word16 lsp_new_fx[MAX_NUM_OBJECTS][1][M]; /* LSPs at the end of the frame Q15 */ Word16 lsp_mid_fx[MAX_NUM_OBJECTS][1][M]; /* ISPs in the middle of the frame Q15 */ Word16 vad_hover_flag[MAX_NUM_OBJECTS][1]; /* VAD hangover flag */ @@ -467,12 +457,9 @@ ivas_error ivas_ism_enc_fx( float realBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ float imagBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ float old_wsp[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */ - float pitch_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values */ - float voicing_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains */ Word16 pitch_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values Q6 */ Word16 voicing_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains Q15 */ Word16 loc_harm[MAX_NUM_OBJECTS][1]; /* harmonicity flag */ - float cor_map_sum[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter */ Word16 cor_map_sum_fx[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter Q8 */ Word16 vad_flag_dtx[MAX_NUM_OBJECTS][1]; /* HE-SAD flag with additional DTX HO */ float enerBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ @@ -594,28 +581,16 @@ ivas_error ivas_ism_enc_fx( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr16( A[sce_id][0], A_fx[sce_id][0], Q12, M + 1 ); -#endif + FOR( i = 0; i < hSCE->hCoreCoder[0]->nb_subfr; i++ ) + { + Scale_sig( &A_fx[sce_id][0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[sce_id][0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 + } error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], &ener[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf, old_wsp[sce_id][0], pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], fft_buff[sce_id][0], fft_buff_fx[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( A_fx[sce_id][0], A[sce_id][0], 14 - norm_s( A_fx[sce_id][0][0] ), NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( Aw_fx[sce_id][0], Aw[sce_id][0], 14 - norm_s( Aw_fx[sce_id][0][0] ), NB_SUBFR16k * ( M + 1 ) ); - // fixedToFloat_arr( lsp_new_fx[sce_id][0], lsp_new[sce_id][0], Q15, M ); - // fixedToFloat_arr( lsp_mid_fx[sce_id][0], lsp_mid[sce_id][0], Q15, M ); - for ( int idx = 0; idx < M; idx++ ) - { - lsp_new[sce_id][0][idx] = (float) lsp_new_fx[sce_id][0][idx] / 32767.0f; - lsp_mid[sce_id][0][idx] = (float) lsp_mid_fx[sce_id][0][idx] / 32767.0f; - } - fixedToFloat_arr( pitch_fr_fx[sce_id][0], pitch_fr[sce_id][0], Q6, NB_SUBFR ); - fixedToFloat_arr( voicing_fr_fx[sce_id][0], voicing_fr[sce_id][0], Q15, NB_SUBFR ); - relE[sce_id][0] = fix16_to_float( relE_fx[sce_id][0], Q8 ); - cor_map_sum[sce_id][0] = fix16_to_float( cor_map_sum_fx[sce_id][0], Q8 ); for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) @@ -654,10 +629,6 @@ ivas_error ivas_ism_enc_fx( if ( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ } - for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) - { - relE_fx[sce_id][0] = float_to_fix16( relE[sce_id][0], Q8 ); - } #endif IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) @@ -815,7 +786,7 @@ ivas_error ivas_ism_enc_fx( test(); IF( !dtx_flag || ( dtx_flag && EQ_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) ) { - IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], ener[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 07c6c7210..44f6853ca 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1638,7 +1638,8 @@ void ivas_mdct_core_whitening_enc( #endif Encoder_State *st, **sts; #ifdef IVAS_FLOAT_FIXED - Word16 q_fac; + Word16 q_fac = 0; + move16(); Word32 scf_fx[CPE_CHANNELS][NB_DIV][M]; Word32 scf_q_fx[CPE_CHANNELS][NB_DIV][M]; #ifdef MSAN_FIX diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 61515b6fd..560fac4b9 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -72,18 +72,10 @@ ivas_error ivas_sce_enc_fx( float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ float ener[1]; /* residual energy from Levinson-Durbin */ - float relE[1]; /* frame relative energy */ - float A[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ - float Aw[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ float epsP[1][M + 1]; /* LP prediction errors */ - float lsp_new[1][M]; /* LSPs at the end of the frame */ - float lsp_mid[1][M]; /* ISPs in the middle of the frame */ float realBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ float imagBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ float old_wsp[1][L_WSP]; /* old weighted input signal */ - float pitch_fr[1][NB_SUBFR]; /* fractional pitch values */ - float voicing_fr[1][NB_SUBFR]; /* fractional pitch gains */ - float cor_map_sum[1]; /* speech/music clasif. parameter */ float enerBuffer[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ float fft_buff[1][2 * L_FFT]; /* FFT buffer */ float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ @@ -247,10 +239,10 @@ ivas_error ivas_sce_enc_fx( * Front Pre-processing *----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr16( A[0], A_fx[0], Q12, M + 1 ); -#endif - + FOR( Word16 i = 0; i < hSCE->hCoreCoder[0]->nb_subfr; i++ ) + { + Scale_sig( &A_fx[0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 + } error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp[0], pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer[0], @@ -258,14 +250,6 @@ ivas_error ivas_sce_enc_fx( st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( A_fx[0], A[0], 14 - norm_s( A_fx[0][0] ), NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( Aw_fx[0], Aw[0], 14 - norm_s( Aw_fx[0][0] ), NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx[0], lsp_new[0], Q15, M ); - fixedToFloat_arr( lsp_mid_fx[0], lsp_mid[0], Q15, M ); - fixedToFloat_arr( pitch_fr_fx[0], pitch_fr[0], Q6, NB_SUBFR ); - fixedToFloat_arr( voicing_fr_fx[0], voicing_fr[0], Q15, NB_SUBFR ); - relE[0] = fix16_to_float( relE_fx[0], Q8 ); - cor_map_sum[0] = fix16_to_float( cor_map_sum_fx[0], Q8 ); for ( int i = 0; i < CLDFB_NO_COL_MAX; i++ ) { for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) @@ -363,13 +347,13 @@ ivas_error ivas_sce_enc_fx( move16(); /* modify the coder_type depending on the total_brate per channel */ - coder_type_modif( st, relE[0] ); + coder_type_modif_ivas_fx( st, relE_fx[0] ); /*----------------------------------------------------------------* * Encoder *----------------------------------------------------------------*/ - IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, ener, A_fx, Aw_fx, epsP, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer, fft_buff, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index f95a72f8f..f13532975 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -406,7 +406,7 @@ static void stereo_td_channel_extrapolate_fx( set16_zero_fx( mem_zero, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER ); /* get the LPC filter */ - autocorr_fx( shift_combined + input_frame + size_ovl - itd_shift - STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER, r_h, r_l, &Q_r, STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT, window, 0, 0 ); + autocorr_ivas_fx( shift_combined + input_frame + size_ovl - itd_shift - STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT, q_shift, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER, r_h, r_l, &Q_r, STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT, window, 0, 0, 0 ); /* Ensure R[0] isn't zero when entering Levinson-Durbin */ r_l[0] = s_max( r_l[0], 1 ); FOR( i = 0; i <= STEREO_DFT_CHANNEL_EXTR_LPC_ORDER; i++ ) diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index ada638d04..8977fd3e6 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -522,7 +522,11 @@ void stereo_mdct_core_enc( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ float new_samples[CPE_CHANNELS][L_INP], /* i : new samples */ float old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */ +#ifndef IVAS_FLOAT_FIXED float pitch_buf[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */ +#else + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */ +#endif ) { #ifdef IVAS_FLOAT_FIXED @@ -729,7 +733,6 @@ void stereo_mdct_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 new_samples_fx[CPE_CHANNELS][L_INP]; Word16 old_wsp_fx[CPE_CHANNELS][L_WSP], q_fac[CPE_CHANNELS]; - Word16 pitch_buf_fx_new[CPE_CHANNELS][NB_SUBFR16k]; /* Q6 */ for ( i = 0; i < CPE_CHANNELS; i++ ) { floatToFixed_arr( new_samples[i], new_samples_fx[i], 0, L_INP ); @@ -737,13 +740,12 @@ void stereo_mdct_core_enc( floatToFixed_arr( old_wsp[i], old_wsp_fx[i], q_fac[i], L_WSP ); } #endif - ivas_mdct_core_whitening_enc( hCPE, new_samples_fx, old_wsp_fx, pitch_buf_fx_new, p_mdst_spectrum_long, + ivas_mdct_core_whitening_enc( hCPE, new_samples_fx, old_wsp_fx, pitch_buf_fx, p_mdst_spectrum_long, tnsBits, p_orig_spectrum_long, tnsSize, p_param, hBstr, 0, CPE_CHANNELS ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < CPE_CHANNELS; i++ ) { fixedToFloat_arr( old_wsp_fx[i], old_wsp[i], q_fac[i], L_WSP ); - fixedToFloat_arr( pitch_buf_fx_new[i], pitch_buf[i], Q6, NB_SUBFR16k ); } #endif diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 6ba8cd1a8..5e86db216 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -77,10 +77,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } -#ifdef IVAS_FLOAT_FIXED GSC_enc_init_fx( st->hGSCEnc ); -#endif - GSC_enc_init( st->hGSCEnc ); } IF( st->hNoiseEst == NULL ) @@ -145,7 +142,11 @@ static ivas_error allocate_CoreCoder_enc( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } +#ifndef IVAS_FLOAT_FIXED GSC_enc_init( st->hGSCEnc ); +#else + GSC_enc_init_fx( st->hGSCEnc ); +#endif } if ( st->hNoiseEst == NULL ) @@ -1392,8 +1393,11 @@ void stereo_switching_enc_fx( init_gp_clip_fx( sts[1]->clip_var_fx ); set32_fx( sts[1]->Bin_E_fx, 0, L_FFT ); + sts[1]->q_Bin_E = Q31; + move16(); set32_fx( sts[1]->Bin_E_old_fx, 0, L_FFT / 2 ); - + sts[1]->q_Bin_E_old = Q31; + move16(); /* sts[1]->hLPDmem reset already done in allocation of handles */ sts[1]->last_L_frame = sts[0]->last_L_frame; diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index 20bc57c1d..b73712ef7 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -2836,8 +2836,10 @@ Word16 tdm_lp_comparison_fx( Word32 res_fx[L_FRAME16k]; Word16 gb1 = find_guarded_bits_fx( M ); + Word16 Q_A_SCh; Word32 *speech_fx = &speech_buff[M]; - residu_ivas_fx( A_SCh_fx, Q12, m, speech_fx, res_fx, L_frame ); + Q_A_SCh = sub( 14, norm_s( A_SCh_fx[0] ) ); + residu_ivas_fx( A_SCh_fx, Q_A_SCh, m, speech_fx, res_fx, L_frame ); /* Find prediction gain for current LP filter */ // residu( A_SCh, m, speech, res, L_frame ); @@ -2846,6 +2848,12 @@ Word16 tdm_lp_comparison_fx( scale_sig32( speech_buff, L_FRAME + M, gb1 ); Word16 exp = sub( 31, Q_speech ); Word32 sum2_value = sum2_32_exp_fx( speech_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb + IF( LT_16( exp, -5 ) ) /*maximum q to prevent 0.01 from saturating is 37, since we are adding it headroom of 1 is required*/ + { + sum2_value = L_shl( sum2_value, add( 5, exp ) ); // sum2_value>>(-5-exp)=>sum2_value<<(5+exp) + exp = -5; + move16(); + } sum2_value = L_add( sum2_value, L_shl( 328, sub( sub( 31, exp ), 15 ) ) ); Word32 temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); ener_sig_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index fd59ab716..3bbb04ecd 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -472,8 +472,6 @@ void stereo_tcx_core_enc( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*q_comm_Bin = s_min( Q_factor_arrL( st->Bin_E_old, 128 ), Q_factor_arrL( st->Bin_E, 256 ) ); - Q_new = q_comm_Bin - ( QSCALE - 2 );*/ q_comm_Bin = Q_new + Q_SCALE - 2; const Word16 Q_ener = Q_new + Q_SCALE - 2; // Q_new + Q_SCALE -2 #endif @@ -847,12 +845,14 @@ void stereo_tcx_core_enc( move16(); } } + st->q_Bin_E = q_comm_Bin; + move16(); + st->q_Bin_E_old = q_comm_Bin; + move16(); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // Fixed to float - fixedToFloat_arr( st->synth, st->synth_flt, Q_new, st->L_frame ); - 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 pop_wmops(); diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 43e5ff5bb..862df80e9 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -134,7 +134,7 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity /* calculate the new step */ /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ tmp16 = sub( *pt_mins, i ); - tmpdB = sub( Bin_E[*pt_mins], Bin_E[i] ); + tmpdB = sub_sat( Bin_E[*pt_mins], Bin_E[i] ); sign_fx = shr( tmpdB, 15 ); /* 0 if positive else -1 */ ExpdB = sub( norm_s( tmpdB ), 1 ); tmpdB = abs_s( shl( tmpdB, ExpdB ) ); diff --git a/lib_enc/pitch_ol2.c b/lib_enc/pitch_ol2.c index 6c5ed0123..11c816513 100644 --- a/lib_enc/pitch_ol2.c +++ b/lib_enc/pitch_ol2.c @@ -215,15 +215,24 @@ void StableHighPitchDetect_ivas_fx( Top = pitch[1]; move16(); pitch_freq_point = idiv1616( L_FFT, Top ); /* Q0*/ - diff = L_deposit_l( 0 ); sum_energy = L_deposit_l( 0 ); FOR( i = 1; i < 2 * pitch_freq_point; i++ ) { - diff = L_add( diff, sub( EspecdB[pitch_freq_point], EspecdB[i] ) ); - sum_energy = L_add( sum_energy, EspecdB[i] ); + sum_energy = L_mac0( sum_energy, EspecdB[i], 1 ); // sum_energy } - /*sum_energy /= (2*pitch_freq_point-1);*/ tmp = sub( shl( pitch_freq_point, 1 ), 1 ); + + /* for ( i = 1; i < 2 * pitch_freq_point; i++ ) + { + diff += ( EspecdB[pitch_freq_point] - EspecdB[i] ); + } + sum energy is the accumulated value of EspecdB over the loop and EspecdB[pitch_freq_point] is constant for the loop + diff can be computed as (2 * pitch_freq_point - 1) * EspecdB[pitch_freq_point] - sum_energy */ + + diff = L_mac0( L_negate( sum_energy ), EspecdB[pitch_freq_point], tmp ); + + /*sum_energy /= (2*pitch_freq_point-1);*/ + exp = norm_s( tmp ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*Q(29-exp)*/ L_tmp = Mult_32_16( sum_energy, tmp1 ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index faee1c89c..ea6c413af 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1145,11 +1145,13 @@ typedef struct gsc_enc_structure Word16 mem_syn_tmp_fx[M]; Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic Q7 */ #endif - int16_t noise_lev; /* AC mode (GSC) - noise level */ - int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ - Word32 Last_frame_ener_fx; /* AC mode (GSC) - Last frame energy */ - int16_t pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching */ - float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ + int16_t noise_lev; /* AC mode (GSC) - noise level */ + int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ + Word32 Last_frame_ener_fx; /* AC mode (GSC) - Last frame energy */ + int16_t pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching */ +#ifndef IVAS_FLOAT_FIXED + float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ +#endif Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous exciation */ Word16 Q_last_exc_dct_in; #ifndef IVAS_FLOAT_FIXED @@ -1453,11 +1455,11 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float state_syn_shbexc[L_SHB_LAHEAD]; float state_lpc_syn[LPC_SHB_ORDER]; + float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ #else Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; /* Q(prev_Q_bwe_exc - 16) */ Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; /* Q(prev_Q_bwe_exc - 16) */ #endif - float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ int16_t bwe_seed[2]; #ifndef IVAS_FLOAT_FIXED @@ -1586,15 +1588,16 @@ typedef struct fd_bwe_enc_structure Word16 old_input_wb_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; /* Q(-1) */ #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_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; float old_fdbwe_speech[L_FRAME48k]; -#endif float mem_deemph_old_syn; +#endif 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 )]; Word16 old_fdbwe_speech_fx[L_FRAME48k]; Word16 mem_deemph_old_syn_fx; + Word16 q_mem_deemph_old_syn; int16_t prev_mode; float old_wtda_swb[L_FRAME48k]; Word16 L_old_wtda_swb_fx[L_FRAME48k]; /* Q(Q_old_wtda) */ @@ -1884,11 +1887,12 @@ typedef struct tcx_enc_structure #endif /* TCX memory */ - float Txnq_flt[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ - float *acelp_zir_flt; Word16 Txnq[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ Word16 *acelp_zir; + Word16 q_Txnq; #ifndef IVAS_FLOAT_FIXED + float Txnq_flt[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ + float *acelp_zir_flt; float tcx_target_bits_fac_flt; #else Word16 tcx_target_bits_fac; /* Q14 */ @@ -2027,9 +2031,10 @@ typedef struct enc_core_structure LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - float Bin_E[L_FFT]; /* per bin energy of two frames */ Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ #ifndef IVAS_FLOAT_FIXED + float Bin_E[L_FFT]; /* per bin energy of two frames */ float lsp_old1[M]; /* old unquantized LSP vector at the end of the frame at 12k8 */ float lsf_old1[M]; /* old unquantized LSF vector at the end of the frame at 12k8 */ float lsp_old[M]; /* old LSP vector at the end of the frame */ @@ -2116,10 +2121,10 @@ typedef struct enc_core_structure int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ #ifndef IVAS_FLOAT_FIXED float min_alpha; /* Stationary noise UV modification - minimum alpha */ + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ #else Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15 */ #endif - float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ int16_t coder_type_raw; /* raw coder_type (before UNVOICED is lost) */ @@ -2156,19 +2161,21 @@ typedef struct enc_core_structure #endif int16_t spike_hyst; /* Hysteresis to prevent UC after sharp energy spike */ int16_t last_harm_flag_acelp; /* harmonicity flag for ACELP @32kbps rate */ - float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ #ifndef IVAS_FLOAT_FIXED - float old_Es_pred; /* old Es_pred for core switching */ + float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ + float old_Es_pred; /* old Es_pred for core switching */ #else Word16 old_Es_pred_fx; /* old Es_pred for core switching Q8 */ #endif Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ Word16 last_vad_spa_fx; - Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ - float mem_preemph16k; /* ACELP@16kHz - preemphasis filter memory @16kHz */ - float mem_deemp_preQ; /* ACELP@16kHz - prequantizer deemhasis memory */ + Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ + float mem_preemph16k; /* ACELP@16kHz - preemphasis filter memory @16kHz */ +#ifndef IVAS_FLOAT_FIXED + float mem_deemp_preQ; /* ACELP@16kHz - prequantizer deemhasis memory */ +#endif float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ @@ -2234,8 +2241,9 @@ typedef struct enc_core_structure Word16 Q_old_wtda; SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; - - float *Bin_E_old; /* per bin energy of old 2nd frames */ +#ifndef IVAS_FLOAT_FIXED + float *Bin_E_old; /* per bin energy of old 2nd frames */ +#endif float *mem_decim; /* decimation filter memory */ float *mem_decim16k; /* ACELP@16kHz - decimation filter memory @16kHz */ float *old_inp_12k8; /* memory of input signal at 12.8kHz */ @@ -2244,7 +2252,8 @@ typedef struct enc_core_structure float *buf_synth_flt; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ float *buf_speech_enc_flt; float *buf_wspeech_enc_flt; - Word32 *Bin_E_old_fx; /* per bin energy of old 2nd frames */ + Word32 *Bin_E_old_fx; /* per bin energy of old 2nd frames */ + Word16 q_Bin_E_old; Word16 *mem_decim_fx; /* decimation filter memory */ Word16 *mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz */ Word16 *old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ diff --git a/lib_enc/swb_bwe_enc.c b/lib_enc/swb_bwe_enc.c index f7890511b..5a716d6f0 100644 --- a/lib_enc/swb_bwe_enc.c +++ b/lib_enc/swb_bwe_enc.c @@ -1857,7 +1857,9 @@ void fd_bwe_enc_init( set_f( hBWE_FD->old_input, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) ); #ifndef IVAS_FLOAT_FIXED set_f( hBWE_FD->old_input_wb, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ) ); + set_f( hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); #else + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ) ); #endif set_f( hBWE_FD->old_input_lp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ) ); @@ -1866,7 +1868,6 @@ void fd_bwe_enc_init( set_f( hBWE_FD->old_input_lp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); #endif - set_f( hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; set_f( hBWE_FD->old_wtda_swb, 0, L_FRAME48k ); @@ -1887,10 +1888,14 @@ void fd_bwe_enc_init( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_FD->old_fdbwe_speech, 0.0f, L_FRAME48k ); + hBWE_FD->mem_deemph_old_syn = 0.0f; #else set16_fx( hBWE_FD->old_fdbwe_speech_fx, 0, L_FRAME48k ); + hBWE_FD->mem_deemph_old_syn_fx = 0; + move16(); + hBWE_FD->q_mem_deemph_old_syn = 0; + move16(); #endif - hBWE_FD->mem_deemph_old_syn = 0.0f; return; } diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index b62b00be1..29461ffb2 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -93,10 +93,10 @@ void InitSWBencBuffer( { int16_t i; - set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; hBWE_TD->bwe_seed[1] = 59; #ifndef IVAS_FLOAT_FIXED + set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) ); set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale = 0; @@ -108,6 +108,7 @@ void InitSWBencBuffer( set_f( hBWE_TD->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); hBWE_TD->prev_fb_energy = 0.0f; #else + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; @@ -2946,10 +2947,11 @@ void TBEreset_enc( { if ( last_core != ACELP_CORE ) { - set_f( hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); #ifndef IVAS_FLOAT_FIXED + set_f( hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale = 0.f; #else + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; #endif } -- GitLab