diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 743dc0a078417661a3678d30eeff56e22ca5ad20..eaa9cb209328360b90cc9cc18e339cf8fd489500 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -286,10 +286,9 @@ ivas_error pre_proc_ivas( 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 */ 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*/ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz */ + Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame*/ Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q6 */ 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 */ @@ -299,7 +298,8 @@ ivas_error pre_proc_ivas( Word16 lsp_mid[M], /* i/o: LSPs in the middle of the frame */ Word16 *new_inp_resamp16k_fx, /* 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 */ + Word16 old_wsp_fx[], /* i : weighted input signal buffer */ + Word16 e_old_wsp, const int16_t loc_harm, /* i : harmonicity flag */ #ifndef IVAS_FLOAT_FIXED const float cor_map_sum, /* i : speech/music clasif. parameter */ @@ -529,8 +529,8 @@ ivas_error ivas_core_enc( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ const int16_t n_CoreChannels, /* i : number of core channels to be coded */ - 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 */ + Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */ + Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */ Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6*/ 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*/ @@ -543,7 +543,8 @@ ivas_error ivas_core_enc( Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ Word16 *q_re_im_buf, - float old_wsp[][L_WSP], /* i : weighted input signal buffer */ + Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer */ + Word16 e_old_wsp[], const int16_t loc_harm[], /* i : harmonicity flag */ 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 */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index fcdb9f10dbf9ea3071e1a80d0a2cbccb097e6025..a8c2e28bdf5d3261438b691593febdde74c38dcb 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -5876,8 +5876,8 @@ static Word32 non_linearity_scaled_copy_ivas( } FOR( ; i < length; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ - L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ + /* L_tmp = (input[i] * input[i]) * prev_scale;*/ + L_tmp = Mpy_32_16_1( Mpy_32_16_1( prev_scale, input[i] ), input[i] ); /* 2*Q_inp */ test(); test(); diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 171e57bfa7d24c17fbc4f428150c0b43c6ceab4b..ad78ce310ce94b5e94772eaaff9c9e58376e0af3 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -297,18 +297,18 @@ static void find_enr_dft_fx( te = W_shl( te, te_exp ); // 2 * Q_inp_dmx + te_exp BinE_fx[bin_cnt] = W_extract_h( te ); // 2 * Q_inp_dmx + te_exp - 32 move32(); - g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); - tmp_fx = L_sub( Mpy_32_32( c_fx, c_1_fx ), Mpy_32_32( s_fx, s_1_fx ) ); - s_fx = L_add( Mpy_32_32( s_fx, c_1_fx ), Mpy_32_32( c_fx, s_1_fx ) ); - c_fx = tmp_fx; + g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); // 30 - guarded_bits + tmp_fx = L_sub( Mpy_32_32( c_fx, c_1_fx ), Mpy_32_32( s_fx, s_1_fx ) ); // 31 - guarded_bits + s_fx = L_add( Mpy_32_32( s_fx, c_1_fx ), Mpy_32_32( c_fx, s_1_fx ) ); // 31 - guarded_bits + c_fx = tmp_fx; // 31 - guarded_bits move32(); - Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q31 - gaurded_bits + Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q30 - gaurded_bits Word16 ngmult_exp = W_norm( ngmult ); - ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp + ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q30 - gaurded_bits + ngmult_exp BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); - BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( *Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); + BinE_fx[bin_cnt] = L_shl_sat( BinE_fx[bin_cnt], sub( *Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); // To Be Checked band_fx[i] = L_add_sat( BinE_fx[bin_cnt], band_fx[i] ); diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 5bded26033aa7ef4f289a73a679e18d74a0197e1..9b91bd505c9273da79cb65a2f25c626463fc1f98 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -567,7 +567,7 @@ void gauss2v_fx( } ELSE { - if ( L_msu( L_shl( L_mult( cor2w_mantissa, eneri_mantissa ), difference_norm ), cor2_mantissa, enerw_mantissa ) < 0 ) + if ( L_msu_sat( L_shl( L_mult( cor2w_mantissa, eneri_mantissa ), difference_norm ), cor2_mantissa, enerw_mantissa ) < 0 ) // Saturation to be revisited { update_best = 1; move16(); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 8fb4481483157d49d5b2f34cacb63fafcc3927b6..96ccde2c0fe28bd2fce8ebc074d65b31202e2fbc 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -170,34 +170,36 @@ ivas_error init_encoder( init_gp_clip( st->clip_var ); pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); set_f( st->old_wsp, 0, L_WSP_MEM ); + set_f( st->old_wsp2, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); #else init_gp_clip_fx( st->clip_var_fx ); pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); -#endif -#ifdef IVAS_FLOAT_FIXED set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); st->exp_old_wsp = 0; move16(); + set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. + st->Q_old_wsp2 = Q15; + move16(); #endif + #ifndef IVAS_FLOAT_FIXED - set_f( st->old_wsp2, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + st->mem_preemph = 0.0f; st->mem_preemph16k = 0.0f; st->mem_preemph_enc_flt = 0.0; -#endif - - st->mem_preemph = 0.0f; -#ifdef IVAS_FLOAT_FIXED +#else st->mem_preemph_fx = 0; st->mem_preemph16k_fx = 0; st->mem_preemph_enc = 0; st->exp_mem_preemph_enc = 0; - st->mem_deemp_preQ_fx = 0; #endif + /* AVQ pre-quantizer memory */ #ifndef IVAS_FLOAT_FIXED st->mem_preemp_preQ = 0.0f; + st->mem_deemp_preQ = 0.0f; #else st->mem_preemp_preQ_fx = 0; + st->mem_deemp_preQ_fx = 0; #endif st->last_nq_preQ = 0; st->last_code_preq = 0; @@ -219,9 +221,6 @@ ivas_error init_encoder( st->mem_wsp_q = 0; move16(); set16_fx( st->mem_decim2_fx, 0, 3 ); - set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. - st->Q_old_wsp2 = Q15; - move16(); #endif #endif @@ -324,17 +323,20 @@ ivas_error init_encoder( st->spike_hyst = -1; /* stereo switching memories */ +#ifndef IVAS_FLOAT_FIXED 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 ); -#ifdef IVAS_FLOAT_FIXED +#else st->mem_preemph_DFT_fx = 0; - set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); + set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); st->mem_preemph16k_DFT_fx = 0; - set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); - st->sharpFlag = 0; + set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); #endif + + st->sharpFlag = 0; + /* Stationary noise UV modification */ #ifndef IVAS_FLOAT_FIXED st->ge_sm = 10; @@ -438,9 +440,13 @@ ivas_error init_encoder( #ifdef IVAS_FLOAT_FIXED st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; -#endif + st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; + st->mem_decim16k_fx = st->hSignalBuf->mem_decim16k_fx; +#else + st->Bin_E_old = st->hSignalBuf->Bin_E_old; st->mem_decim = st->hSignalBuf->mem_decim_flt; st->mem_decim16k = st->hSignalBuf->mem_decim16k_flt; +#endif st->old_inp_12k8 = st->hSignalBuf->old_inp_12k8_flt; st->old_inp_16k = st->hSignalBuf->old_inp_16k_flt; #ifdef IVAS_FLOAT_FIXED @@ -463,17 +469,22 @@ ivas_error init_encoder( #endif /* initializations */ +#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->mem_decim_fx, 0, 2 * L_FILT_MAX ); + set16_fx( st->mem_decim16k_fx, 0, 2 * L_FILT_MAX ); +#else + 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 ); +#endif 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 ); st->input_buff_fx = st->hSignalBuf->input_buff; st->input_buff32_fx = st->hSignalBuf->input_buff32; set32_fx( st->hSignalBuf->input_buff32, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); @@ -513,12 +524,15 @@ ivas_error init_encoder( else { st->hSignalBuf = NULL; +#ifndef IVAS_FLOAT_FIXED + st->Bin_E_old = NULL; st->mem_decim = NULL; -#ifdef IVAS_FLOAT_FIXED + st->mem_decim16k = NULL; +#else st->Bin_E_old_fx = NULL; st->mem_decim_fx = NULL; + st->mem_decim16k_fx = NULL; #endif - st->mem_decim16k = NULL; st->old_inp_12k8 = NULL; st->old_inp_16k = NULL; #ifndef IVAS_FLOAT_FIXED @@ -1399,11 +1413,6 @@ ivas_error init_encoder_ivas_fx( move16(); #if 1 // TODO: Float Initializations. To be removed later - st->mem_preemph = 0.0f; - 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 ); st->active_cnt = 0; #ifndef IVAS_FLOAT_FIXED st->old_hpfilt_in = 0.0f; @@ -1646,8 +1655,6 @@ ivas_error init_encoder_ivas_fx( st->input_fx = st->input_buff_fx + frame_length; } #if 1 // TODO: To be removed later - 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; st->old_inp_16k = st->hSignalBuf->old_inp_16k_flt; #ifndef IVAS_FLOAT_FIXED @@ -1655,8 +1662,6 @@ ivas_error init_encoder_ivas_fx( st->buf_speech_enc_flt = st->hSignalBuf->buf_speech_enc_flt; st->buf_wspeech_enc_flt = st->hSignalBuf->buf_wspeech_enc_flt; #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 ); #ifndef IVAS_FLOAT_FIXED @@ -1679,8 +1684,6 @@ ivas_error init_encoder_ivas_fx( st->buf_wspeech_enc = NULL; st->input_buff_fx = NULL; #if 1 - st->mem_decim = NULL; - st->mem_decim16k = NULL; st->old_inp_12k8 = NULL; st->old_inp_16k = NULL; #ifndef IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 0284cacf345829d11cd77df1ce96025a1420efd6..c8e6b0f12cfa7d0ca688ad3ab26ae44d67bfc0de 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -60,9 +60,9 @@ ivas_error ivas_core_enc( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ - const int16_t n_CoreChannels, /* i : number of core channels to be coded */ - 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 */ + const Word16 n_CoreChannels, /* i : number of core channels to be coded */ + Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */ + Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */ Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6 */ 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 */ @@ -70,21 +70,22 @@ ivas_error ivas_core_enc( Word16 epsP_fx_q[], /* i : LP prediction errors */ 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) */ + const Word16 vad_hover_flag[], /* i : VAD hanglover flag */ + Word16 attack_flag[], /* i : attack flag (GSC or TC) */ Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ Word16 *q_re_im_buf, - float old_wsp[][L_WSP], /* i : weighted input signal buffer */ - const int16_t loc_harm[], /* i : harmonicity flag */ + Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer */ + Word16 e_old_wsp[], + const Word16 loc_harm[], /* i : harmonicity flag */ 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 */ + const Word16 vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ Word16 enerBuffer_fx_exp[], /* o : energy buffer */ Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer */ - const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag */ - const int16_t ivas_format, /* i : IVAS format */ - const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag */ + const Word16 ivas_format, /* i : IVAS format */ + const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ) { Word16 n, input_frame; @@ -92,10 +93,9 @@ ivas_error ivas_core_enc( Encoder_State **sts, *st; STEREO_ICBWE_ENC_HANDLE hStereoICBWE; STEREO_TD_ENC_DATA_HANDLE hStereoTD; - float *inp[CPE_CHANNELS]; Word16 Q_new[CPE_CHANNELS] = { 0 }; Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ -#ifdef IVAS_FLOAT_FIXED + Word32 shb_speech_fx32[L_FRAME16k]; Word32 *new_swb_speech_fx; Word16 *inp_fx[CPE_CHANNELS]; Word16 shb_speech_fx[L_FRAME16k]; // Q_shb_spch @@ -107,7 +107,6 @@ ivas_error ivas_core_enc( Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ Word16 *new_swb_speech_fx_16; Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; -#endif Word16 Voicing_flag[CPE_CHANNELS]; Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q6 */ Word16 unbits[CPE_CHANNELS]; @@ -194,7 +193,7 @@ ivas_error ivas_core_enc( input_Fs = sts[0]->input_Fs; move32(); - input_frame = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + input_frame = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); // Q0 FOR( n = 0; n < n_CoreChannels; n++ ) { @@ -228,35 +227,14 @@ ivas_error ivas_core_enc( Scale_sig( fft_buff_fx[n], ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum // fft_buff_fx_exp = add(fft_buff_fx_exp,1); -#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_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], -#ifndef IVAS_FLOAT_FIXED - cor_map_sum[n], -#endif - vad_flag_dtx[n], -#ifndef IVAS_FLOAT_FIXED - enerBuffer[n], - fft_buff[n], -#endif - MCT_flag, vad_hover_flag[n], flag_16k_smc -#ifdef IVAS_FLOAT_FIXED - , - enerBuffer_fx[n], - enerBuffer_fx_exp[n], - fft_buff_fx[n], - cor_map_sum_fx[n], - &Q_new[n] -#endif - ) ) != IVAS_ERR_OK ) + 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_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, + &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], + vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ) != IVAS_ERR_OK ) { return error; } @@ -275,6 +253,7 @@ ivas_error ivas_core_enc( diff_nBits = 0; move16(); + test(); test(); IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) @@ -300,8 +279,8 @@ ivas_error ivas_core_enc( /* write TD stereo spatial parameters */ move_indices( hStereoTD->tdm_hBstr_tmp.ind_list, st->hBstr->ind_list, hStereoTD->tdm_hBstr_tmp.nb_ind_tot ); - st->hBstr->nb_ind_tot += hStereoTD->tdm_hBstr_tmp.nb_ind_tot; - st->hBstr->nb_bits_tot += hStereoTD->tdm_hBstr_tmp.nb_bits_tot; + st->hBstr->nb_ind_tot = add( st->hBstr->nb_ind_tot, hStereoTD->tdm_hBstr_tmp.nb_ind_tot ); + st->hBstr->nb_bits_tot = add( st->hBstr->nb_bits_tot, hStereoTD->tdm_hBstr_tmp.nb_bits_tot ); reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP ); } @@ -321,22 +300,7 @@ ivas_error ivas_core_enc( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_old_inp_16k_fx; - Word16 q_old_inp_12k8_fx; - Word16 old_inp_16k_fx[L_INP]; - Word16 old_inp_12k8_fx[L_INP_12k8]; - Word16 Q_old_syn_12k8_16k; - - q_old_inp_12k8_fx = Q_factor_arr( old_inp_12k8[n], L_INP_12k8 ); - q_old_inp_16k_fx = Q_factor_arr( old_inp_16k[n], L_INP ); - - - floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, q_old_inp_12k8_fx, L_INP_12k8 ); - floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx, q_old_inp_16k_fx, L_INP ); -#endif - - core_switching_pre_enc_ivas_fx( st, old_inp_12k8_fx, q_old_inp_12k8_fx, old_inp_16k_fx, q_old_inp_16k_fx, sts[0]->active_cnt, last_element_mode ); + core_switching_pre_enc_ivas_fx( st, old_inp_12k8_fx[n], sub( Q_new[n], 1 ), old_inp_16k_fx[n], sub( Q_new[n], 1 ), sts[0]->active_cnt, last_element_mode ); /*---------------------------------------------------------------------* * ACELP core encoding @@ -346,17 +310,13 @@ ivas_error ivas_core_enc( IF( st->core == ACELP_CORE ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 inp_buff[CPE_CHANNELS][L_FRAME16k + M + 1]; - inp_fx[n] = &inp_buff[n][M]; - floatToFixed_arr( &inp[n][-M], &inp_fx[n][-M], Q_new[n] - 1, L_FRAME16k + M ); -#endif /* ACELP core encoder */ + Word16 Q_old_syn_12k8_16k; 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 ) { return error; } - Scale_sig( old_syn_12k8_16k_fx[n], st->L_frame, sub( sub( Q_new[n], 1 ), Q_old_syn_12k8_16k ) ); + Scale_sig( old_syn_12k8_16k_fx[n], st->L_frame, sub( sub( Q_new[n], 1 ), Q_old_syn_12k8_16k ) ); // Q_old_syn_12k8_16k -> Q_new[n] - 1 } test(); @@ -367,34 +327,27 @@ ivas_error ivas_core_enc( { 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 TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - - // Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); - // hTcxEnc->spectrum_e[0] = 31 - q_spectrum; - // floatToFixed_arrL32( hTcxEnc->spectrum[0], hTcxEnc->spectrum_fx[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); - // IF( hTcxEnc->tcxMode != TCX_20 ) - //{ - // q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[1], st->hTcxEnc->L_frameTCX / nSubframes ); - // 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 ); - // } -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - 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 Word16 Q_spec_old, L_spec; - Q_spec_old = hTcxEnc->spectrum_long_e; - move16(); + + Scale_sig( old_inp_12k8_fx[n], L_INP_12k8, sub( Q1, Q_new[n] ) ); // Q0 + Scale_sig( old_inp_16k_fx[n], L_INP, sub( Q1, Q_new[n] ) ); // Q0 + Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( -1, st->hTcxEnc->q_Txnq ) ); st->hTcxEnc->q_Txnq = -Q1; move16(); + + Q_spec_old = hTcxEnc->spectrum_long_e; + 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 ); + stereo_tcx_core_enc( st, old_inp_12k8_fx[n] + L_INP_MEM, old_inp_16k_fx[n] + 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 ); + + Scale_sig( old_inp_12k8_fx[n], L_INP_12k8, sub( Q_new[n], Q1 ) ); // Q_new[n] - 1 + Scale_sig( old_inp_16k_fx[n], L_INP, sub( Q_new[n], Q1 ) ); // Q_new[n] - 1 Scale_sig( st->hTcxEnc->old_out_fx, L_FRAME32k, -st->hTcxEnc->Q_old_out ); // scaling back to Q0 st->hTcxEnc->Q_old_out = 0; + move16(); IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) { @@ -402,8 +355,8 @@ ivas_error ivas_core_enc( move16(); Word16 e_max = s_max( hTcxEnc->spectrum_e[0], Q_spec_old ); e_max = sub( e_max, L_norm_arr( hTcxEnc->spectrum_long_fx, N_MAX ) ); - scale_sig32( hTcxEnc->spectrum_fx[0], L_spec, sub( hTcxEnc->spectrum_e[0], e_max ) ); - scale_sig32( hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old, e_max ) ); + scale_sig32( hTcxEnc->spectrum_fx[0], L_spec, sub( hTcxEnc->spectrum_e[0], e_max ) ); // exp(e_max) + scale_sig32( hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old, e_max ) ); // exp(e_max) hTcxEnc->spectrum_long_e = e_max; move16(); @@ -413,10 +366,10 @@ ivas_error ivas_core_enc( Word16 e_max = s_max( Q_spec_old, s_max( hTcxEnc->spectrum_e[0], hTcxEnc->spectrum_e[1] ) ); e_max = sub( e_max, L_norm_arr( hTcxEnc->spectrum_long_fx, N_MAX ) ); L_spec = shr( st->hTcxCfg->tcx_coded_lines, 1 ); - scale_sig32( hTcxEnc->spectrum_fx[0], L_spec, sub( hTcxEnc->spectrum_e[0], e_max ) ); - scale_sig32( hTcxEnc->spectrum_fx[1], L_spec, sub( hTcxEnc->spectrum_e[1], e_max ) ); - scale_sig32( hTcxEnc->spectrum_fx[0] + L_spec, N_TCX10_MAX - L_spec, sub( Q_spec_old, e_max ) ); - scale_sig32( hTcxEnc->spectrum_fx[1] + L_spec, sub( N_MAX - N_TCX10_MAX, L_spec ), sub( Q_spec_old, e_max ) ); + scale_sig32( hTcxEnc->spectrum_fx[0], L_spec, sub( hTcxEnc->spectrum_e[0], e_max ) ); // exp(e_max) + scale_sig32( hTcxEnc->spectrum_fx[1], L_spec, sub( hTcxEnc->spectrum_e[1], e_max ) ); // exp(e_max) + scale_sig32( hTcxEnc->spectrum_fx[0] + L_spec, N_TCX10_MAX - L_spec, sub( Q_spec_old, e_max ) ); // exp(e_max) + scale_sig32( hTcxEnc->spectrum_fx[1] + L_spec, sub( N_MAX - N_TCX10_MAX, L_spec ), sub( Q_spec_old, e_max ) ); // exp(e_max) hTcxEnc->spectrum_long_e = s_max( Q_spec_old, s_max( hTcxEnc->spectrum_e[0], hTcxEnc->spectrum_e[1] ) ); move16(); @@ -430,13 +383,13 @@ ivas_error ivas_core_enc( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core encoder */ - Scale_sig( st->input_fx, input_frame, negate( st->q_inp ) ); + Scale_sig( st->input_fx, input_frame, negate( st->q_inp ) ); // Q0 st->q_inp = 0; move16(); - Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); // Q0 st->q_old_inp = 0; move16(); - Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( 0, st->hTcxEnc->q_Txnq ) ); + Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( 0, st->hTcxEnc->q_Txnq ) ); // Q0 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] ); @@ -468,32 +421,24 @@ ivas_error ivas_core_enc( { Word16 mdst_spectrum_e[CPE_CHANNELS][NB_DIV]; Word16 orig_spectrum_e[CPE_CHANNELS][NB_DIV]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_inp_16k_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++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { - Encoder_State *st1 = sts[i]; - floatToFixed_arr( old_inp_16k[i], old_inp_16k_fx[i], 0, L_INP ); - q_fac[i] = Q_factor_arr( old_wsp[i], L_WSP ); - floatToFixed_arr( old_wsp[i], old_wsp_fx[i], q_fac[i], L_WSP ); - if ( st1->element_mode == IVAS_CPE_DFT ) - { - } - else if ( st1->element_mode != IVAS_CPE_MDCT ) + st = sts[n]; + Scale_sig( old_inp_16k_fx[i], L_INP, sub( Q1, Q_new[i] ) ); // Q0 + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - st1->hTcxEnc->exp_buf_speech_ltp = st1->exp_buf_speech_enc; + st->hTcxEnc->exp_buf_speech_ltp = st->exp_buf_speech_enc; + move16(); } - Scale_sig( st1->input_fx, input_frame, negate( st1->q_inp ) ); - Scale_sig( st1->old_input_signal_fx, input_frame, negate( st1->q_old_inp ) ); - st1->q_old_inp = 0; + Scale_sig( st->input_fx, input_frame, negate( st->q_inp ) ); // Q0 + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); // Q0 + st->q_old_inp = 0; move16(); - st1->q_inp = 0; + st->q_inp = 0; move16(); } -#endif Word16 Q_spec_old[2], L_spec; Q_spec_old[0] = hCPE->hCoreCoder[0]->hTcxEnc->spectrum_long_e; move16(); @@ -505,10 +450,11 @@ ivas_error ivas_core_enc( FOR( i = 0; i < CPE_CHANNELS; i++ ) { - Encoder_State *st1 = sts[i]; + st = sts[i]; Word16 nSubframes = NB_DIV; move16(); - if ( EQ_16( st1->hTcxEnc->tcxMode, TCX_20 ) ) + Scale_sig( old_inp_16k_fx[i], L_INP, sub( Q_new[i], Q1 ) ); // Q_new[n] - 1 + if ( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) { nSubframes = 1; move16(); @@ -524,8 +470,8 @@ ivas_error ivas_core_enc( IF( EQ_16( nSubframes, NB_DIV ) ) { Word16 max_e = s_max( orig_spectrum_e[i][0], orig_spectrum_e[i][1] ); - Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); - Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); + Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); // exp(max_e) + Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); // exp(max_e) hMCT->q_orig_spectrum_long_fx[cpe_id][i] = max_e; move16(); } @@ -534,72 +480,53 @@ ivas_error ivas_core_enc( hMCT->q_orig_spectrum_long_fx[cpe_id][i] = orig_spectrum_e[i][0]; move16(); } - } - for ( i = 0; i < CPE_CHANNELS; i++ ) - { - Encoder_State *st1 = sts[i]; - IF( EQ_16( st1->hTcxEnc->tcxMode, TCX_20 ) ) + + IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) { - Word16 e_max = s_max( st1->hTcxEnc->spectrum_e[0], Q_spec_old[i] ); - e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); - L_spec = st1->hTcxEnc->L_frameTCX; + Word16 e_max = s_max( st->hTcxEnc->spectrum_e[0], Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st->hTcxEnc->spectrum_long_fx, N_MAX ) ); + L_spec = st->hTcxEnc->L_frameTCX; move16(); - scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); + scale_sig32( st->hTcxEnc->spectrum_fx[0], L_spec, sub( st->hTcxEnc->spectrum_e[0], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); // exp(e_max) - st1->hTcxEnc->spectrum_long_e = e_max; + st->hTcxEnc->spectrum_long_e = e_max; move16(); } ELSE { - Word16 e_max = s_max( s_max( st1->hTcxEnc->spectrum_e[0], st1->hTcxEnc->spectrum_e[1] ), Q_spec_old[i] ); - e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); - L_spec = shr( st1->hTcxEnc->L_frameTCX, 1 ); - scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[0] + L_spec, sub( N_TCX10_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[1], L_spec, sub( st1->hTcxEnc->spectrum_e[1], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[1] + L_spec, sub( ( N_MAX - N_TCX10_MAX ), L_spec ), sub( Q_spec_old[i], e_max ) ); - - st1->hTcxEnc->spectrum_long_e = e_max; + Word16 e_max = s_max( s_max( st->hTcxEnc->spectrum_e[0], st->hTcxEnc->spectrum_e[1] ), Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st->hTcxEnc->spectrum_long_fx, N_MAX ) ); + L_spec = shr( st->hTcxEnc->L_frameTCX, 1 ); + scale_sig32( st->hTcxEnc->spectrum_fx[0], L_spec, sub( st->hTcxEnc->spectrum_e[0], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_fx[0] + L_spec, sub( N_TCX10_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_fx[1], L_spec, sub( st->hTcxEnc->spectrum_e[1], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_fx[1] + L_spec, sub( ( N_MAX - N_TCX10_MAX ), L_spec ), sub( Q_spec_old[i], e_max ) ); // exp(e_max) + + st->hTcxEnc->spectrum_long_e = e_max; move16(); } - st1->hTcxEnc->spectrum_e[0] = st1->hTcxEnc->spectrum_long_e; + st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_long_e; move16(); - st1->hTcxEnc->spectrum_e[1] = st1->hTcxEnc->spectrum_long_e; + st->hTcxEnc->spectrum_e[1] = st->hTcxEnc->spectrum_long_e; move16(); } -#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 ); - } -#endif } ELSE { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_inp_16k_fx[CPE_CHANNELS][L_INP]; - Word16 old_wsp_fx[CPE_CHANNELS][L_WSP], q_fac[CPE_CHANNELS]; - for ( i = 0; i < CPE_CHANNELS; i++ ) - { - floatToFixed_arr( old_inp_16k[i], old_inp_16k_fx[i], 0, L_INP ); - q_fac[i] = Q_factor_arr( old_wsp[i], L_WSP ); - floatToFixed_arr( old_wsp[i], old_wsp_fx[i], q_fac[i], L_WSP ); - } - for ( i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { - Encoder_State *st1 = sts[i]; - if ( st1->element_mode == IVAS_CPE_DFT ) - { - } - else if ( st1->element_mode != IVAS_CPE_MDCT ) + st = sts[i]; + Scale_sig( old_inp_16k_fx[i], L_INP, sub( Q1, Q_new[i] ) ); // Q0 + + test(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - st1->hTcxEnc->exp_buf_speech_ltp = st1->exp_buf_speech_enc; + st->hTcxEnc->exp_buf_speech_ltp = st->exp_buf_speech_enc; + move16(); } } -#endif Word16 Q_spec_old[2], L_spec; Q_spec_old[0] = hCPE->hCoreCoder[0]->hTcxEnc->spectrum_long_e; @@ -609,51 +536,39 @@ ivas_error ivas_core_enc( stereo_mdct_core_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx ); - for ( i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { - Encoder_State *st1 = sts[i]; - IF( EQ_16( st1->hTcxEnc->tcxMode, TCX_20 ) ) + Scale_sig( old_inp_16k_fx[i], L_INP, sub( Q_new[i], Q1 ) ); // Q_new[n] - 1 + st = sts[i]; + IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) { - L_spec = st1->hTcxEnc->L_frameTCX; + L_spec = st->hTcxEnc->L_frameTCX; move16(); - Word16 e_max = s_max( st1->hTcxEnc->spectrum_e[0], Q_spec_old[i] ); - e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); - st1->hTcxEnc->spectrum_long_e = e_max; + Word16 e_max = s_max( st->hTcxEnc->spectrum_e[0], Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st->hTcxEnc->spectrum_long_fx, N_MAX ) ); + scale_sig32( st->hTcxEnc->spectrum_fx[0], L_spec, sub( st->hTcxEnc->spectrum_e[0], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); // exp(e_max) + st->hTcxEnc->spectrum_long_e = e_max; move16(); } ELSE { - L_spec = shr( st1->hTcxEnc->L_frameTCX, 1 ); - Word16 e_max = s_max( s_max( st1->hTcxEnc->spectrum_e[1], st1->hTcxEnc->spectrum_e[0] ), Q_spec_old[i] ); - e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[0] + L_spec, sub( N_TCX10_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[1], L_spec, sub( st1->hTcxEnc->spectrum_e[1], e_max ) ); - scale_sig32( st1->hTcxEnc->spectrum_fx[1] + L_spec, sub( ( N_MAX - N_TCX10_MAX ), L_spec ), sub( Q_spec_old[i], e_max ) ); - st1->hTcxEnc->spectrum_long_e = e_max; + L_spec = shr( st->hTcxEnc->L_frameTCX, 1 ); + Word16 e_max = s_max( s_max( st->hTcxEnc->spectrum_e[1], st->hTcxEnc->spectrum_e[0] ), Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st->hTcxEnc->spectrum_long_fx, N_MAX ) ); + scale_sig32( st->hTcxEnc->spectrum_fx[0], L_spec, sub( st->hTcxEnc->spectrum_e[0], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_fx[0] + L_spec, sub( N_TCX10_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_fx[1], L_spec, sub( st->hTcxEnc->spectrum_e[1], e_max ) ); // exp(e_max) + scale_sig32( st->hTcxEnc->spectrum_fx[1] + L_spec, sub( ( N_MAX - N_TCX10_MAX ), L_spec ), sub( Q_spec_old[i], e_max ) ); // exp(e_max) + st->hTcxEnc->spectrum_long_e = e_max; move16(); } - st1->hTcxEnc->spectrum_e[0] = st1->hTcxEnc->spectrum_long_e; + st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_long_e; move16(); - st1->hTcxEnc->spectrum_e[1] = st1->hTcxEnc->spectrum_long_e; + st->hTcxEnc->spectrum_e[1] = st->hTcxEnc->spectrum_long_e; move16(); } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Word16 k; - for ( i = 0; i < CPE_CHANNELS; i++ ) - { - fixedToFloat_arr( old_wsp_fx[i], old_wsp[i], q_fac[i], L_WSP ); - // Word16 length = sts[i]->hTcxEnc->L_frameTCX / ( ( sts[i]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); - // FOR( k = 0; k <= ( ( sts[i]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) - //{ - // fixedToFloat_arrL32( sts[i]->hTcxEnc->spectrum_fx[k], sts[i]->hTcxEnc->spectrum[k], 31 - sts[i]->hTcxEnc->spectrum_e[k], length ); - // } - } -#endif } } ELSE IF( EQ_32( sts[0]->core_brate, SID_2k40 ) && EQ_32( sts[1]->core_brate, SID_2k40 ) ) @@ -665,7 +580,7 @@ ivas_error ivas_core_enc( test(); IF( ( NE_16( st->hFdCngEnc->hFdCngCom->frameSize, st->L_frame ) ) || ( NE_16( st->hFdCngEnc->hFdCngCom->CngBandwidth, st->bwidth ) ) ) { - configureFdCngEnc( st->hFdCngEnc, s_max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); + configureFdCngEnc( st->hFdCngEnc, s_max( st->bwidth, WB ), EQ_16( st->L_frame, L_FRAME16k ) ? ACELP_16k40 : ACELP_9k60 ); } } @@ -680,26 +595,6 @@ ivas_error ivas_core_enc( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 shb_speech_fx32[L_FRAME16k]; - Word16 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8], old_inp_16k_fx[CPE_CHANNELS][L_INP]; - for ( n = 0; n < n_CoreChannels; n++ ) - { - st = sts[n]; - Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); - Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); - st->q_old_inp = st->q_inp = 0; - move16(); - move16(); - /*---------------------------------------------------------------------* - * Postprocessing for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - - // prev_lsp_wb_temp_fx, prev_lsp_wb_fx and prev_lpc_wb_fx in Q15. No float counterparts - 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 ); - } -#endif /*---------------------------------------------------------------------* * Postprocessing, BWEs and Updates *---------------------------------------------------------------------*/ @@ -708,6 +603,12 @@ ivas_error ivas_core_enc( { st = sts[n]; + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); // Q0 + Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); // Q0 + st->q_old_inp = st->q_inp = 0; + move16(); + move16(); + IF( st->hTcxEnc != NULL ) { st->hTcxEnc->exp_buf_speech_ltp = 31; // Q0 @@ -906,7 +807,7 @@ ivas_error ivas_core_enc( } IF( st->hTcxEnc != NULL ) { - Scale_sig( st->hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( st->hTcxEnc->exp_buf_speech_ltp ) ); + Scale_sig( st->hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( st->hTcxEnc->exp_buf_speech_ltp ) ); // Q0 } } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index d19f9a06fa9cb30e85d118b2d227348f01777ab5..d2abdfb1a1fbde71135ac1d5ef91f336b0129034 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -57,10 +57,9 @@ ivas_error pre_proc_ivas( 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*/ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz */ + Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame*/ Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q6 */ 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 */ @@ -70,12 +69,13 @@ ivas_error pre_proc_ivas( Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ Word16 *new_inp_resamp16k_fx, /* 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 */ + Word16 old_wsp_fx[], /* i : weighted input signal buffer */ + Word16 e_old_wsp, + 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], @@ -87,9 +87,8 @@ ivas_error pre_proc_ivas( ) { Word16 L_look, element_mode, lMemRecalc_12k8; - float *inp_12k8, *new_inp_12k8, *inp_16k; /* pointers to current frame and new data */ - Word16 *inp_16k_fx, *new_inp_12k8_fx; - float *wsp; /* weighted input signal buffer */ + Word16 *inp_16k_fx, *new_inp_12k8_fx, *inp_12k8_fx; /* pointers to current frame and new data */ + Word16 *wsp_fx; /* weighted input signal buffer */ Word32 sr_core_tmp, total_brate_tmp; ivas_error error; @@ -105,21 +104,15 @@ ivas_error pre_proc_ivas( element_mode = st->element_mode; move16(); - 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 ( NE_16( element_mode, IVAS_CPE_DFT ) ) - { - new_inp_12k8 -= L_FILT; - } new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8_fx = new_inp_12k8_fx - L_LOOK_12k8; if ( NE_16( element_mode, IVAS_CPE_DFT ) ) { new_inp_12k8_fx -= L_FILT; } - wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + wsp_fx = old_wsp_fx + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ lMemRecalc_12k8 = 0; move16(); @@ -543,22 +536,14 @@ ivas_error pre_proc_ivas( L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ move16(); - inp_16k = old_inp_16k + L_INP_MEM - L_look; + inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_inp_16k_fx[L_INP], Q_old_inp_16k = -1; - Word16 Q_r[2] = { 0 }, exp_wsp; - Word16 old_wsp_fx[L_WSP], wsp_fx[L_FRAME + L_LOOK_12k8]; + Word16 Q_old_inp_16k = -1; + Word16 Q_r[2] = { 0 }; inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; - st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); - - floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); - floatToFixed_arr16( wsp, wsp_fx, Q_old_inp_16k, (Word16) ( L_FRAME + L_LOOK_12k8 ) ); - f2me_buf_16( old_wsp, old_wsp_fx, &exp_wsp, L_WSP ); f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); - floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); - floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); if ( st->hBWE_FD != NULL ) { Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); @@ -631,29 +616,24 @@ ivas_error pre_proc_ivas( /* update old weighted speech buffer - for OL pitch analysis */ Copy( &old_wsp_fx[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); - st->exp_old_wsp = exp_wsp; + st->exp_old_wsp = e_old_wsp; move16(); st->exp_buf_speech_enc_pe = sub( Q15, *Q_new - 1 ); move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // No need to do fixed to float for signal_in_fx - st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); - - fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, *Q_new - 1, L_INP ); fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, *Q_new - 1, L_INP_MEM ); - fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); - fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); #endif /* set the pointer of the current frame for the ACELP core */ IF( EQ_16( st->L_frame, L_FRAME ) ) { - *inp = inp_12k8; + *inp_fx = inp_12k8_fx; } ELSE { - *inp = inp_16k; + *inp_fx = inp_16k_fx; } /* Update VAD hangover frame counter in active frames */ diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 8982be68d1c2f7a308898f279cdab665782285ea..2975ddd3b560f40da2e31806dde92aa7f8a81694 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -926,8 +926,6 @@ ivas_error pre_proc_front_ivas_fx( st = hCPE->hCoreCoder[n]; } Word16 old_inp_12k8_e; - Word16 mem_decim_e; - f2me_buf_16( st->mem_decim, st->mem_decim_fx, &mem_decim_e, 2 * L_FILT_MAX ); f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); f2me_buf_16( old_inp_12k8, old_inp_12k8_fx, &old_inp_12k8_e, 496 ); if ( old_inp_12k8_e > st->exp_old_inp_12k8 ) @@ -940,12 +938,6 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig( old_inp_12k8_fx, 496, old_inp_12k8_e - st->exp_old_inp_12k8 ); old_inp_12k8_e = st->exp_old_inp_12k8; } - Word16 mem_preemph_DFT_e; - Word16 inp_12k8_mem_stereo_sw_e; - Word16 mem_preemph_e; - f2me_buf_16( st->inp_12k8_mem_stereo_sw, st->inp_12k8_mem_stereo_sw_fx, &inp_12k8_mem_stereo_sw_e, 4 ); - f2me_16( st->mem_preemph_DFT, &st->mem_preemph_DFT_fx, &mem_preemph_DFT_e ); - f2me_16( st->mem_preemph, &st->mem_preemph_fx, &mem_preemph_e ); float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ float *wsp; /* weighted input signal buffer */ float Etot; /* total energy */ @@ -1412,7 +1404,6 @@ ivas_error pre_proc_front_ivas_fx( // floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_to_be_looked_into, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); // input_fx and old_input_signal_fx already in Q(-1). All these point to input_buff - floatToFixed_arr( st->mem_decim, st->mem_decim_fx, Q_to_be_looked_into, 2 * L_FILT_MAX ); floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); #endif test(); @@ -1465,7 +1456,6 @@ ivas_error pre_proc_front_ivas_fx( // fixedToFloat_arr( st->input_buff_fx, st->input_buff, Q_to_be_looked_into, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); // input_fx and old_input_signal_fx already in Q(-1). All these point to input_buff - fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, Q_to_be_looked_into, 2 * L_FILT_MAX ); fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_to_be_looked_into, L_INP_12k8 ); #endif old_inp_12k8_e = sub( 15, Q_to_be_looked_into ); @@ -1592,9 +1582,6 @@ ivas_error pre_proc_front_ivas_fx( #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); - floatToFixed_arr( st->inp_12k8_mem_stereo_sw, st->inp_12k8_mem_stereo_sw_fx, Q_to_be_looked_into, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); - floatToFixed_arr( &st->mem_preemph, &st->mem_preemph_fx, Q_to_be_looked_into, 1 ); - floatToFixed_arr( &st->mem_preemph_DFT, &st->mem_preemph_DFT_fx, Q_to_be_looked_into, 1 ); #endif Word16 Q_new = 1; @@ -1750,9 +1737,6 @@ ivas_error pre_proc_front_ivas_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_new, L_INP_12k8 ); - fixedToFloat_arr( st->inp_12k8_mem_stereo_sw_fx, st->inp_12k8_mem_stereo_sw, Q_to_be_looked_into, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); - st->mem_preemph = fixedToFloat_16( st->mem_preemph_fx, Q_to_be_looked_into ); - st->mem_preemph_DFT = fixedToFloat_16( st->mem_preemph_DFT_fx, Q_to_be_looked_into ); cldfbScale.hb_scale = cldfbScale.lb_scale; #endif @@ -2731,12 +2715,9 @@ ivas_error pre_proc_front_ivas_fx( { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_old_inp_16k = -1; - st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, 880 ); floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); - floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); - floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); if ( st->hBWE_FD != NULL ) { @@ -2768,12 +2749,8 @@ ivas_error pre_proc_front_ivas_fx( *epsP_fx_q = add( Q_r[0], 1 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // No need to do fixed to float for signal_in_fx - st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); - fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); - fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); - fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); #endif #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 43f7f994da57cd78c6e6145c73656f186bf8637f..ae01f6d54e1d3df3d75ddb0d5c158a13105a5163 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -1181,7 +1181,20 @@ 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_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 old_wsp_fx[CPE_CHANNELS][L_WSP]; + Word16 e_old_wsp[CPE_CHANNELS]; + Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP]; + for ( n = 0; n < n_CoreChannels; n++ ) + { + floatToFixed_arr( old_inp_16k[n], old_inp_16k_16fx[n], -1, L_INP ); + floatToFixed_arr( old_inp_12k8[n], old_inp_12k8_16fx[n], -1, L_INP_12k8 ); + floatToFixed_arr( old_wsp[n], old_wsp_fx[n], -1, L_WSP ); + e_old_wsp[n] = 16; + } +#endif + if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 01ffc82b3c915cc9304f4f2bbba7cc339ed571c3..d6dedf0b981df795807d7dd728d80989ca529796 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -778,7 +778,20 @@ 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_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 old_wsp_fx[MAX_NUM_OBJECTS][CPE_CHANNELS][L_WSP]; + Word16 e_old_wsp[MAX_NUM_OBJECTS][CPE_CHANNELS]; + Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][CPE_CHANNELS][L_INP]; + for ( int n = 0; n < 1; n++ ) + { + floatToFixed_arr( old_inp_16k[sce_id][n], old_inp_16k_fx[sce_id][n], -1, L_INP ); + floatToFixed_arr( old_inp_12k8[sce_id][n], old_inp_12k8_fx[sce_id][n], -1, L_INP_12k8 ); + floatToFixed_arr( old_wsp[sce_id][n], old_wsp_fx[sce_id][n], -1, L_WSP ); + e_old_wsp[sce_id][n] = 16; + } +#endif + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_mct_enc_mct.c b/lib_enc/ivas_mct_enc_mct.c index 0cfad1d3b97040585f7a7316d71033c5b9d434d1..a70904e571a7731586516c87d0716aaf32dcc36b 100644 --- a/lib_enc/ivas_mct_enc_mct.c +++ b/lib_enc/ivas_mct_enc_mct.c @@ -1422,16 +1422,20 @@ void apply_MCT_enc_fx( L_subframeTCX = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); } + Word16 exp; IF( hMCT->lowE_ch[ch] ) { // qratio = (float) hMCT->mc_global_ild[ch] / SMDCT_ILD_RANGE; - qratio = div_l( L_shl( hMCT->mc_global_ild[ch], 11 ), SMDCT_ILD_RANGE / 2 ); // Q11 + qratio = div_l( L_shl( hMCT->mc_global_ild[ch], 11 ), SMDCT_ILD_RANGE ); // Q10 } ELSE { // qratio = (float) SMDCT_ILD_RANGE / hMCT->mc_global_ild[ch]; - qratio = shl_sat( div_l( ( (Word32) SMDCT_ILD_RANGE << 11 ), hMCT->mc_global_ild[ch] ), 1 ); // Q11 + qratio = div_l( ( SMDCT_ILD_RANGE << 11 ), hMCT->mc_global_ild[ch] ); // Q10 } + exp = norm_s( qratio ); + qratio = shl( qratio, exp ); + exp = sub( 5, exp ); // Q = 10 + exp FOR( k = 0; k < nSubframes; k++ ) { @@ -1439,8 +1443,8 @@ void apply_MCT_enc_fx( v_multc_fixed( mdst_spectrum[ch][k], L_deposit_h( qratio ), mdst_spectrum[ch][k], L_subframeTCX ); set32_fx( inv_spectrum[ch][k], 0, L_subframeTCX ); } - sts[ch]->hTcxEnc->spectrum_e[1] = add( sts[ch]->hTcxEnc->spectrum_e[0], 4 ); - sts[ch]->hTcxEnc->spectrum_e[0] = add( sts[ch]->hTcxEnc->spectrum_e[0], 4 ); + sts[ch]->hTcxEnc->spectrum_e[1] = add( sts[ch]->hTcxEnc->spectrum_e[0], exp ); + sts[ch]->hTcxEnc->spectrum_e[0] = add( sts[ch]->hTcxEnc->spectrum_e[0], exp ); hMCT->mc_global_ild[ch] = 0; move16(); move16(); diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 7b25e5ac39755ace7a7802e2c38f406eab7786d3..9078624168a91b3f0450fc70452368d5e067c009 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -341,7 +341,19 @@ ivas_error ivas_sce_enc_fx( * Encoder *----------------------------------------------------------------*/ - IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 old_wsp_fx[1][L_WSP]; + Word16 e_old_wsp[1]; + Word16 old_inp_16k_fx[1][L_INP]; + for ( int n = 0; n < 1; n++ ) + { + floatToFixed_arr( old_inp_16k[n], old_inp_16k_fx[n], -1, L_INP ); + floatToFixed_arr( old_inp_12k8[n], old_inp_12k8_fx[n], -1, L_INP_12k8 ); + floatToFixed_arr( old_wsp[n], old_wsp_fx[n], -1, L_WSP ); + e_old_wsp[n] = 16; + } +#endif + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 7e0de47b1af6fa862cdb9ba27a16da56521436e7..89aacf215cc555c0a5b956277d5d97df6663bf11 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -4434,7 +4434,7 @@ static void tonal_context_improv_fx( test(); IF( st_fx->sp_aud_decision1 == 1 && ( GT_32( L_min( L_min( tonality1, tonality2 ), tonality3 ), 1638400 ) ) && - ( GT_32( L_add( tonality1, tonality2 ), 6553600 ) && GT_32( L_add( tonality2, tonality3 ), 6553600 ) && GT_32( L_add( tonality1, tonality3 ), 6553600 ) ) && + ( GT_32( L_add_sat( tonality1, tonality2 ), 6553600 ) && GT_32( L_add_sat( tonality2, tonality3 ), 6553600 ) && GT_32( L_add_sat( tonality1, tonality3 ), 6553600 ) ) && ( LT_32( hSpMusClas->lt_tonality, 655360000 ) ) && ( ( GT_32( hSpMusClas->lt_tonality, 32768000 ) && GT_16( s_max( hSpMusClas->lt_voicing, voi_mean ), 32440 ) ) || ( GT_32( hSpMusClas->lt_tonality, 49152000 ) && GT_16( hSpMusClas->lt_corr, 32440 ) ) || diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 8d8ffbc794233f07df9e875ead500f24445956a5..2aaf957a1b0472f745983ddc7e198f1ec82046c8 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -105,12 +105,12 @@ typedef struct signal_buffers_enc_data_structure { #ifndef IVAS_FLOAT_FIXED float input_buff_flt[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; - float Bin_E_old_flt[L_FFT / 2]; /* per bin energy of old 2nd frames */ -#endif + float Bin_E_old_flt[L_FFT / 2]; /* per bin energy of old 2nd frames */ float mem_decim_flt[2 * L_FILT_MAX]; /* decimation filter memory */ float mem_decim16k_flt[2 * L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ - float old_inp_12k8_flt[L_INP_MEM]; /* memory of input signal at 12.8kHz */ - float old_inp_16k_flt[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ +#endif + float old_inp_12k8_flt[L_INP_MEM]; /* memory of input signal at 12.8kHz */ + float old_inp_16k_flt[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ #ifndef IVAS_FLOAT_FIXED float buf_synth_flt[OLD_SYNTH_SIZE_ENC + L_FRAME32k]; /* can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching */ float buf_wspeech_enc_flt[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; /* increased by 320 to avoid memory overlap in find_wsp() and also to accomodate for the wspeech_enc */ @@ -2073,8 +2073,8 @@ typedef struct enc_core_structure Word16 streaklimit_fx; /* LSF quantizer Q15 */ Word16 stab_fac_fx; /* LSF stability factor Q15 */ #endif - float mem_preemph; /* preemphasis filter memory */ #ifndef IVAS_FLOAT_FIXED + float mem_preemph; /* preemphasis filter memory */ float old_wsp[L_WSP_MEM]; /* old weighted signal vector */ float old_wsp2[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector */ float mem_wsp; /* weighted signal vector memory */ @@ -2095,7 +2095,7 @@ typedef struct enc_core_structure Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 mem_preemph_fx; /* preemphasis filter memory */ + Word16 mem_preemph_fx; /* preemphasis filter memory Q(-1) */ Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ #ifdef IVAS_FLOAT_FIXED @@ -2261,10 +2261,10 @@ typedef struct enc_core_structure SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; #ifndef IVAS_FLOAT_FIXED - float *Bin_E_old; /* per bin energy of old 2nd frames */ -#endif + float *Bin_E_old; /* per bin energy of old 2nd frames */ float *mem_decim; /* decimation filter memory */ float *mem_decim16k; /* ACELP@16kHz - decimation filter memory @16kHz */ +#endif float *old_inp_12k8; /* memory of input signal at 12.8kHz */ float *old_inp_16k; /* ACELP@16kHz - memory of input signal @16 kHz */ #ifndef IVAS_FLOAT_FIXED @@ -2275,8 +2275,8 @@ typedef struct enc_core_structure #endif 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 *mem_decim_fx; /* decimation filter memory Q(-1) */ + Word16 *mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz Q(-1) */ Word16 *old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ Word16 *old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ @@ -2651,15 +2651,17 @@ typedef struct enc_core_structure Word16 cna_dirac_flag; /* CNA in DirAC flag */ /* stereo switching memories */ +#ifndef IVAS_FLOAT_FIXED float mem_preemph_DFT; float inp_12k8_mem_stereo_sw[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; float mem_preemph16k_DFT; float inp_16k_mem_stereo_sw[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; - - Word16 mem_preemph_DFT_fx; - Word16 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; - Word16 mem_preemph16k_DFT_fx; - Word16 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; +#else + Word16 mem_preemph_DFT_fx; /* Q(-1) */ + Word16 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; /* Q(-1) */ + Word16 mem_preemph16k_DFT_fx; /* Q(-1) */ + Word16 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; /* Q(-1) */ +#endif /* MCT Channel mode indication: LFE, ignore channel? */ MCT_CHAN_MODE mct_chan_mode;