From 1b983b413b344febfc4211493401775194cb21b7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 18 Nov 2024 13:57:11 +0530 Subject: [PATCH] Encoder SCE/CPE cleanup, SBA/OMASA LTV crash fixes --- lib_com/int_lsp.c | 1 + lib_com/ivas_prot.h | 93 ++-- lib_com/ivas_prot_fx.h | 28 +- lib_com/ivas_stat_com.h | 4 +- lib_com/prot.h | 13 +- lib_com/prot_fx.h | 25 + lib_com/rom_com.c | 51 ++ lib_com/stat_com.h | 8 +- lib_dec/acelp_core_dec_ivas_fx.c | 10 +- lib_dec/cng_dec_fx.c | 741 +++++++++++++++++++++++++++-- lib_dec/jbm_pcmdsp_apa.c | 3 + lib_dec/lsf_dec_fx.c | 263 ++++++++++ lib_enc/acelp_core_enc.c | 29 +- lib_enc/analy_lp_fx.c | 4 +- lib_enc/cod4t64.c | 6 + lib_enc/dtx.c | 99 ++-- lib_enc/enc_acelp.c | 10 + lib_enc/enc_acelpx.c | 2 + lib_enc/gs_enc.c | 6 +- lib_enc/inov_enc.c | 2 + lib_enc/ivas_core_pre_proc_front.c | 679 +++++++------------------- lib_enc/ivas_cpe_enc.c | 113 +++-- lib_enc/ivas_front_vad.c | 7 +- lib_enc/ivas_ism_enc.c | 99 ++-- lib_enc/ivas_sce_enc.c | 61 ++- lib_enc/ivas_stat_enc.h | 31 +- lib_enc/ivas_stereo_classifier.c | 52 +- lib_enc/ivas_stereo_dft_enc.c | 4 +- lib_enc/ivas_stereo_dft_enc_itd.c | 124 ++++- lib_enc/ivas_stereo_dft_td_itd.c | 2 +- lib_enc/ivas_stereo_ica_enc.c | 36 +- lib_enc/ivas_stereo_td_analysis.c | 6 +- lib_enc/lsf_enc_fx.c | 4 +- lib_enc/nois_est_fx.c | 2 +- lib_enc/speech_music_classif.c | 11 +- lib_enc/speech_music_classif_fx.c | 19 +- lib_enc/stat_enc.h | 124 ++--- lib_enc/swb_tbe_enc_fx.c | 2 +- 38 files changed, 1815 insertions(+), 959 deletions(-) diff --git a/lib_com/int_lsp.c b/lib_com/int_lsp.c index 0adb332fa..75d76eb94 100644 --- a/lib_com/int_lsp.c +++ b/lib_com/int_lsp.c @@ -344,6 +344,7 @@ void int_lsp4_ivas_fx( } ELSE IF( EQ_16( relax_prev_lsf_interp, -2 ) ) { + // This condition not present in int_lsp4_fx pt_int_coeffs = interpol_frac2_mid_fx; /*Q15*/ } ELSE diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 4296a51fd..2409d91bd 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -227,51 +227,52 @@ ivas_error pre_proc_front_ivas( ); ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const int32_t element_brate, /* i : SCE/CPE element bitrate */ - const int16_t nb_bits_metadata, /* i : number of metadata bits */ - const int16_t input_frame, /* i : frame length */ - const int16_t n, /* i : channel number */ - Word16 old_inp_12k8_fx[], /* o : buffer of old input signal */ - float old_inp_12k8[], /* o : buffer of old input signal */ - float old_inp_16k[], /* o : buffer of old input signal @16kHz */ - float *ener, /* o : residual energy from Levinson-Durbin */ - float *relE, /* o : frame relative energy */ - float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - float epsP[M + 1], /* o : LP prediction errors */ - float lsp_new[M], /* o : LSPs at the end of the frame */ - float lsp_mid[M], /* o : LSPs in the middle of the frame */ - int16_t *vad_hover_flag, /* o : VAD hangover flag */ - int16_t *attack_flag, /* o : flag signaling attack */ - 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[], /* o : weighted input signal buffer */ - float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ - float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ - int16_t *loc_harm, /* o : harmonicity flag */ - float *cor_map_sum, /* o : speech/music clasif. parameter */ - int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ - float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - float fft_buff[2 * L_FFT], /* o : FFT buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ - const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ - const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ - const float currFlatness, /* i : flatness parameter */ - const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ - float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ - const float Etot_LR[], /* i : total energy Left & Right channel */ - float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ - const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ - float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ - const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ - const int16_t force_front_vad, /* i : flag to force VAD decision */ - const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + const Word16 input_frame, /* i : frame length */ + const Word16 n, /* i : channel number */ + Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + Word16 *relE_fx, /* o : frame relative energy Q8 */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15 */ + Word16 *vad_hover_flag, /* o : VAD hangover flag */ + Word16 *attack_flag, /* o : flag signaling attack */ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ + Word16 *loc_harm, /* o : harmonicity flag */ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ + const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const Word16 force_front_vad, /* i : flag to force VAD decision */ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + 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 */ ); ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ @@ -2276,7 +2277,6 @@ void td_stereo_param_updt( const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ const int16_t tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ ); -#endif void gsc_enc( Encoder_State *st, /* i/o: State structure */ @@ -2290,7 +2290,6 @@ void gsc_enc( float *tmp_noise /* o : long-term noise energy */ ); -#ifndef IVAS_FLOAT_FIXED void tdm_low_rate_enc( Encoder_State *st, /* i/o: State structure */ const float Aq[], /* i : 12k8 Lp coefficient */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index e0c66f460..d549056b5 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3110,16 +3110,15 @@ void stereo_classifier_features_ivas_fx( const Word16 idchan, /* i : channel ID */ const Word16 element_mode, /* i : element mode */ const Word16 vad_flag, /* i : VAD flag */ - Word32 lsf_new_fx[], /* i : LSFs at the end of the frame */ + Word16 lsf_new_fx[], /* i : LSFs at the end of the frame Q1*1.28 */ Word32 epsP_fx[], /* i : LP analysis residual energies for each iteration*/ - Word16 pitch[], /*q0 i : open-loop pitch values for quantiz. */ - Word16 voicing_fx[], /* i : OL maximum normalized correlation */ + Word16 pitch[], /* i : open-loop pitch values for quantiz. Q0 */ + Word16 voicing_fx[], /* i : OL maximum normalized correlation Q15 */ Word32 cor_map_sum_fx, /* i : speech/music clasif. parameter */ Word32 non_staX_fx, /* i : unbound non-stationarity for sp/mu clas. */ - Word32 sp_div_fx, /* i : spectral diversity feature */ + Word16 sp_div_fx, /* i : spectral diversity feature */ const Word16 clas, /* i : signal class */ Word16 epsP_e, /*exponent for epsP_fx */ - Word16 voicing_e, /*exponent for voicing_fx */ Word16 cor_map_sum_e, /*exponent for cor_map_sum_fx */ Word16 non_staX_e, /*exponent for non_staX_fx */ Word16 sp_div_e /*exponent for sp_div_fx */ @@ -3974,15 +3973,14 @@ Word16 ivas_smc_gmm_fx( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ const Word16 Etot_fx, /* i : total frame energy */ - Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ - Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ - Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ - Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ - const Word16 non_sta_fx, /* i : unbound non-stationarity */ - const Word16 relE_fx, /* i : relative frame energy */ + const Word16 lsp_new_fx[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) Q8 */ + const Word32 epsP_fx[M + 1], /* i : LP prediciton error */ + const Word32 PS_fx[], /* i : energy spectrum */ + const Word16 non_sta_fx, /* i : unbound non-stationarity Q8 */ + const Word16 relE_fx, /* i : relative frame energy Q8 */ Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ - const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ - , + const Word16 flag_spitch, /* i : flag to indicate very short stable pitch */ Word16 Qfact_PS, Word16 Q_esp, Word16 Qfact_PS_past ); @@ -4407,8 +4405,8 @@ Word16 tdm_lp_comparison_fx( const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ const Word16 m, /* i : filter length */ - const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ - const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 *isp_PCh_fx, /* i : primary channel LSPs Q15 */ + const Word16 *isp_SCh_fx, /* i : secondary channel LSPs Q15 */ const Word16 L_frame, /* i : frame length */ const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ Word16 Q_speech ); diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index b893c1d84..a050f7675 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -868,9 +868,7 @@ typedef struct ivas_fb_mixer_state_structure /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ Word16 cross_fade_start_offset; Word16 cross_fade_end_offset; - const float *pFilterbank_cross_fade; Word16 ana_window_offset; - const float *pAna_window; Word16 prior_input_length; Word16 windowed_fr_offset; @@ -881,6 +879,8 @@ typedef struct ivas_fb_mixer_state_structure const Word16 *pAna_window_fx; #else float cldfb_cross_fade[CLDFB_NO_COL_MAX]; + const float *pFilterbank_cross_fade; + const float *pAna_window; #endif // IVAS_FLOAT_FIXED Word16 cldfb_cross_fade_start; Word16 cldfb_cross_fade_end; diff --git a/lib_com/prot.h b/lib_com/prot.h index 4f795250c..71ede8fe3 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3164,6 +3164,7 @@ void find_targets( float *h1 /* o : impulse response of weighted synthesis filter */ ); +#ifndef IVAS_FLOAT_FIXED void inov_encode( Encoder_State *st, /* i/o: encoder state structure */ const int32_t core_brate, /* i : core bitrate */ @@ -3188,6 +3189,7 @@ void inov_encode( int16_t *unbits, /* o : number of unused bits for EVS_PI */ const int16_t L_subfr /* i : subframe length */ ); +#endif void acelp_1t64( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -3206,6 +3208,7 @@ void acelp_2t32( float y[] /* o : filtered fixed codebook excitation */ ); +#ifndef IVAS_FLOAT_FIXED int16_t acelp_4t64( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ float dn[], /* i : corr. between target and h[]. */ @@ -3219,6 +3222,7 @@ int16_t acelp_4t64( const int16_t cmpl_flag, /* i : coomplexity reduction flag */ const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +#endif /*! r: return (2*N)+1 bits */ int16_t quant_2p_2N1( @@ -3406,7 +3410,7 @@ void lp_gain_updt( float *lp_gainc, /* i/o: LP-filtered code gain (FEC) */ const int16_t L_frame /* i : length of the frame */ ); - +#ifndef IVAS_FLOAT_FIXED void enc_pit_exc( Encoder_State *st, /* i/o: state structure */ const float *speech, /* i : Input speech */ @@ -3424,11 +3428,13 @@ void enc_pit_exc( const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); +#endif void GSC_enc_init( GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */ ); +#ifndef IVAS_FLOAT_FIXED void encod_audio( Encoder_State *st, /* i/o: state structure */ const float speech[], /* i : input speech */ @@ -3446,6 +3452,7 @@ void encod_audio( const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const float tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); +#endif /*! r: index of the last band where pitch contribution is significant */ int16_t Pit_exc_contribution_len( @@ -4222,6 +4229,7 @@ void pre_exc( const int16_t L_subfr /* i : subframe length */ ); +#ifndef IVAS_FLOAT_FIXED void encod_unvoiced( Encoder_State *st, /* i/o: state structure */ const float *speech, /* i : input speech */ @@ -4273,6 +4281,7 @@ int16_t encod_tran( int16_t position, /* i : maximum of residual signal index */ int16_t *unbits /* i/o: number of unused bits */ ); +#endif void encod_amr_wb( Encoder_State *st, /* i/o: state structure */ @@ -6739,6 +6748,7 @@ void acelp_pulsesign( float vec[], const float alp ); +#ifndef IVAS_FLOAT_FIXED void E_ACELP_4t( float dn[], float cn[], @@ -6770,6 +6780,7 @@ void E_ACELP_4tsearchx( float code[], PulseConfig *config, int16_t ind[] ); +#endif int16_t E_ACELP_indexing( float code[], diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index df01a6775..76d46c48c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5928,6 +5928,21 @@ void lsf_dec_fx( #endif ); +void lsf_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ +#endif +); + /*! r: index of the maximum value in the input vector */ Word16 maximum_l( const Word32 *vec, /* i : input vector */ @@ -6085,6 +6100,16 @@ void CNG_dec_fx( Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ Word32 *q_env ); +void CNG_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ + Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ + Word32 *q_env ); + void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index acf416c0a..cec1af1e9 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -2777,6 +2777,56 @@ const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k * 3] = { 4915, *----------------------------------------------------------------------------------*/ /* Innovative codebook config */ +#ifdef IVAS_FLOAT_FIXED +const PulseConfig PulseConfTable[] = +{ + /* Design rules: + * ---> "fixed" + "tried-pair-pos"*2 = pulses & 0xfe + * ---> tracks with pulses % 3 == 0, have always TRACKPOS_FIXED_FIRST */ + /* bits,iter,alp,pulses,fixed,tried-pair-pos,codetrack */ + { 7, 4, 16384/*2.0f Q13*/, 1, 0, {8}, TRACKPOS_FREE_ONE }, /* 7 bits, 1 pulses, 4 tracks, 1000 free track */ + { 10, 4, 16384/*2.0f Q13*/, 2, 0, {8}, TRACKPOS_FIXED_EVEN }, /* 10 bits, 2 pulses, 4 tracks 1010 (used only even tracks designed for NB) */ + { 12, 4, 16384/*2.0f Q13*/, 2, 0, {8}, TRACKPOS_FIXED_TWO }, /* 12 bits, 2 pulses, 2 tracks 11 used all tracks ala AMR-WB 6.6 */ + { 15, 4, 16384/*2.0f Q13*/, 3, 0, {8}, TRACKPOS_FIXED_FIRST }, /* 15 bits, 3 pulses, 4 tracks 1110 fixed track to first ? */ + { 17, 6, 16384/*2.0f Q13*/, 3, 0, {8}, TRACKPOS_FREE_THREE }, /* 17 bits, 3 pulses, 4 tracks (used all tracks) - 1110, 1101, 1011, 0111 */ + { 20, 4, 16384/*2.0f Q13*/, 4, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 20 bits, 4 pulses, 4 tracks 1111 */ + { 24, 4, 16384/*2.0f Q13*/, 5, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 24 bits, 5 pulses, 4 tracks 2111 fixed track to first */ + { 26, 4, 16384/*2.0f Q13*/, 5, 0, {4, 8}, TRACKPOS_FREE_ONE }, /* 26 bits, 5 pulses, 4 tracks 2111 one free track ? */ + { 28, 4, 12288/*1.5f Q13*/, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 28 bits, 6 pulses, 4 tracks 2211 */ + { 30, 4, 12288/*1.5f Q13*/, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_TWO }, /* 30 bits, 6 pulses, 4 tracks 2211 free consecutive track positions ? */ + { 32, 4, 12288/*1.5f Q13*/, 7, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 32 bits, 6 pulses, 4 tracks 2221 fixed ?*/ + { 34, 4, 12288/*1.5f Q13*/, 7, 0, {4, 8, 8}, TRACKPOS_FREE_THREE }, /* 34 bits, 6 pulses, 4 tracks 2221 free track positions ? */ + { 36, 4, 8192/*1.0f Q13*/, 8, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 36 bits, 8 pulses, 4 tracks 2222 */ + { 40, 4, 8192/*1.0f Q13*/, 9, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 40 bits, 9 pulses, 4 tracks 3222 fixed ?*/ + { 43, 4, 8192/*1.0f Q13*/, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 44 bits, 10 pulses, 4 tracks 3322 */ + { 46, 4, 8192/*1.0f Q13*/, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 46 bits, 10 pulses, 4 tracks 3322 free consecutive tracks ? */ + { 47, 4, 8192/*1.0f Q13*/, 11, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 47 bits, 10 pulses, 4 tracks 3332 fixed ? */ + { 49, 4, 8192/*1.0f Q13*/, 11, 2, {4, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 49 bits, 10 pulses, 4 tracks 3332 free three track positions ? */ + { 50, 4, 8192/*1.0f Q13*/, 12, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 50 bits, 12 pulses, 4 tracks 3333 */ + { 53, 4, 8192/*1.0f Q13*/, 13, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 53 bits, 13 pulses, 4 tracks 4333 fixed ? */ + { 55, 4, 8192/*1.0f Q13*/, 13, 4, {4, 6, 8, 8}, TRACKPOS_FREE_ONE }, /* 55 bits, 13 pulses, 4 tracks 4333 free one ? */ + { 56, 4, 8192/*1.0f Q13*/, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 56 bits, 14 pulses, 4 tracks 4433 fixed ?!?! */ + { 58, 4, 8192/*1.0f Q13*/, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 58 bits, 14 pulses, 4 tracks 4433 free consecutive ? */ + { 59, 4, 8192/*1.0f Q13*/, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 59 bits, 15 pulses, 4 tracks 4443 fixed ? */ + { 61, 4, 8192/*1.0f Q13*/, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 61 bits, 15 pulses, 4 tracks 4443 free ? */ + { 62, 3, 6554/*0.8f Q13*/, 16, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 62 bits, 16 pulses, 4 tracks 4444 */ + { 65, 3, 6554/*0.8f Q13*/, 17, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 65 bits, 17 pulses, 4 tracks 5444 fixed ?*/ + { 68, 3, 6144/*0.75f Q13*/, 18, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 68 bits, 18 pulses, 4 tracks 5544 */ + { 70, 3, 6144/*0.75f Q13*/, 19, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 70 bits, 19 pulses, 4 tracks 5554 fixed ? */ + { 73, 3, 6144/*0.75f Q13*/, 20, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 73 bits, 20 pulses, 4 tracks 5555 fixed ? */ + { 75, 3, 6144/*0.75f Q13*/, 21, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 75 bits, 21 pulses, 4 tracks 6555 fixed ? */ + { 78, 3, 6144/*0.75f Q13*/, 22, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 78 bits, 22 pulses, 4 tracks 6655 fixed ? */ + { 80, 3, 6144/*0.75f Q13*/, 23, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 80 bits, 23 pulses, 4 tracks 6665 fixed ? */ + { 83, 2, 2458/*0.30f Q13*/, 24, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 83 bits, 24 pulses, 4 tracks 6666 */ + { 85, 2, 2458/*0.30f Q13*/, 25, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 85 bits, 25 pulses, 4 tracks 7666 */ + { 87, 2, 2048/*0.25f Q13*/, 26, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 87 bits, 26 pulses, 4 tracks 7766 */ + { 89, 2, 2048/*0.25f Q13*/, 27, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 89 bits, 27 pulses, 4 tracks 7776 */ + { 92, 2, 2048/*0.25f Q13*/, 28, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 92 bits, 28 pulses, 4 tracks 7777 */ + { 94, 2, 2048/*0.25f Q13*/, 29, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 94 bits, 29 pulses, 4 tracks 8777 */ + { 96, 1, 1638/*0.20f Q13*/, 30, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 96 bits, 30 pulses, 4 tracks 8877 */ + { 98, 1, 1638/*0.20f Q13*/, 31, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 98 bits, 31 pulses, 4 tracks 8887 */ +}; +#else const PulseConfig PulseConfTable[] = { /* Design rules: @@ -2825,6 +2875,7 @@ const PulseConfig PulseConfTable[] = { 96, 1, 0.20f, 1638/*0.20f Q13*/, 30, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 96 bits, 30 pulses, 4 tracks 8877 */ { 98, 1, 0.20f, 1638/*0.20f Q13*/, 31, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 98 bits, 31 pulses, 4 tracks 8887 */ }; +#endif /* Number of pulses & positions to the number of unique states that can be achieved with those pulses */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 1bbd51a5f..8a6da6ead 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -170,9 +170,11 @@ typedef struct typedef struct { - Word16 bits; /* bits per subframe */ - Word16 nbiter; /* number of iterations */ - float alp_flt; /* initial energy of all fixed pulses */ + Word16 bits; /* bits per subframe */ + Word16 nbiter; /* number of iterations */ +#ifndef IVAS_FLOAT_FIXED + float alp_flt; /* initial energy of all fixed pulses */ +#endif Word16 alp; /* initial energy of all fixed pulses, exponent = ALP_E Q13*/ Word16 nb_pulse; /* number of pulses */ Word16 fixedpulses; /* number of pulses whose position is determined from correlation and not by iteration */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 3fcf4610b..7a7db41a7 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -205,7 +205,7 @@ ivas_error acelp_core_dec_ivas_fx( configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); /* decode CNG parameters */ - CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); @@ -645,7 +645,7 @@ ivas_error acelp_core_dec_ivas_fx( /* decode CNG parameters */ IF( st->cng_type == LP_CNG ) { - CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); FOR( Word32 nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); @@ -892,9 +892,9 @@ ivas_error acelp_core_dec_ivas_fx( IF( !tdm_lp_reuse_flag ) { #ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE - lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); + lsf_dec_ivas_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); #else - lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); + lsf_dec_ivas_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); #endif } ELSE @@ -1023,7 +1023,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); } /*---------------------------------------------------------------* diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index d17bf1966..258bde6d7 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -10,28 +10,723 @@ #include "prot_fx.h" #include "ivas_cnst.h" +#ifdef IVAS_FLOAT_FIXED /*Temporary location to be move in prot* when merge is done*/ void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); -/*-----------------------------------------------------------------* - * Local function prototypes - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * Local function prototypes + *-----------------------------------------------------------------*/ + +static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + +static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + +/*-----------------------------------------------------------------* + * Decode residual signal energy + *-----------------------------------------------------------------*/ + +void CNG_dec_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ + Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID Q0 */ + , + Word32 *q_env ) +{ + Word16 istep; + Word16 i, L_enr_index; + Word32 L_ener; + Word16 ener_fra, ener_int; + Word16 num_bits; + Word16 weights, ptr, j, k; + Word16 m1; + Word16 m = 0; + move16(); + Word16 tmp[HO_HIST_SIZE * M]; + Word16 burst_ho_cnt = 0; + move16(); + Word16 ll, s_ptr; + Word32 L_enr, L_tmp1; + Word16 tmp1, exp; + Word16 lsf_tmp[M]; + Word32 C[M]; + Word32 max_val[2]; + Word16 max_idx[2]; + Word16 ftmp_fx; + Word16 lsp_tmp[M]; + Word16 dev; + Word16 max_dev; + Word16 dist; + Word16 tmpv; + Word16 env_idx[2]; + Word32 enr1; + Word32 env[NUM_ENV_CNG]; + Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG]; + Word32 L_tmp; + Word16 fra; + Word16 temp_lo_fx, temp_hi_fx; + Word16 exp_pow; + Word16 tmp_loop; + Word16 enr_new, Aq_tmp[M + 1]; + + Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ + TD_CNG_DEC_HANDLE hTdCngDec; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + hTdCngDec = st_fx->hTdCngDec; + + m = 0; + move16(); + /*-----------------------------------------------------------------* + * Decode CNG spectral envelope (only in SID frame) + *-----------------------------------------------------------------*/ + test(); + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + /* de-quantize the LSF vector */ + IF( st_fx->Opt_AMR_WB != 0 ) + { + /* Flt function */ + isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); + /* check IF ISPs may trigger too much synthesis energy */ + + E_LPC_f_isp_a_conversion( lsp_new, Aq_tmp, M ); + enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + + IF( ( shr( enr_new, 14 ) > 0 ) ) + { + /* Use old LSP vector */ + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ + } + } + ELSE + { + lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + NULL +#endif + ); + /* check IF LSPs may trigger too much synthesis energy */ + + E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); + enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + + IF( shr( enr_new, 14 ) > 0 ) + { + /* Use old LSP vector */ + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ + } + } + } + ELSE + { + /* Use old LSP vector */ + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ + } + + /* Initialize the CNG spectral envelope in case of the very first CNG frame */ + IF( st_fx->first_CNG == 0 ) + { + Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); /* Q15 */ + } + + /*-----------------------------------------------------------------* + * Decode residual signal energy + *-----------------------------------------------------------------*/ + + *allow_cn_step = 0; + move16(); + test(); + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + istep = ISTEP_AMR_WB_SID_FX; /* Q15 */ + move16(); + if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + istep = ISTEP_SID_FX; /* Q15 */ + move16(); + } + + /* initialize the energy quantization parameters */ + num_bits = 6; + move16(); + if ( st_fx->Opt_AMR_WB == 0 ) + { + num_bits = 7; + move16(); + } + + /* decode the energy index */ + L_enr_index = get_next_indice_fx( st_fx, num_bits ); + + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) || EQ_16( st_fx->prev_bfi, 1 ) ) + { + tmp1 = add( hTdCngDec->old_enr_index, 20 ); + } + ELSE + { + tmp1 = add( hTdCngDec->old_enr_index, 40 ); + } + IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ + { + L_enr_index = tmp1; + move16(); + L_enr_index = s_min( L_enr_index, 127 ); /* Q0 */ + IF( st_fx->Opt_AMR_WB ) + { + L_enr_index = s_min( L_enr_index, 63 ); /* Q0 */ + } + } + + test(); + test(); + test(); + IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && + NE_16( st_fx->first_CNG, 0 ) && + GE_16( hTdCngDec->old_enr_index, 0 ) && + GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) + { + *allow_cn_step = 1; + move16(); + } + + hTdCngDec->old_enr_index = L_enr_index; + move16(); + if ( !L_enr_index ) + { + L_enr_index = -5; + move16(); + } + /* st_fx->Enew = L_enr_index / step - 2.0f;*/ + L_ener = L_mult( L_enr_index, istep ); /* Q16 (0+15) */ + /* subtract by 2 not done to leave Energy in Q2 */ + + /* extract integral and fractional parts */ + ener_fra = L_Extract_lc( L_ener, &ener_int ); + ener_int = add( ener_int, 4 ); /* Q2 to Q6 */ + + /* find the new energy value */ + hTdCngDec->Enew_fx = Pow2( ener_int, ener_fra ); + move32(); + + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */ + + *sid_bw = get_next_indice_fx( st_fx, 1 ); + move16(); + IF( *sid_bw == 0 ) + { + env_idx[0] = get_next_indice_fx( st_fx, 6 ); + move16(); + + /* get quantized res_env_details */ + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + q_env[i] = L_deposit_l( CNG_details_codebook_fx[env_idx[0]][i] ); + move32(); + } + } + } + /* Reset CNG history IF CNG frame length is changed */ + test(); + test(); + IF( EQ_16( st_fx->bwidth, WB ) && NE_16( st_fx->first_CNG, 0 ) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) + { + hTdCngDec->ho_hist_size = 0; + move16(); + } + } + + /*---------------------------------------------------------------------* + * CNG spectral envelope update + * Find A(z) coefficients + *---------------------------------------------------------------------*/ + test(); + test(); + test(); + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) + { + /* Reset hangover counter if not first SID period */ + if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) + { + hTdCngDec->num_ho = 0; + move16(); + } + /* Update LSPs IF last SID energy not outliers or insufficient number of hangover frames */ + test(); + IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) ) + { + FOR( i = 0; i < M; i++ ) + { + /* AR low-pass filter */ + st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); + move16(); /* Q15 (15+15+1-16) */ + } + } + } + ELSE + { + /* Update CNG_mode IF allowed */ + test(); + test(); + test(); + IF( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !st_fx->first_CNG || GE_16( hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) ) + { + IF( GT_32( st_fx->last_active_brate, ACELP_16k40 ) ) + { + st_fx->CNG_mode = -1; + move16(); + } + ELSE + { + st_fx->CNG_mode = get_cng_mode( st_fx->last_active_brate ); + move16(); + } + } + + /* If first sid after active burst update LSF history from circ buffer */ + burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX Q0*/ + hTdCngDec->act_cnt = 0; + move16(); + s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); + IF( s_ptr < 0 ) + { + s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); + } + + FOR( ll = burst_ho_cnt; ll > 0; ll-- ) + { + hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); /* Q0 */ + move16(); + if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_ptr = 0; + move16(); + } + + /* Conversion between 12.8k and 16k LSPs */ + test(); + test(); + test(); + IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) + { + /* Conversion from 16k LPSs to 12k8 */ + lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); + } + /* update the circular buffers */ + Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); /* Qx */ + Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); /* Q6 */ + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + move32(); + Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Qx */ + + hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); + move16(); + + if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_size = HO_HIST_SIZE; + move16(); + } + + s_ptr = add( s_ptr, 1 ); + if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) + { + s_ptr = 0; + move16(); + } + } + + IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ + { + /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ + L_tmp1 = L_shr( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); + L_tmp1 = L_sub( L_tmp1, st_fx->lp_ener_fx ); + + test(); + test(); + IF( ( L_tmp1 > 0 && ( st_fx->first_CNG || st_fx->element_mode == EVS_MONO ) ) ) + { + *allow_cn_step = s_or( *allow_cn_step, 1 ); + move16(); + } + } + IF( EQ_16( last_element_mode, IVAS_CPE_TD ) ) + { + *allow_cn_step = 1; + move16(); + } + test(); + IF( EQ_16( *allow_cn_step, 0 ) && GT_16( hTdCngDec->ho_hist_size, 0 ) ) + { + /* Use average of energies below last energy */ + ptr = hTdCngDec->ho_hist_ptr; + move16(); + Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); /* Qx */ + m1 = 0; + move16(); + IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) + { + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + m1 = 1; + move16(); + } + L_enr = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ + + weights = W_DTX_HO_FX[0]; /* Q15 */ + move16(); + + m = 1; + move16(); + FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) + { + ptr--; + if ( ptr < 0 ) + { + ptr = HO_HIST_SIZE - 1; + move16(); + } + + test(); + IF( LT_32( Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ) && + GT_32( hTdCngDec->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], BUF_L_NRG_FX ) ) ) + { + /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/ + L_tmp1 = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ + L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */ + + /*weights += W_DTX_HO[k];*/ + weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ + + Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); /* Qx */ + IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) ) + { + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); /* Qx */ + m1++; + } + m++; + } + } + + /*enr /= weights;*/ + exp = norm_s( weights ); + tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ + L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ + L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ + + st_fx->lp_ener_fx = L_enr; /* Q6 */ + move32(); + set32_fx( max_val, 0, 2 ); + set16_fx( max_idx, 0, 2 ); + + FOR( i = 0; i < m; i++ ) + { + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); + ftmp_fx = 964; + move16(); /*X2.56 */ + tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + } + ELSE + { + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); + ftmp_fx = 1205; + move16(); /*QX2.56*/ + tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + } + + tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ + FOR( j = 0; j < M - 1; j++ ) + { + tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ + } + + C[i] = Mpy_32_16_1( L_tmp, 1928 ); /*QX6.5536*/ + move32(); + + IF( GT_32( C[i], max_val[0] ) ) + { + max_val[1] = max_val[0]; + move32(); + max_idx[1] = max_idx[0]; + move16(); + max_val[0] = C[i]; + move32(); + max_idx[0] = i; + move16(); + } + ELSE IF( GT_32( C[i], max_val[1] ) ) + { + max_val[1] = C[i]; + move32(); + max_idx[1] = i; + move16(); + } + } + + IF( EQ_16( m, 1 ) ) + { + Copy( tmp, lsp_tmp, M ); /* Qx */ + } + ELSE IF( LT_16( m, 4 ) ) + { + FOR( i = 0; i < M; i++ ) + { + L_tmp1 = 0; + move32(); + FOR( j = 0; j < m; j++ ) + { + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + } + + L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) ); + tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ + L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ + lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ + move16(); + } + } + ELSE + { + FOR( i = 0; i < M; i++ ) + { + L_tmp1 = 0; + move32(); + FOR( j = 0; j < m; j++ ) + { + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + } -#ifdef IVAS_FLOAT_FIXED -static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/ + tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ + L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ + lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ + move16(); + } + } + + dist = 0; + move16(); /*Q15*/ + max_dev = 0; + move16(); /*Q15*/ + FOR( i = 0; i < M; i++ ) + { + dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/ +#ifdef BASOP_NOGLOB + dist = add_o( dist, dev, &Overflow ); /*Q15*/ +#else + dist = add( dist, dev ); /*Q15*/ #endif + if ( GT_16( dev, max_dev ) ) + { + max_dev = dev; + move16(); + } + } -#ifdef IVAS_FLOAT_FIXED -static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); + test(); + IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) /* 0.4 and 0.1 in Q15 */ + { + FOR( i = 0; i < M; i++ ) + { + st_fx->lspCNG_fx[i] = lsp_tmp[i]; + move16(); /*Q15*/ + } + } + ELSE + { + FOR( i = 0; i < M; i++ ) + { + /* AR low-pass filter */ + st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); /* Q15 */ + move16(); + } + } + IF( m1 > 0 ) + { + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + L_tmp = L_deposit_l( 0 ); + FOR( j = 0; j < m1; j++ ) + { + /* env[i] += tmp_env[j*NUM_ENV_CNG+i];*/ +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, tmp_env[j * NUM_ENV_CNG + i] ); +#else + L_tmp = L_add( L_tmp, tmp_env[j * NUM_ENV_CNG + i] ); +#endif + } + /* env[i] /= (float)m1; */ + /* env[i] = env[i] - 2*st_fx->lp_ener_fx; */ + IF( EQ_16( m1, 1 ) ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#endif + } + ELSE + { + tmp1 = div_s( 1, m1 ); + L_tmp = Mult_32_16( L_tmp, tmp1 ); /* Q6 */ +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #endif + } + env[i] = L_tmp; /* Q6 */ + move32(); + } -/*-----------------------------------------------------------------* - * Decode residual signal energy - *-----------------------------------------------------------------*/ + Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); /* Q6 */ + } + } + ELSE + { + Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ + } + } -#ifdef IVAS_FLOAT_FIXED -void CNG_dec_fx( + test(); + IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + /* Update hangover memory during CNG */ + test(); +#ifdef BASOP_NOGLOB + IF( ( *allow_cn_step == 0 ) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#else + IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#endif + { + /* update the pointer to circular buffer of old LSP vectors */ + hTdCngDec->ho_hist_ptr++; + move16(); + if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_ptr = 0; + move16(); + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); /* Q15 */ + + /* update the hangover energy buffer */ + hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; /* Q6 */ + move32(); + test(); + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && ( *sid_bw == 0 ) ) + { + /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ + exp = norm_l( hTdCngDec->Enew_fx ); + L_tmp = L_shl( hTdCngDec->Enew_fx, exp ); /*Q(exp+6)*/ + L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /*Q(exp+6+5-15=exp-4)*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /*Q6*/ +#else + L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /*Q6*/ +#endif + exp = norm_l( L_tmp ); + fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + enr1 = L_shr( L_tmp, 10 ); /* Q6 */ + + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* get quantized envelope */ + /* env[i] = pow(2.0f,(enr1 - q_env[i])) + 2*st->Enew;*/ + L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ + L_tmp = L_shl( L_tmp, 10 ); /* 16 */ + temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); + + exp_pow = sub( 14, temp_hi_fx ); + L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ + env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); /* Q6 */ + move32(); + L_tmp = L_add( hTdCngDec->Enew_fx, hTdCngDec->Enew_fx ); + env[i] = L_add( env[i], L_tmp ); /* Q6 */ + move32(); + } + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ + move32(); + Copy32( env, &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Q6 */ + } + ELSE IF( ( *sid_bw != 0 ) ) + { + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ + move32(); + hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); /* Q0 */ + move32(); + } + + hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); + move16(); + if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + { + hTdCngDec->ho_hist_size = HO_HIST_SIZE; + move16(); + } + } + /* Update the frame length memory */ + st_fx->last_CNG_L_frame = st_fx->L_frame; + move16(); + + if ( NE_32( st_fx->core_brate, SID_1k75 ) ) + { + hTdCngDec->num_ho = m; + move16(); + } + } + + IF( st_fx->element_mode == EVS_MONO ) + { + st_fx->last_CNG_L_frame = st_fx->L_frame; + move16(); + + IF( NE_32( st_fx->core_brate, SID_1k75 ) ) + { + hTdCngDec->num_ho = m; + move16(); + } + } + IF( st_fx->Opt_AMR_WB ) + { + E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); + } + ELSE + { + E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); + } + + tmp_loop = shr( st_fx->L_frame, 6 ); + FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ + { + Copy( Aq, &Aq[i * ( M + 1 )], add( M, 1 ) ); /* Q12 */ + } + + return; +} + +void CNG_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 last_element_mode, /* i : last element mode Q0 */ Word16 Aq[], /* o : LP coefficients Q12 */ @@ -113,10 +808,10 @@ void CNG_dec_fx( } ELSE { - lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 + lsf_dec_ivas_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE - , - NULL + , + NULL #endif ); /* check IF LSPs may trigger too much synthesis energy */ @@ -536,7 +1231,7 @@ void CNG_dec_fx( #ifdef BASOP_NOGLOB dist = add_o( dist, dev, &Overflow ); /*Q15*/ #else - dist = add( dist, dev ); /*Q15*/ + dist = add( dist, dev ); /*Q15*/ #endif if ( GT_16( dev, max_dev ) ) { @@ -729,14 +1424,13 @@ void CNG_dec_fx( return; } -#endif /*---------------------------------------------------------------------* * swb_CNG_dec() * * Comfort noise generation for SHB signal *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED + void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -775,9 +1469,7 @@ void swb_CNG_dec_fx( return; } -#endif -#ifdef IVAS_FLOAT_FIXED void swb_CNG_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -815,14 +1507,13 @@ void swb_CNG_dec_ivas_fx( return; } -#endif /*---------------------------------------------------------------------* * shb_CNG_decod() * * Main routine of SHB SID decoding and CNG *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED + static void shb_CNG_decod_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -1112,9 +1803,7 @@ static void shb_CNG_decod_fx( return; } -#endif -#ifdef IVAS_FLOAT_FIXED static void shb_CNG_decod_ivas_fx( Decoder_State *st, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -1394,7 +2083,6 @@ static void shb_CNG_decod_ivas_fx( ResetSHBbuffer_Dec_fx( st ); return; } -#endif /*-------------------------------------------------------------------* * td_cng_dec_init_fx() @@ -1402,7 +2090,6 @@ static void shb_CNG_decod_ivas_fx( * *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void td_cng_dec_init_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) @@ -1492,9 +2179,7 @@ void td_cng_dec_init_fx( return; } -#endif -#ifdef IVAS_FLOAT_FIXED void td_cng_dec_init_ivas_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 297221eb4..4eff4ad5e 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -271,6 +271,9 @@ UWord8 apa_reconfigure( free( ps->buf_out_fx ); ps->buf_out_fx = (Word16 *) malloc( sizeof( Word16 ) * ps->buf_out_capacity ); +#ifdef MSAN_FIX + memset( ps->buf_out_fx, 0, ( sizeof( Word16 ) * ps->buf_out_capacity ) ); +#endif ps->Q_buf_out = Q15; move16(); IF( !ps->buf_out_fx ) diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index a50c98d09..3f92a6972 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -102,6 +102,7 @@ static void dqlsf_CNG_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*===========================================================================*/ + void lsf_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 tc_subfr, /* i : TC subframe index Q0*/ @@ -333,6 +334,268 @@ void lsf_dec_fx( return; } + +/*===========================================================================*/ +/* FUNCTION : lsf_dec_ivas_fx() */ +/*---------------------------------------------------------------------------*/ +/* PURPOSE : LSF decoder */ +/*---------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Struct) st_fx : decoder static memory */ +/* _ (Word16) L_frame : length of the frame */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16) bwidth : input signal bandwidth */ +/*---------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) Aq : LP filter coefficient Q12 */ +/* _ (Word16*) lsf_new : LP filter coefficient Q(x2.56) */ +/* _ (Word16*) lsp_new : LP filter coefficient Q15 */ +/* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ +/*---------------------------------------------------------------------------*/ + +/* _ (Word16[]) st_fx->lsf_adaptive_mean_fx : FEC - adaptive mean LSF */ +/* vector for FEC Q(x2.56) */ +/* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ +/* (past quantized LSFs without mean) Q(x2.56) */ +/* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ +/*---------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*===========================================================================*/ + +void lsf_dec_ivas_fx( + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ +#endif +) +{ + Word16 i; + Word16 no_param_lpc; + Word16 param_lpc[NPRM_LPC_NEW]; + Word32 L_tmp; + Word16 nBits = 0; + move16(); + Word16 tmp_old[M + 1], tmp_new[M + 1]; + Word16 enr_old = 0, enr_new = 0; + move16(); + move16(); + Word16 lsf_diff, coder_type; + + /* initialize */ + coder_type = st_fx->coder_type; + if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + coder_type = INACTIVE; /* Q0 */ + move16(); + } + test(); + if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) + { + coder_type = GENERIC; /* Q0 */ + move16(); + } + no_param_lpc = 0; + nBits = 0; + move16(); + move16(); + + /* Find the number of bits for LSF quantization */ + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + nBits = LSF_BITS_CNG; /* Q0 */ + move16(); + } + ELSE + { + test(); + IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) + { + nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ + move16(); + } + ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) + { + IF( EQ_16( coder_type, UNVOICED ) ) + { + nBits = 30; /* Q0 */ + move16(); + if ( st_fx->bwidth == NB ) + { + nBits = 32; /* Q0 */ + move16(); + } + } + } + ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) + { + nBits = 26; /* Q0 */ + move16(); + } + } + + /* LSF de-quantization */ + lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc +#ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + tdm_lsfQ_PCh +#endif + ); + + /* convert quantized LSFs to LSPs */ + + lsf2lsp_fx( lsf_new, lsp_new, M, st_fx->sr_core ); + /* set seed_acelp used in UC mode */ + test(); + IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) ) + { + st_fx->seed_acelp = 0; + move16(); + FOR( i = no_param_lpc - 1; i >= 0; i-- ) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ + move16(); + // PMTE() /*IVAS_CODE to be completed */ + } + } + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) + { + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-------------------------------------------------------------------------------------* + * FEC - update adaptive LSF mean vector + *-------------------------------------------------------------------------------------*/ + + FOR( i = 0; i < M; i++ ) + { + L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ + st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ + move16(); + } + + test(); + test(); + IF( ( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) + { + lsf_diff = 1205; + move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + lsf_diff = 964; + move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ + } + st_fx->lsf_old_fx[0] = lsf_diff; + move16(); + + FOR( i = 1; i < M; i++ ) + { + st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */ + move16(); + } + lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); + } + /*-------------------------------------------------------------------------------------* + * Mid-frame LSF decoding + * LSP interpolation and conversion of LSPs to A(z) + *-------------------------------------------------------------------------------------*/ + IF( st_fx->rate_switching_reset ) + { + /*extrapolation in case of unstable LSF convert*/ + Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ + Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ + } + { + /* Mid-frame LSF decoding */ + lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid ); + } + test(); + test(); + IF( !( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) + { + IF( st_fx->prev_bfi ) + { + /* check, if LSP interpolation can be relaxed */ + E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ + + E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ + + IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) + { + /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */ + st_fx->relax_prev_lsf_interp = -1; + move16(); + test(); + test(); + test(); + test(); + if ( st_fx->clas_dec == UNVOICED_CLAS || EQ_16( st_fx->clas_dec, SIN_ONSET ) || st_fx->clas_dec == INACTIVE_CLAS || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) + { + st_fx->relax_prev_lsf_interp = 1; + move16(); + } + } + } + } + test(); + IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) + { + /* update old LSPs/LSFs in case of HQ->ACELP core switching */ + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + } + test(); + IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) + { + // PMT("To be verified") + IF( EQ_16( st_fx->active_cnt, 1 ) ) + { + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + Copy( lsp_new, lsp_mid, M ); /* Q15 */ + } + + /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ + int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); + } + ELSE + { + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); + } + /*------------------------------------------------------------------* + * Check LSF stability (distance between old LSFs and current LSFs) + *------------------------------------------------------------------*/ + + IF( st_fx->element_mode == EVS_MONO ) + { + st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/ + move16(); + } + ELSE + { + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */ + move16(); + } + + return; +} + + /*========================================================================*/ /* FUNCTION : lsf_end_dec_fx() */ /*------------------------------------------------------------------------*/ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 45e429430..19cf8c52a 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -289,7 +289,6 @@ ivas_error acelp_core_enc( /* reset the GSC pre echo energy threshold in case of switching */ if ( st->hGSCEnc != NULL ) { - st->hGSCEnc->Last_frame_ener = (float) MAX_32; st->hGSCEnc->Last_frame_ener_fx = MAX_32; move32(); } @@ -417,11 +416,11 @@ ivas_error acelp_core_enc( IF( st->rate_switching_reset ) { /*extrapolation in case of unstable LSP*/ - int_lsp4_fx( st->L_frame, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); } ELSE { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); } /* Reset LPC mem */ @@ -489,7 +488,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, Q_new - 1, 30 ); for ( i = 0; i < M; i++ ) { lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f ); @@ -501,7 +499,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) ); fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, Q_new - 1, 30 ); for ( i = 0; i < M; i++ ) { lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f ); @@ -516,17 +513,9 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr32( q_env, q_env_fx, Q6, NUM_ENV_CNG ); - // Word16 Q_exc_l = Q_factor_arr( st->hTdCngEnc->exc_mem, 24 ); - // Word16 Q_exc1_l = Q_factor_arr( st->hTdCngEnc->exc_mem1, 30 ); - // Q_exc_l = min( Q_exc_l, Q_exc1_l ); - floatToFixed_arr( st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem_fx, Q_new - 1, 24 ); - floatToFixed_arr( st->hTdCngEnc->exc_mem1, st->hTdCngEnc->exc_mem1_fx, Q_new - 1, 30 ); #endif /* comfort noise generation */ - // CNG_exc( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc, exc2, &st->hTdCngEnc->lp_ener, st->last_core_brate, &st->hDtxEnc->first_CNG, - //&st->hTdCngEnc->cng_ener_seed, bwe_exc, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, st->hTdCngEnc->num_ho, q_env, st->hTdCngEnc->lp_env, st->hTdCngEnc->old_env, - // st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem1, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, EVS_MONO ); 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, &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho, q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO ); @@ -537,8 +526,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( exc2_fx, exc2, Q_new - 1, st->L_frame ); fixedToFloat_arr( exc3_fx, exc3, Q_new - 1, st->L_frame ); fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_new - 1, st->L_frame ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem, Q_new - 1, 24 ); - fixedToFloat_arr( st->hTdCngEnc->exc_mem1_fx, st->hTdCngEnc->exc_mem1, Q_new - 1, 30 ); #endif } else @@ -731,22 +718,14 @@ ivas_error acelp_core_enc( IF( tdm_lsfQ_PCh ) tdm_lsfQ_PCh_fx[idx] = (Word16) ( tdm_lsfQ_PCh[idx] * 2.56f ); } - // Q_old_bwe_exc = Q_factor_arr( old_bwe_exc, 1380 ); floatToFixed_arr( old_bwe_exc, old_bwe_exc_fx, Q_new, 1380 ); - /*Q_exc = Q_factor_arr( old_exc_flt, st->L_frame ); - hLPDmem->e_old_exc = Q_factor_arr( &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 ) - 1; - Q_exc = min(s_min( Q_exc, hLPDmem->e_old_exc ), Q_new); - hLPDmem->e_old_exc = Q15 - Q_exc;*/ floatToFixed_arr( &hLPDmem->old_exc_flt[-M - 1], &hLPDmem->old_exc[-M - 1], Q_new, L_EXC_MEM + M + 1 ); floatToFixed_arr( old_exc_flt, old_exc_fx, Q_new, st->L_frame ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); - // Word16 pitch_buf_fx[NB_SUBFR16k]; - // Word16 voice_factors_fx[NB_SUBFR16k]; floatToFixed_arr( voice_factors, voice_factors_fx, Q15, NB_SUBFR16k ); - st->hGSCEnc->Last_frame_ener_fx = floatToFixed_32( st->hGSCEnc->Last_frame_ener, Q4 ); 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 @@ -1016,7 +995,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) ); } fixedToFloat_arr( old_exc_fx, old_exc_flt, Q_new, st->L_frame ); - // me2f_buf_16(&hLPDmem->old_exc[-M - 1], hLPDmem->e_old_exc, &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1); fixedToFloat_arr( &hLPDmem->old_exc[-M - 1], &hLPDmem->old_exc_flt[-M - 1], Q_new, L_EXC_MEM + M + 1 ); fixedToFloat_arr( old_bwe_exc_fx, old_bwe_exc, Q_new, 1380 ); fixedToFloat_arr( res_fx, res, Q_new, st->L_frame ); @@ -1028,7 +1006,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( exc2_fx, exc2, Q_new, L_FRAME16k ); if ( st->hBWE_TD ) fixedToFloat_arr( bwe_exc_fx, bwe_exc, Q_new, L_FRAME32k ); - st->hGSCEnc->Last_frame_ener = fixedToFloat_32( st->hGSCEnc->Last_frame_ener_fx, Q4 ); me2f_buf_16( st->hGSCEnc->last_exc_dct_in_fx, Q15 - st->hGSCEnc->Q_last_exc_dct_in, st->hGSCEnc->last_exc_dct_in, L_FRAME16k ); fixedToFloat_arr( syn_fx, syn, Q_new - 1, L_FRAME16k ); fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, NB_SUBFR16k ); @@ -1113,7 +1090,7 @@ ivas_error acelp_core_enc( Word32 epsP_fx[M + 1]; Word16 e_epsP; f2me_buf( epsP, epsP_fx, &e_epsP, M + 1 ); - st->exc_pe_fx = float_to_fix16( st->exc_pe, st->Q_stat_noise ); + // st->exc_pe_fx = float_to_fix16_thrld( st->exc_pe, st->Q_stat_noise ); floatToFixed_arr( lsp_new, lsp_new_fx, 15, 16 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, 15, 16 ); #endif diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index cd8856713..ee21c7ae8 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -111,12 +111,12 @@ void analy_lp_ivas_fx( IF( EQ_16( sec_chan_low_rate, 1 ) ) { /* LSP interpolation */ - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); + int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); } ELSE { /* LSP interpolation */ - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); + int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); } Copy( lsp_new, lsp_old, M ); *ener = L_Comp( epsP_h[M], epsP_l[M] ); diff --git a/lib_enc/cod4t64.c b/lib_enc/cod4t64.c index 88bbc93ec..5c609ad9d 100644 --- a/lib_enc/cod4t64.c +++ b/lib_enc/cod4t64.c @@ -47,11 +47,13 @@ * Local function prototypes *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t quant_1p_N1( const int16_t pos, const int16_t N ); static int16_t quant_3p_3N1( const int16_t pos1, const int16_t pos2, const int16_t pos3, const int16_t N ); static int32_t quant_4p_4N( const int16_t pos[], const int16_t N ); static int32_t quant_5p_5N( const int16_t pos[], const int16_t N ); static int32_t quant_6p_6N_2( const int16_t pos[], const int16_t N ); +#endif static int16_t pre_process( const float v[], int16_t pos_vector[], int16_t pos_vector_num[], int16_t *pulse_pos_num ); static int32_t fcb_encode_position( const int16_t pos_vector[], int16_t n, const int16_t pos_num, const int16_t flag ); static int32_t fcb_encode_class( const int16_t buffer[], const int16_t pulse_num, const int16_t pos_num ); @@ -78,6 +80,7 @@ static int32_t fcb_encode_PI( const float v[], const int16_t pulse_num ); * Each pulse can have sixteen (16) possible positions. *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t acelp_4t64( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ float dn[], /* i : corr. between target and h[]. */ @@ -436,6 +439,7 @@ static int16_t quant_1p_N1( /*---------------------------------------------------------------------* * Quantization of 2 pulses with 2*N+1 bits: * *---------------------------------------------------------------------*/ +#endif /*! r: return (2*N)+1 bits */ int16_t quant_2p_2N1( @@ -494,6 +498,7 @@ int16_t quant_2p_2N1( return index; } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Quantization of 3 pulses with 3*N+1 bits: * *---------------------------------------------------------------------*/ @@ -767,6 +772,7 @@ static int32_t quant_6p_6N_2( return ( index ); } +#endif /*---------------------------------------------------------------------* *order the pulse position * diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index ac6b98299..2c2161079 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -761,118 +761,97 @@ void dtx_hangover_control( #ifdef IVAS_FLOAT_FIXED void td_cng_enc_init( TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ - const int16_t Opt_DTX_ON, /* i : flag indicating DTX operation */ - const int16_t max_bwidth /* i : maximum encoded bandwidth */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ ) { hTdCngEnc->cng_seed = RANDOM_INITSEED; hTdCngEnc->cng_ener_seed = RANDOM_INITSEED; hTdCngEnc->cng_ener_seed1 = RANDOM_INITSEED; -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->lp_ener = 0.0f; -#else hTdCngEnc->lp_ener_fx = 0; -#endif hTdCngEnc->old_enr_index = -1; -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->Enew = 0.0f; - - hTdCngEnc->lp_sp_enr = 0.0f; -#else hTdCngEnc->Enew_fx = 0; - hTdCngEnc->lp_sp_enr_fx = 0; -#endif - hTdCngEnc->last_allow_cn_step = 0; - -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->CNG_att = 0.0f; -#else hTdCngEnc->CNG_att_fx = 0; -#endif - - if ( Opt_DTX_ON ) + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + IF( Opt_DTX_ON ) { hTdCngEnc->cng_hist_ptr = -1; -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->cng_lsp_hist, 0, DTX_HIST_SIZE * M ); - set_f( hTdCngEnc->cng_ener_hist, 0, DTX_HIST_SIZE ); -#else set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M ); set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); -#endif hTdCngEnc->ho_hist_ptr = -1; hTdCngEnc->ho_sid_bw = 0; -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->ho_lsp_hist, 0, HO_HIST_SIZE * M ); - set_f( hTdCngEnc->ho_ener_hist, 0, HO_HIST_SIZE ); - set_f( hTdCngEnc->ho_env_hist, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#else set16_fx( hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); set32_fx( hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE ); set32_fx( hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#endif hTdCngEnc->ho_hist_size = 0; hTdCngEnc->act_cnt = 0; + move16(); + move16(); + move16(); + move16(); + move16(); } - set_s( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE ); + set16_fx( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE ); hTdCngEnc->act_cnt2 = 0; hTdCngEnc->num_ho = 0; + move16(); + move16(); hTdCngEnc->ho_circ_ptr = -1; -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->ho_lsp_circ, 0, HO_HIST_SIZE * M ); - set_f( hTdCngEnc->ho_ener_circ, 0, HO_HIST_SIZE ); - set_f( hTdCngEnc->ho_env_circ, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#else + move16(); set16_fx( hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); set32_fx( hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE ); set32_fx( hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); -#endif hTdCngEnc->ho_circ_size = 0; hTdCngEnc->burst_ho_cnt = 0; hTdCngEnc->cng_buf_cnt = 0; + move16(); + move16(); + move16(); - -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->lp_env, 0.0f, 20 ); - set_f( hTdCngEnc->cng_res_env, 0.0f, 20 * 8 ); -#else set32_fx( hTdCngEnc->lp_env_fx, 0, 20 ); set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 ); -#endif - set_f( hTdCngEnc->exc_mem, 0.0f, 24 ); - set_f( hTdCngEnc->exc_mem1, 0.0f, 30 ); - set_f( hTdCngEnc->exc_mem2, 0.0f, 30 ); -#ifndef IVAS_FLOAT_FIXED - set_f( hTdCngEnc->old_env, 0.0f, NUM_ENV_CNG ); -#else + set16_fx( hTdCngEnc->exc_mem_fx, 0, 24 ); + set16_fx( hTdCngEnc->exc_mem1_fx, 0, 30 ); + set16_fx( hTdCngEnc->exc_mem2_fx, 0, 30 ); set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG ); -#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions set_f( hTdCngEnc->cng_exc2_buf_flt, 0.0f, HO_HIST_SIZE * L_FFT ); #endif /* SWB CNG/DTX */ -#ifndef IVAS_FLOAT_FIXED - hTdCngEnc->last_wb_cng_ener = -6.02f; - hTdCngEnc->last_shb_cng_ener = -6.02f; - hTdCngEnc->mov_wb_cng_ener = -6.02f; - hTdCngEnc->mov_shb_cng_ener = -6.02f; -#else hTdCngEnc->last_wb_cng_ener_fx = -1541; hTdCngEnc->last_shb_cng_ener_fx = -1541; hTdCngEnc->mov_wb_cng_ener_fx = -1541; hTdCngEnc->mov_shb_cng_ener_fx = -1541; -#endif + move16(); + move16(); + move16(); + move16(); hTdCngEnc->shb_cng_ini_cnt = 1; hTdCngEnc->shb_NO_DATA_cnt = 0; - hTdCngEnc->last_SID_bwidth = min( max_bwidth, SWB ); + move16(); + move16(); + hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB ); hTdCngEnc->last_vad = 0; hTdCngEnc->last_idx_ener = 0; + move16(); + move16(); + move16(); return; } diff --git a/lib_enc/enc_acelp.c b/lib_enc/enc_acelp.c index 30ce1c54a..e2eff084b 100644 --- a/lib_enc/enc_acelp.c +++ b/lib_enc/enc_acelp.c @@ -74,6 +74,7 @@ static void E_ACELP_codearithp( const float v[], uint32_t *n, uint32_t *ps, int1 * Returns: * void */ +#ifndef IVAS_FLOAT_FIXED static void acelp_h_vec_corr1( float h[], float vec[], @@ -139,6 +140,7 @@ static void acelp_h_vec_corr2( } return; } +#endif /* @@ -164,6 +166,7 @@ static void acelp_h_vec_corr2( * Returns: * void */ +#ifndef IVAS_FLOAT_FIXED static void acelp_2pulse_search( int16_t nb_pos_ix, int16_t track_x, @@ -236,6 +239,7 @@ static void acelp_2pulse_search( return; } +#endif /* @@ -257,6 +261,7 @@ static void acelp_2pulse_search( * Returns: * void */ +#ifndef IVAS_FLOAT_FIXED static void E_ACELP_1pulse_search( int16_t track_x, int16_t track_y, @@ -321,6 +326,7 @@ static void E_ACELP_1pulse_search( return; } +#endif /* @@ -417,6 +423,7 @@ void acelp_findcandidates( } +#ifndef IVAS_FLOAT_FIXED static void acelp_hbuf( float *h_buf, float **h, @@ -1006,6 +1013,7 @@ void E_ACELP_4tsearch( return; } +#endif /* @@ -1043,6 +1051,7 @@ void E_ACELP_4tsearch( * void */ +#ifndef IVAS_FLOAT_FIXED void E_ACELP_4t( float dn[], float cn[], @@ -1088,6 +1097,7 @@ void E_ACELP_4t( return; } +#endif int16_t E_ACELP_indexing( diff --git a/lib_enc/enc_acelpx.c b/lib_enc/enc_acelpx.c index 8a01982a1..c7fb86512 100644 --- a/lib_enc/enc_acelpx.c +++ b/lib_enc/enc_acelpx.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /* Iterations: nb_pos_ix*16 */ static void E_ACELP_2pulse_searchx( const int16_t nb_pos_ix, @@ -495,3 +496,4 @@ void E_ACELP_4tsearchx( return; } +#endif diff --git a/lib_enc/gs_enc.c b/lib_enc/gs_enc.c index f60107866..1a068ff68 100644 --- a/lib_enc/gs_enc.c +++ b/lib_enc/gs_enc.c @@ -46,20 +46,18 @@ #include "prot_fx.h" #endif -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static float edyn( const float *vec, const int16_t lvec ); - /*-------------------------------------------------------------------* * encod_audio() * * Encode audio (AC) frames *-------------------------------------------------------------------*/ - void encod_audio( Encoder_State *st, /* i/o: State structure */ const float speech[], /* i : input speech */ @@ -685,8 +683,8 @@ void GSC_enc_init( set16_fx( hGSCEnc->mem_syn_tmp_fx, 0, M ); #endif - hGSCEnc->Last_frame_ener = (float) MAX_32; #ifndef IVAS_FLOAT_FIXED + hGSCEnc->Last_frame_ener = (float) MAX_32; hGSCEnc->mid_dyn = 40.0f; #else hGSCEnc->mid_dyn_fx = 5120; diff --git a/lib_enc/inov_enc.c b/lib_enc/inov_enc.c index 58c880029..80af44816 100644 --- a/lib_enc/inov_enc.c +++ b/lib_enc/inov_enc.c @@ -48,6 +48,7 @@ * Encode the algebraic innovation *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void inov_encode( Encoder_State *st, /* i/o: encoder state structure */ const int32_t core_brate, /* i : core bitrate */ @@ -378,3 +379,4 @@ void inov_encode( return; } +#endif diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index c83202108..532b59ed4 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -862,51 +862,52 @@ ivas_error pre_proc_front_ivas( } #else ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - const Word16 input_frame, /* i : frame length */ - const Word16 n, /* i : channel number */ - Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ - float old_inp_12k8[], /* o : buffer of old input signal */ - float old_inp_16k[], /* o : buffer of old input signal @16kHz */ - float *ener, /* o : residual energy from Levinson-Durbin */ - float *relE, /* o : frame relative energy */ - float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - float epsP[M + 1], /* o : LP prediction errors */ - float lsp_new[M], /* o : LSPs at the end of the frame */ - float lsp_mid[M], /* o : LSPs in the middle of the frame */ - Word16 *vad_hover_flag, /* o : VAD hangover flag */ - Word16 *attack_flag, /* o : flag signaling attack */ - 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[], /* o : weighted input signal buffer */ - float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ - float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ - Word16 *loc_harm, /* o : harmonicity flag */ - float *cor_map_sum, /* o : speech/music clasif. parameter */ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ - float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - float fft_buff[2 * L_FFT], /* o : FFT buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ - const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ - const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ - const float currFlatness, /* i : flatness parameter */ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ - float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ - const float Etot_LR[], /* i : total energy Left & Right channel Q8*/ - float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ - float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ - const Word16 force_front_vad, /* i : flag to force VAD decision */ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - 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 */ + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + const Word16 input_frame, /* i : frame length */ + const Word16 n, /* i : channel number */ + Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + Word16 *relE_fx, /* o : frame relative energy Q8 */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12 */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12 */ + float epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15 */ + Word16 *vad_hover_flag, /* o : VAD hangover flag */ + Word16 *attack_flag, /* o : flag signaling attack */ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ + Word16 *loc_harm, /* o : harmonicity flag */ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ + const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const Word16 force_front_vad, /* i : flag to force VAD decision */ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + 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_CONVERSIONS @@ -944,16 +945,6 @@ ivas_error pre_proc_front_ivas_fx( 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 ); - Word16 relE_fx; - Word16 old_wsp_fx[L_WSP]; - Word16 pitch_fr_fx[NB_SUBFR]; - Word16 voicing_fr_fx[NB_SUBFR]; - Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; - Word16 epsP_h[M + 1]; /* o : LP prediction errors */ - Word16 epsP_l[M + 1]; /* o : LP prediction errors */ - Word16 cor_map_sum16_fx; /* o : speech/music clasif. parameter */ - Word32 fr_bands_LR_fx[2][2 * NB_BANDS]; -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ float *wsp; /* weighted input signal buffer */ float Etot; /* total energy */ @@ -963,72 +954,41 @@ ivas_error pre_proc_front_ivas_fx( float tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ float tmpN_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ float tmpE_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary averaged energy of 2 sf. */ - float cor_map_sum_LR[CPE_CHANNELS]; /* speech/music clasif. parameter */ - // float non_staX_LR; /* non-stationarity for sp/mus classifier */ - // float ncharX_LR; /* noise character for sp/mus classifier */ - // float sp_div_LR; /* spectral diversity feature */ - float S_map_LR[L_FFT / 2]; /* short-term correlation map */ - float corr_shiftL; /* correlation shift */ - float corr_shiftR; /* correlation shift */ - // Word16 loc_harmLR[CPE_CHANNELS]; /* harmonicity flag */ + float PS[128]; /* speech/music clasif. parameters */ + float hp_E[2]; /* Energy in HF */ + float band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ + float *res_cod_SNR_M, tmpF[STEREO_DFT_BAND_MAX]; +#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED + + Word16 old_wsp_fx[L_WSP]; + Word16 epsP_h[M + 1]; /* o : LP prediction errors */ + Word16 epsP_l[M + 1]; /* o : LP prediction errors */ + Word32 fr_bands_LR_fx[2][2 * NB_BANDS]; Word16 lr_vad_enabled; /* LR VAD indicator */ - float ee[2]; /* Spectral tilt */ - float corr_shift; /* correlation shift */ - float sp_div, PS[128]; /* speech/music clasif. parameters */ Word16 L_look; /* length of look-ahead */ -#if 0 - float mem_decim_dummy[2 * L_FILT_MAX]; /* dummy decimation filter memory */ - float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ -#endif - float hp_E[2]; /* Energy in HF */ Word16 flag_spitch; Word16 high_lpn_flag; - float lsf_new[M]; - Word32 lsf_new_fx[M]; - float band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ -#if 0 - Word32 band_energies_fx[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ -#endif + Word16 lsf_new_fx[M]; // Q2.56 Word16 localVAD_HE_SAD; - float non_staX; - Word16 currFlatness_fx; - Word32 non_staX_fx; - float stab_fac; + Word16 non_staX_fx; Word16 alw_pitch_lag_12k8[2]; Word16 alw_voicing_fx[2]; Word16 last_core_orig; - // float dummy; - float S_map[L_FFT / 2]; - // Word16 S_map_fx[L_FFT / 2]; Word16 i, lMemRecalc, lMemRecalc_12k8; Word16 smc_dec; - // float dE1X; - // float ncharX; - // Encoder_State *st; - // float *signal_in; Word16 element_mode; Word32 input_Fs, last_element_brate; Word16 *tdm_SM_last_clas, tmpS; - float *res_cod_SNR_M, tmpF[STEREO_DFT_BAND_MAX]; STEREO_CLASSIF_HANDLE hStereoClassif; Word16 old_pitch1; /* previous frame OL pitch[1] @12.8 kHz */ Word16 LR_localVAD; ivas_error error; Word32 epsP_fx[17]; /*to be removed later*/ - Word32 cor_map_sum_fx; push_wmops( "pre_proc_front" ); Word16 *signal_in_fx; -#if 0 - Word16 *lgBin_E_fx; - Word32 PS_fx[128]; - Word32 lf_E_fx[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ -#endif Word32 *signal32_in_fx; -#if 0 - Word16 *inp_12k8_fx; -#endif Word16 *inp_12k8_fx, *new_inp_12k8_fx; /* pointers to current frame and new data */ CLDFB_SCALE_FACTOR cldfbScale; Word32 *enerBuffer_fx; @@ -1036,9 +996,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 *temp1F_icatdmResampBuf_fx; Word16 *old_inp_16k_fx; Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ -#if 1 - Word16 Etot_16fx; /* total energy, Q8 */ -#endif Word32 tmpF_fx[STEREO_DFT_BAND_MAX]; #ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING Word32 *res_cod_SNR_M_fx; @@ -1047,37 +1004,26 @@ ivas_error pre_proc_front_ivas_fx( Word16 new_inp_out_size; Word16 Q_new_inp; Word16 mem_decim_size; - // Word16 *wsp_fx; - // Word16 pitch_fr_fx[NB_SUBFR]; - // Word16 voicing_fr_fx[NB_SUBFR]; #ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING Word16 Q_new; Word16 corr_shift_fx; #endif -#if 0 - Word16 Q_exp; - Word32 Le_min_scaled; - Word16 relE_fx; -#endif Word16 dummy_fx; Word16 ncharX_fx; Word16 ncharX_LR_fx; /* noise character for sp/mus classifier */ Word16 loc_harmLR_fx[CPE_CHANNELS]; /* harmonicity flag */ - Word16 non_staX16_fx; - Word16 non_staX_LR_fx; /* non-stationarity for sp/mus classifier */ - Word32 sp_div_fx; - Word16 sp_div16_fx; + Word16 non_staX_LR_fx; /* non-stationarity for sp/mus classifier */ + Word16 sp_div_fx; Word16 q_sp_div; Word16 sp_div_LR_fx; Word16 q_sp_div_LR; Word16 *wsp_fx; Word32 dE1X_fx; - Word16 Etot_LR_fx[2]; Word16 S_map_fx[L_FFT / 2]; Word16 cor_map_sum_LR_fx[CPE_CHANNELS]; /* speech/music clasif. parameter */ Word16 S_map_LR_fx[L_FFT / 2]; /* short-term correlation map */ - Word32 Etot_fx; /* total energy */ + Word16 Etot_fx; /* total energy Q8 */ Word32 tmpN_fx[NB_BANDS]; /* Temporary noise update */ Word32 tmpE_fx[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ Word32 tmpN_LR_fx[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ @@ -1090,6 +1036,8 @@ ivas_error pre_proc_front_ivas_fx( Word32 lf_E_fx[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ Word32 lf_E_LR_fx[2][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ Word32 hp_E_fx[2]; /* Energy in HF */ + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; enerBuffer_exp = 0; move16(); @@ -1098,18 +1046,12 @@ ivas_error pre_proc_front_ivas_fx( mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); set16_fx( fft_buff_fx, 0, 512 ); - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; #ifdef MSAN_FIX - for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) { set32_fx( realBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); } -#endif - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; -#ifdef MSAN_FIX - for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) { set32_fx( imagBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); } @@ -1133,7 +1075,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); tdm_SM_last_clas = &tmpS; -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS set_f( tmpF, 0, STEREO_DFT_BAND_MAX ); res_cod_SNR_M = tmpF; #endif // IVAS_FLOAT @@ -1239,15 +1181,8 @@ ivas_error pre_proc_front_ivas_fx( localVAD_HE_SAD = 0; move16(); -#if 1 - corr_shiftL = 0; - corr_shiftR = 0; -#endif // DEBUG - -#if 1 snr_sum_he_fx = 0; move16(); -#endif corr_shiftL_fx = 0; corr_shiftR_fx = 0; @@ -1271,6 +1206,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } *attack_flag = 0; + move16(); IF( st->Opt_SC_VBR ) { @@ -1287,7 +1223,7 @@ ivas_error pre_proc_front_ivas_fx( L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ move16(); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ // int x = L_INP_MEM - L_look; inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ @@ -1295,7 +1231,7 @@ ivas_error pre_proc_front_ivas_fx( 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; /* pointer to the current frame of input signal in 12.8kHz core */ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_16( element_mode, IVAS_CPE_DFT ) ) { new_inp_12k8 -= L_FILT; @@ -1374,6 +1310,9 @@ ivas_error pre_proc_front_ivas_fx( move16(); } + *q_re_im_buf = sub( 16, cldfbScale.lb_scale ); + move16(); + /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) @@ -1460,7 +1399,6 @@ ivas_error pre_proc_front_ivas_fx( #endif // DEBUG #ifndef MSAN_FIX /*To be enabled when updations related to new_inp_12k8_fx is enabled */ -#if 1 IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); @@ -1476,8 +1414,7 @@ ivas_error pre_proc_front_ivas_fx( Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); } -#endif -#endif // !MSAN_FIX +#endif // !MSAN_FIX /*------------------------------------------------------------------* * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ @@ -1577,15 +1514,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arr( st->inp_12k8_mem_stereo_sw_fx, st->inp_12k8_mem_stereo_sw, 15 - inp_12k8_mem_stereo_sw_e, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, 15 - old_inp_12k8_e, L_INP_MEM + L_FRAME ); // To be removed - /*analysisCldfbEncoder_ivas_fx*/ - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - realBuffer[i][j] = fixedToFloat( realBuffer_fx[i][j], 16 - cldfbScale.lb_scale ); - imagBuffer[i][j] = fixedToFloat( imagBuffer_fx[i][j], 16 - cldfbScale.lb_scale ); - } - } cldfbScale.hb_scale = cldfbScale.lb_scale; fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); #endif @@ -1634,8 +1562,7 @@ ivas_error pre_proc_front_ivas_fx( #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*float to fix conversions for noise_est_pre_32fx*/ - Etot_fx = (Word32) ( Etot * ( 1 << 24 ) ); + Etot_fx = (Word16) ( Etot * ( 1 << 8 ) ); /*float to fix conversions for wb_vad_ivas_fx*/ Word16 Q_new = Q_factor_arr( fr_bands, 40 ) + 3; @@ -1654,14 +1581,12 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( fr_bands_LR[1], fr_bands_LR_fx[1], Q_bands1 + QSCALE, 2 * NB_BANDS ); floatToFixed_arrL( hCPE->hFrontVad[0]->hNoiseEst->bckr, hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, Q_bands0 + QSCALE, NB_BANDS ); floatToFixed_arrL( hCPE->hFrontVad[1]->hNoiseEst->bckr, hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, Q_bands1 + QSCALE, NB_BANDS ); - Etot_LR_fx[0] = float_to_fix16( Etot_LR[0], 8 ); - Etot_LR_fx[1] = float_to_fix16( Etot_LR[1], 8 ); } #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED IF( hStereoClassif != NULL ) { - IF( GT_32( L_sub( L_shl( st->lp_speech_fx, 16 ), Etot_fx ), 25 << Q24 ) ) /*q24*/ + IF( GT_32( sub( st->lp_speech_fx, Etot_fx ), 25 << Q8 ) ) /*Q8*/ { hStereoClassif->silence_flag = 2; move16(); @@ -1679,7 +1604,7 @@ ivas_error pre_proc_front_ivas_fx( * SAD (1-signal, 0-noise) *----------------------------------------------------------------*/ - noise_est_pre_32fx( Etot_fx, st->ini_frame, st->hNoiseEst, st->idchan, element_mode, hCPE != NULL ? hCPE->last_element_mode : element_mode ); + noise_est_pre_32fx( L_deposit_h( Etot_fx ), st->ini_frame, st->hNoiseEst, st->idchan, element_mode, hCPE != NULL ? hCPE->last_element_mode : element_mode ); test(); test(); @@ -1780,8 +1705,8 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); - Etot_16fx = extract_h( Etot_fx ); /*q24 to q8*/ - noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_16fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); + + noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); test(); IF( lr_vad_enabled && st->idchan == 0 ) @@ -1812,39 +1737,27 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL( tmpE_LR_fx[0], tmpE_LR[0], Q_bands0 + QSCALE, 20 ); fixedToFloat_arrL( tmpN_LR_fx[1], tmpN_LR[1], Q_bands1 + QSCALE, 20 ); fixedToFloat_arrL( tmpE_LR_fx[1], tmpE_LR[1], Q_bands1 + QSCALE, 20 ); - - // performing fix to float conversion of (corr_shift_fx) - corr_shiftL = fix16_to_float( corr_shiftL_fx, 15 ); - corr_shiftR = fix16_to_float( corr_shiftR_fx, 15 ); } #endif - *relE = Etot - st->lp_speech; + *relE_fx = sub( Etot_fx, st->lp_speech_fx ); + move16(); -#ifndef IVAS_FLOAT_FIXED - corr_shift = correlation_shift( st->hNoiseEst->totalNoise ); -#else corr_shift_fx = correlation_shift_fx( st->hNoiseEst->totalNoise_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // performing fix to float conversion of (corr_shift_fx) - corr_shift = fix16_to_float( corr_shift_fx, 15 ); -#endif -#endif /*----------------------------------------------------------------* * FD-CNG Noise Estimator *----------------------------------------------------------------*/ - if ( st->hFdCngEnc != NULL ) + IF( st->hFdCngEnc != NULL ) { -#ifdef IVAS_FLOAT_FIXED resetFdCngEnc_fx( st ); -#else - resetFdCngEnc( st ); -#endif - if ( st->idchan == 0 || element_mode == IVAS_CPE_MDCT ) + test(); + IF( st->idchan == 0 || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - if ( element_mode == IVAS_CPE_TD && lr_vad_enabled && band_energies_LR != NULL ) + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_TD ) && lr_vad_enabled && band_energies_LR != NULL ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 band_energies_LR_fx[2 * NB_BANDS] = { 0 }; /* energy in critical bands without minimum noise floor E_MIN */ @@ -1962,49 +1875,67 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ - - if ( hCPE != NULL && element_mode != IVAS_CPE_DFT && element_mode != IVAS_CPE_MDCT ) + test(); + test(); + if ( hCPE != NULL && NE_16( element_mode, IVAS_CPE_DFT ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { *vad_flag_dtx = 1; + move16(); } - if ( st->Opt_DTX_ON == 1 && *vad_flag_dtx == 0 && element_mode == IVAS_CPE_DFT && element_brate <= ACELP_16k40 && hCPE->hStereoDft->hConfig->force_mono_transmission == 1 ) /* force LP_CNG usage for MASA DTX when mono tranmission */ + test(); + test(); + test(); + test(); + if ( EQ_16( st->Opt_DTX_ON, 1 ) && *vad_flag_dtx == 0 && EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, ACELP_16k40 ) && EQ_16( hCPE->hStereoDft->hConfig->force_mono_transmission, 1 ) ) /* force LP_CNG usage for MASA DTX when mono tranmission */ { st->cng_type = LP_CNG; + move16(); } -#ifndef IVAS_FLOAT_FIXED - dtx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8 ); -#else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_inp_12k8 = Q_factor_arr( inp_12k8, L_FRAME ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, L_FRAME ); - // Q_lp_noise = Q_factor( st->lp_noise ); #endif dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_inp_12k8 ); -#endif - if ( hCPE != NULL && hCPE->hStereoDft != NULL && st->core_brate == SID_2k40 ) + + test(); + test(); + IF( hCPE != NULL && hCPE->hStereoDft != NULL && EQ_32( st->core_brate, SID_2k40 ) ) { /* Add another period of expected xcorr updates */ - hCPE->hStereoDft->expectedNumUpdates += st->hDtxEnc->max_SID; + hCPE->hStereoDft->expectedNumUpdates = add( hCPE->hStereoDft->expectedNumUpdates, st->hDtxEnc->max_SID ); + move16(); } /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ - - if ( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || last_element_brate != element_brate || st->last_bwidth != st->bwidth ) ) + test(); + test(); + test(); + IF( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || NE_32( last_element_brate, element_brate ) || NE_16( st->last_bwidth, st->bwidth ) ) ) { - int32_t total_brate; + Word32 total_brate; - total_brate = ( element_mode == IVAS_SCE ) ? st->total_brate : st->bits_frame_nominal * FRAMES_PER_SEC; + IF( EQ_16( element_mode, IVAS_SCE ) ) + { + total_brate = st->total_brate; + move32(); + } + ELSE + { + total_brate = imult3216( FRAMES_PER_SEC, st->bits_frame_nominal ); + } configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), total_brate ); - configureFdCngEnc_ivas_fx( st->hFdCngEnc, max( st->input_bwidth, WB ), total_brate ); - if ( hCPE != NULL ) + configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate ); + IF( hCPE != NULL ) { - st->hFdCngEnc->hFdCngCom->CngBitrate = hCPE->element_brate - 1; + st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); + move32(); } } + test(); IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { Word16 zero_flag = 0, msPeriodog_fx_Q = Q31; @@ -2020,6 +1951,7 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->msPeriodog_fx_exp = sub( 31, msPeriodog_fx_Q ); Word16 energy_ho_fx_Q = Q31; + move16(); zero_flag = get_zero_flag( st->hFdCngEnc->energy_ho_fx, NPART ); IF( zero_flag ) { @@ -2030,6 +1962,7 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->energy_ho_fx_exp = st->hFdCngEnc->energy_ho_fx_exp - energy_ho_fx_Q; Word16 msNoiseEst_old_Q = Q31; + move16(); zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); IF( zero_flag ) { @@ -2053,13 +1986,9 @@ ivas_error pre_proc_front_ivas_fx( Word16 *inp_12k8_loc_fx, *new_inp_12k8_loc_fx; /* pointers to current frame and new data */ new_inp_12k8_loc_fx = old_inp_12k8_loc_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ inp_12k8_loc_fx = new_inp_12k8_loc_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ - Word16 lsp_new_loc_fx[M]; - Word16 lsp_mid_loc_fx[M]; - Word16 lsf_new_16_loc_fx[M]; Word16 stab_fac_fx; Word16 Q_new_loc; Word16 Q_r[2] = { 0 }; - Word16 A_loc_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; Word16 epsP_l_loc[M + 1]; Word16 epsP_h_loc[M + 1]; Word32 ener_fx; @@ -2077,10 +2006,6 @@ ivas_error pre_proc_front_ivas_fx( { old_inp_12k8_loc_fx[idx] = (Word16) ( old_inp_12k8[idx] * ( 1 << Q_new_loc ) ); } - for ( int idx = 0; idx < M; idx++ ) - { - lsp_new_loc_fx[idx] = (Word16) ( lsp_new[idx] * 32767 ); - } for ( int idx = 0; idx < 3; idx++ ) { st->voicing_fx[idx] = (Word16) ( st->voicing[idx] * 32767 ); @@ -2107,14 +2032,14 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - analy_lp_ivas_fx( inp_12k8_loc_fx, L_FRAME, L_look, &ener_fx, A_loc_fx, epsP_h_loc, epsP_l_loc, lsp_new_loc_fx, lsp_mid_loc_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, + analy_lp_ivas_fx( inp_12k8_loc_fx, L_FRAME, L_look, &ener_fx, A_fx, epsP_h_loc, epsP_l_loc, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, i, Q_new_loc, Q_r ); - lsp2lsf_fx( lsp_new_loc_fx, lsf_new_16_loc_fx, M, INT_FS_12k8 ); + lsp2lsf_fx( lsp_new_fx, lsf_new_fx, M, INT_FS_12k8 ); - stab_fac_fx = lsf_stab_fx( lsf_new_16_loc_fx, st->lsf_old1_fx, 0, L_FRAME ); + stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old1_fx, 0, L_FRAME ); - Copy( lsf_new_16_loc_fx, st->lsf_old1_fx, M ); + Copy( lsf_new_fx, st->lsf_old1_fx, M ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS float power_2 = powf( 2.0, (float) ( Q_r[0] + 1 ) ); @@ -2128,20 +2053,6 @@ ivas_error pre_proc_front_ivas_fx( check_float = (float) ener_fx / power_2; *ener = check_float; - for ( int idx = 0; idx < M; idx++ ) - { - - lsp_new[idx] = (float) lsp_new_loc_fx[idx] / 32767.0f; - lsp_mid[idx] = (float) lsp_mid_loc_fx[idx] / 32767.0f; - lsf_new[idx] = (float) ( (float) lsf_new_16_loc_fx[idx] / 2.56f ); - } - for ( int idx = 0; idx < NB_SUBFR16k * ( M + 1 ); idx++ ) - { - A[idx] = (float) ( (float) A_loc_fx[idx] / 16384.0f ); - } - - stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); - free( old_inp_12k8_loc_fx ); #endif @@ -2151,33 +2062,14 @@ ivas_error pre_proc_front_ivas_fx( * Comparison of the LP coefficents to determine if it is possible * to reuse the primary channel LP coefficients in the secondary channel *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - Word32 isp_PCh_fx[M]; - Word32 isp_SCh_fx[M]; - Word16 A_SCh_fx[M + 1]; - Word16 A_PCh_fx[M + 1]; - Word32 speech_buff[L_FRAME + M]; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 speech_buff[L_FRAME + M]; Word16 Q_speech = Q_factor_arrL( inp_12k8 - M, L_FRAME + M ); Word16 gb1 = find_guarded_bits_fx( M ); floatToFixed_arr32( inp_12k8 - M, speech_buff, Q_speech - gb1, L_FRAME + M ); - for ( i = 0; i < M + 1; i++ ) - { - A_PCh_fx[i] = (Word16) ( tdm_A_PCh[i] * ONE_IN_Q12 ); - A_SCh_fx[i] = (Word16) ( A[i] * ONE_IN_Q12 ); - } - - for ( i = 0; i < M; i++ ) - { - isp_PCh_fx[i] = (Word32) ( tdm_lsp_new_PCh[i] * MAX_32 ); - isp_SCh_fx[i] = (Word32) ( lsp_new[i] * MAX_32 ); - } -#endif - hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], A_PCh_fx, A_SCh_fx, M, isp_PCh_fx, isp_SCh_fx, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC, Q_speech ); -#else - hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison( hCPE->hStereoTD, hCPE->hStereoClassif, st, inp_12k8, tdm_A_PCh, A, M, tdm_lsp_new_PCh, lsp_new, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC ); - #endif + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), Q_speech ); + move16(); } /*----------------------------------------------------------------* @@ -2187,15 +2079,11 @@ ivas_error pre_proc_front_ivas_fx( * 1/4 pitch precision improvement *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; Word16 buf[15000] = { 0 }; Word16 *inp_12k8_fx1 = &buf[M]; // this is done because find_wsp accesses inp from -16 index Word16 wsp_fx1[L_FRAME + L_LOOK_12k8] = { 0 }; - floatToFixed_arr16( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); - Word16 e1, e2, q_inp_12k8; f2me_buf_16( inp_12k8 - M, inp_12k8_fx1, &e1, 368 + M ); f2me_buf_16( &st->mem_wsp, &st->mem_wsp_fx, &e2, 1 ); @@ -2216,13 +2104,6 @@ ivas_error pre_proc_front_ivas_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < ( NB_SUBFR16k - 1 ); i++ ) - { - FOR( int j = 0; j < M + 1; j++ ) - { - Aw[i * ( M + 1 ) + j] = (float) Aw_fx[i * ( M + 1 ) + j] / Aw_fx[i * ( M + 1 )]; - } - } FOR( i = 0; i < L_FRAME + L_LOOK_12k8; i++ ) { wsp[i] = fixedToFloat( wsp_fx1[i], q_inp_12k8 ); @@ -2230,18 +2111,8 @@ ivas_error pre_proc_front_ivas_fx( st->mem_wsp = fixedToFloat( st->mem_wsp_fx, q_inp_12k8 ); #endif -#else - find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1_FLT, L_look ); - - if ( st->vad_flag == 0 ) - { - /* reset the OL pitch tracker memories during inactive frames */ - pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); - } -#endif - old_pitch1 = st->pitch[1]; - + move16(); #ifdef IVAS_FLOAT_FIXED Word16 exp_wsp = 0, Q_wsp = 0; @@ -2251,25 +2122,21 @@ ivas_error pre_proc_front_ivas_fx( Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); - corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); f2me_buf_16( wsp, wsp_fx, &exp_wsp, L_WSP - L_WSP_MEM ); Q_wsp = sub( 15, exp_wsp ); floatToFixed_arr( wsp, wsp_fx, Q_wsp, L_WSP - L_WSP_MEM ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q_wsp, 115 ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q_wsp, 3 ); - relE_fx = (Word16) floatToFixed( *relE, Q8 ); #endif pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, - &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); + &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, *relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); - corr_shift = fixedToFloat( corr_shift_fx, Q15 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q_wsp, 115 ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q_wsp, 3 ); - *relE = fixedToFloat( relE_fx, Q8 ); #endif #else @@ -2277,8 +2144,7 @@ ivas_error pre_proc_front_ivas_fx( #endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; - -#ifdef IVAS_FLOAT_FIXED + move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -2288,10 +2154,6 @@ ivas_error pre_proc_front_ivas_fx( 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 - corr_shift_fx = float_to_fix16( corr_shift, Q15 ); - corr_shiftL_fx = float_to_fix16( corr_shiftL, Q15 ); - corr_shiftR_fx = float_to_fix16( corr_shiftR, Q15 ); - 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 ) ); @@ -2356,23 +2218,12 @@ ivas_error pre_proc_front_ivas_fx( q_inp_12k8 = Q_factor_arr( old_inp_12k8, L_INP_12k8 ); // inp_12k8_fx floatToFixed_arr16( old_inp_12k8, old_inp_12k8_fx, q_inp_12k8, L_INP_12k8 ); - Word16 Etot16_fx = float_to_fix16( Etot, Q8 ); - relE_fx = float_to_fix16( *relE, Q8 ); - Word16 Q_epsp = Q_factor_arrL( epsP, M + 1 ); floatToFixed_arr32( epsP, epsP_fx, Q_epsp, M + 1 ); FOR( Word16 j = 0; j <= M; j++ ) { L_Extract( epsP_fx[j], &epsP_h[j], &epsP_l[j] ); } - - if ( lr_vad_enabled && st->idchan == 0 ) - { - for ( int j = 0; j < 2; j++ ) - { - Etot_LR_fx[j] = float_to_fix16( Etot_LR[j], Q8 ); - } - } #endif // IVAS_FLOAT_FIXED_CONVERSIONS /* Detection of very short stable pitch period */ @@ -2412,8 +2263,8 @@ ivas_error pre_proc_front_ivas_fx( * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot16_fx, relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, &cor_map_sum16_fx, &ncharX_fx, &sp_div16_fx, &q_sp_div, - &non_staX16_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); + noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div, + &non_staX_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); test(); IF( lr_vad_enabled && st->idchan == 0 ) @@ -2443,26 +2294,14 @@ ivas_error pre_proc_front_ivas_fx( *-----------------------------------------------------------------*/ find_tilt_ivas_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, q_fr_bands, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); - 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, Etot16_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, q_inp_12k8, q_fr_bands ); + 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 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( pitch_fr_fx, pitch_fr, Q6, NB_SUBFR ); - fixedToFloat_arr( voicing_fr_fx, voicing_fr, Q15, NB_SUBFR ); - - fixedToFloat_arrL32( ee_fx, ee, Q6, 2 ); fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); - - non_staX = fixedToFloat_16( non_staX16_fx, Q8 ); - sp_div = fixedToFloat_16( sp_div16_fx, q_sp_div ); - *cor_map_sum = fixedToFloat_16( cor_map_sum16_fx, Q8 ); - - fixedToFloat_arr( S_map_fx, S_map, Q7, L_FFT / 2 ); fixedToFloat_arr( st->lgBin_E_fx, st->Bin_E, Q7, L_FFT / 2 ); if ( lr_vad_enabled && st->idchan == 0 ) { - fixedToFloat_arr( cor_map_sum_LR_fx, cor_map_sum_LR, Q8, 2 ); - fixedToFloat_arr( S_map_LR_fx, S_map_LR, Q7, L_FFT / 2 ); for ( int j = 0; j < 2; j++ ) { fixedToFloat_arrL32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, hCPE->hFrontVad[j]->hNoiseEst->bckr, q_fr_bands, NB_BANDS ); @@ -2478,71 +2317,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( st->hNoiseEst->ave_enr_fx, st->hNoiseEst->ave_enr, q_fr_bands, NB_BANDS ); fixedToFloat_arrL32( st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->ave_enr2, q_fr_bands, NB_BANDS ); #endif -#else - - /* Detection of very short stable pitch period */ - 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 ); - - /* 1/4 pitch precision improvement */ - if ( element_brate <= IVAS_32k ) - { - pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); - pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); - pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[2], &voicing_fr[2], 2 * L_SUBFR, wsp, 7 ); - pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[3], &voicing_fr[3], 3 * L_SUBFR, wsp, 7 ); - } - else - { - pitch_fr[0] = st->pitch[0]; - pitch_fr[1] = st->pitch[0]; - pitch_fr[2] = st->pitch[1]; - pitch_fr[3] = st->pitch[1]; - - voicing_fr[0] = st->voicing[0]; - voicing_fr[1] = st->voicing[0]; - voicing_fr[2] = st->voicing[1]; - voicing_fr[3] = st->voicing[1]; - } - - /*------------------------------------------------------------------* - * Update estimated noise energy and voicing cut-off frequency - *-----------------------------------------------------------------*/ - - noise_est( st, old_pitch1, tmpN, epsP, Etot, *relE, corr_shift, tmpE, fr_bands, cor_map_sum, &ncharX, &sp_div, - &non_staX, loc_harm, lf_E, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp, &dummy /*sp_floor*/, S_map, hStereoClassif, NULL, st->ini_frame ); - - if ( lr_vad_enabled && st->idchan == 0 ) - { - /* Run noise_est for Left and Right channel */ - *loc_harmLR = *loc_harm; - noise_est( st, old_pitch1, tmpN_LR[0], epsP, Etot_LR[0], Etot_LR[0] - hCPE->hFrontVad[0]->lp_speech, corr_shiftL, tmpE_LR[0], fr_bands_LR[0], &cor_map_sum_LR[0], &ncharX_LR, &sp_div_LR, - &non_staX_LR, loc_harmLR, lf_E_LR[0], &hCPE->hFrontVad[0]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[0], hCPE->hFrontVad[0]->ini_frame ); - - /* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */ - noise_est( st, old_pitch1, tmpN_LR[1], epsP, Etot_LR[1], Etot_LR[1] - hCPE->hFrontVad[1]->lp_speech, corr_shiftR, tmpE_LR[1], fr_bands_LR[1], &cor_map_sum_LR[1], &ncharX_LR, &sp_div_LR, - &non_staX_LR, loc_harmLR, lf_E_LR[1], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame ); - } - - /*------------------------------------------------------------------* - * Update parameters used in the VAD and DTX - *-----------------------------------------------------------------*/ - - vad_param_updt( st, corr_shift, corr_shift, A, old_pitch1, NULL, 1 ); - - if ( lr_vad_enabled && st->idchan == 0 ) - { - vad_param_updt( st, corr_shiftL, corr_shiftR, A, old_pitch1, &hCPE->hFrontVad[0], CPE_CHANNELS ); - } - - /*-----------------------------------------------------------------* - * Find spectral tilt - * UC and VC frame selection - *-----------------------------------------------------------------*/ - - find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, MODE1, &( st->bckr_tilt_lt_flt ), st->Opt_SC_VBR ); - - st->coder_type = find_uv( st, pitch_fr, voicing_fr, inp_12k8, ee, &dE1X, corr_shift, *relE, Etot, hp_E, &flag_spitch, last_core_orig, hStereoClassif ); -#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * channel aware mode configuration * @@ -2550,138 +2324,95 @@ ivas_error pre_proc_front_ivas_fx( st->rf_mode = 0; st->rf_target_bits_write = 0; + move16(); + move16(); /*-----------------------------------------------------------------* * Signal classification for FEC * TC frame selection *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 oi12k8_fx[L_INP_12k8]; floatToFixed_arr( old_inp_12k8, oi12k8_fx, 0, L_INP_12k8 ); // Q_fac doesn't matter as it is only being used for sign Word16 *ni12k8_fx = oi12k8_fx + L_INP_MEM; inp_12k8_fx = ni12k8_fx - L_look; - floatToFixed_arrL( ee, ee_fx, Q6, 2 ); - relE_fx = float_to_fix16( *relE, Q8 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); #endif - st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, relE_fx, L_look, tdm_SM_last_clas ); + st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); #endif -#else - st->clas = signal_clas( st, inp_12k8, ee, *relE, L_look, tdm_SM_last_clas ); -#endif -#ifndef IVAS_FLOAT_FIXED - select_TC( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); -#else + select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); -#endif + if ( st->Opt_SC_VBR ) { st->hSC_VBR->Local_VAD = st->localVAD; + move16(); } /*-----------------------------------------------------------------* * Collect stereo classifier features *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 cor_map_sum_e; - f2me( *cor_map_sum, &cor_map_sum_fx, &cor_map_sum_e ); -#endif - if ( hStereoClassif != NULL ) + IF( hStereoClassif != NULL ) { -#if 1 #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 non_staX_e, sp_div_e, epsP_e, max_e_Etot; - floatToFixed_arr32( lsf_new, lsf_new_fx, Q15, M ); - f2me_buf_16( st->voicing, st->voicing_fx, &st->voicing_e, 3 ); - f2me( non_staX, &non_staX_fx, &non_staX_e ); + Word16 epsP_e, max_e_Etot; + floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); f2me_buf( epsP, epsP_fx, &epsP_e, 17 ); - f2me( sp_div, &sp_div_fx, &sp_div_e ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS - max_e_Etot = max( hStereoClassif->e_Etot_buf_fx, max( hStereoClassif->Etot_up_e, hStereoClassif->Etot_dn_e ) ); + + max_e_Etot = s_max( hStereoClassif->e_Etot_buf_fx, s_max( hStereoClassif->Etot_up_e, hStereoClassif->Etot_dn_e ) ); scale_sig32( hStereoClassif->Etot_buf_fx, 3, hStereoClassif->e_Etot_buf_fx - max_e_Etot ); hStereoClassif->Etot_up_fx = L_shr( hStereoClassif->Etot_up_fx, max_e_Etot - hStereoClassif->Etot_up_e ); hStereoClassif->Etot_dn_fx = L_shr( hStereoClassif->Etot_dn_fx, max_e_Etot - hStereoClassif->Etot_dn_e ); hStereoClassif->Etot_up_e = hStereoClassif->Etot_dn_e = hStereoClassif->e_Etot_buf_fx = max_e_Etot; stereo_classifier_features_ivas_fx( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new_fx, epsP_fx, - st->pitch, st->voicing_fx, cor_map_sum_fx, non_staX_fx, sp_div_fx, - st->clas, epsP_e, st->voicing_e, cor_map_sum_e, non_staX_e, sp_div_e ); - -#else - stereo_classifier_features( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new, epsP, st->pitch, st->voicing, *cor_map_sum, non_staX, sp_div, st->clas ); -#endif // IVAS_FLOAT_FIXED + st->pitch, st->voicing_fx, *cor_map_sum_fx, non_staX_fx, sp_div_fx, + st->clas, epsP_e, ( 15 - Q8 ) /* exp of cor_map_sum */, ( 15 - Q8 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); } /*----------------------------------------------------------------* * 1st stage speech/music classification (GMM model) *----------------------------------------------------------------*/ -#if 0 - smc_dec = ivas_smc_gmm( st, hStereoClassif, localVAD_HE_SAD, Etot, lsp_new, *cor_map_sum, epsP, PS, non_staX, *relE, &high_lpn_flag, flag_spitch ); -#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; -#if 1 - Word16 lsp_new_fx[M]; Word32 PS_fx[128]; Word16 Q_esp; - Word16 non_sta_fx = float_to_fix16( non_staX, Q6 ); - Word16 Etot_fx_0 = float_to_fix16( Etot, Q8 ); - floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - relE_fx = float_to_fix16( *relE, 8 ); floatToFixed_arr16( st->voicing, st->voicing_fx, 15, 3 ); Word16 Qfact_PS = Q_factor_arrL( PS, 128 ); floatToFixed_arr32( PS, PS_fx, Qfact_PS, 128 ); Word16 e_esp; f2me_buf( epsP, epsP_fx, &e_esp, M + 1 ); Q_esp = sub( 31, e_esp ); - Word16 Qfact_PS_past = Q_factor_arrL( hSpMusClas->past_PS, 67 ); - floatToFixed_arr32( hSpMusClas->past_PS, hSpMusClas->past_PS_fx, Qfact_PS_past, 67 ); -#endif - smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx_0, lsp_new_fx, extract_l( L_shr( cor_map_sum_fx, sub( 23, cor_map_sum_e ) ) ) /*q8*/, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, Qfact_PS_past ); -#if 1 - fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); -#endif #endif - + smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx, lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, hSpMusClas->past_PS_Q ); /*----------------------------------------------------------------* * VAD energy updates * Update of old per-band energy spectrum *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - long_enr( st, Etot, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); -#else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from float to fix - Etot_fx = float_to_fix( Etot, 8 ); - Etot16_fx = extract_l( Etot_fx ); st->lp_speech_fx = float_to_fix16( st->lp_speech, 8 ); #endif - ivas_long_enr_fx( st, Etot16_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); + + ivas_long_enr_fx( st, Etot_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from fix to float st->lp_speech = fix16_to_float( st->lp_speech_fx, 8 ); #endif -#endif + mvr2r( fr_bands + NB_BANDS, st->hNoiseEst->enrO, NB_BANDS ); - if ( lr_vad_enabled && st->idchan == 0 ) + test(); + IF( lr_vad_enabled && st->idchan == 0 ) { -#ifndef IVAS_FLOAT_FIXED - long_enr( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from float to fix - Etot_LR_fx[0] = float_to_fix16( Etot_LR[0], 8 ); - Etot_LR_fx[1] = float_to_fix16( Etot_LR[1], 8 ); -#endif ivas_long_enr_fx( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR_fx ); -#endif + mvr2r( fr_bands_LR[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO, NB_BANDS ); mvr2r( fr_bands_LR[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO, NB_BANDS ); } @@ -2692,19 +2423,25 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ st->GSC_IVAS_mode = 0; - if ( st->idchan == 1 && element_mode == IVAS_CPE_TD ) + move16(); + test(); + IF( EQ_16( st->idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { /* No speech/music classification in the secondary channel of TD stereo */ st->sp_aud_decision1 = 0; st->sp_aud_decision2 = 0; + move16(); + move16(); st->GSC_noisy_speech = 0; + move16(); if ( st->hGSCEnc != NULL ) { st->hGSCEnc->noise_lev = NOISE_LEVEL_SP3; + move16(); } } - else if ( element_mode != IVAS_CPE_MDCT ) + ELSE IF( NE_16( element_mode, IVAS_CPE_MDCT ) ) { /* SNR-based speech/music classification */ if ( ( element_mode >= IVAS_CPE_DFT && element_brate >= IVAS_24k4 ) || ( element_mode == IVAS_SCE && element_brate >= SCE_SMC_THR ) ) @@ -2756,47 +2493,24 @@ ivas_error pre_proc_front_ivas_fx( /* these are for ivas_acelp_tcx20_switching_fx */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 lsp_mid_fx_1[M]; Word32 res_cod_SNR_M_fx[STEREO_DFT_BAND_MAX]; Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; Word16 tcx_mdct_window_fx[L_LOOK_16k]; - // Word16 stab_fac_fx; - float tmp = currFlatness * ONE_IN_Q7; Word16 wsp_fx_temp[L_WSP]; Word16 *wsp_fx_l; - non_staX16_fx = float_to_fix16( non_staX, Q8 ); - // currFlatness_fx = float_to_fix16_thrld( currFlatness, Q7 ); - if ( tmp > MAX_16 ) - { - currFlatness_fx = MAX_16; - } - else if ( tmp < MIN_16 ) - { - currFlatness_fx = MIN_16; - } - else - currFlatness_fx = (Word16) tmp; - stab_fac_fx = float_to_fix16( stab_fac, Q15 ); if ( flag_16k_smc ) floatToFixed_arr16( st->hTcxCfg->tcx_mdct_window_flt, tcx_mdct_window_fx, Q15, L_LOOK_16k ); else floatToFixed_arr16( st->hTcxCfg->tcx_mdct_window_flt, tcx_mdct_window_fx, Q15, L_LOOK_12k8 ); - floatToFixed_arr( pitch_fr, pitch_fr_fx, Q6, NB_SUBFR ); - floatToFixed_arr( voicing_fr, voicing_fr_fx, Q15, NB_SUBFR ); floatToFixed_arrL( st->hTcxEnc->spectrum_long, st->hTcxEnc->spectrum_long_fx, Q15, N_MAX ); #endif - if ( flag_16k_smc ) + IF( flag_16k_smc ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 lsp_mid_fx[M]; - - 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 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_old_inp_16k = -1; floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); + floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, 15, 16 ); st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); @@ -2816,7 +2530,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); st->Q_old_wtda = -1; // This reset needs to be looked into } -#endif #endif /* Compute core-coder buffers at internal sampling rate */ @@ -2828,11 +2541,6 @@ ivas_error pre_proc_front_ivas_fx( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); -#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // No need to do fixed to float for signal_in_fx st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); @@ -2846,6 +2554,7 @@ ivas_error pre_proc_front_ivas_fx( } fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, 15, 16 ); fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); 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 ); @@ -2867,12 +2576,11 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 q_speech_enc; - floatToFixed_arr16( lsp_mid, lsp_mid_fx_1, Q15, M ); q_speech_enc = s_min( Q_factor_arr( st->speech_enc_flt - 560, 2 * 560 ), Q_factor_arr( st->wspeech_enc_flt - 560, 2 * 560 ) ); floatToFixed_arr( st->speech_enc_flt - 560, st->speech_enc - 560, q_speech_enc, 2 * 560 ); floatToFixed_arr( st->wspeech_enc_flt - 560, st->wspeech_enc - 560, q_speech_enc, 2 * 560 ); #endif - smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, q_speech_enc, st->wspeech_enc, non_staX16_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx_1, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, q_speech_enc, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < 7; i++ ) { @@ -2898,15 +2606,13 @@ ivas_error pre_proc_front_ivas_fx( break; } } - floatToFixed_arr16( lsp_mid, lsp_mid_fx_1, Q15, M ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_new, ATT_NSEG * ATT_SEG_LEN ); floatToFixed_arr( wsp - L_WSP_MEM, wsp_fx_temp, Q_new, L_WSP_MEM ); wsp_fx_l = wsp_fx_temp + L_WSP_MEM; floatToFixed_arr( wsp, wsp_fx_l, Q_new, L_WSP - L_WSP_MEM ); #endif - smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX16_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx_1, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // st->prevTempFlatness = currFlatness; for ( i = 0; i < 7; i++ ) { res_cod_SNR_M[i] = me2f( res_cod_SNR_M_fx[i], res_cod_SNR_M_fx_e[i] ); @@ -2920,7 +2626,6 @@ ivas_error pre_proc_front_ivas_fx( /* Switch to ACELP for non-harmonic transient signals */ else if ( ( ( element_mode >= IVAS_CPE_DFT && element_brate <= IVAS_16k4 ) || ( element_mode == IVAS_SCE && element_brate < SCE_SMC_THR ) ) && ( loc_harm[0] != 1 ) && smc_dec == MUSIC ) { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( EQ_16( element_mode, IVAS_SCE ) ) { @@ -2968,33 +2673,10 @@ ivas_error pre_proc_front_ivas_fx( } } } -#else - if ( element_mode == IVAS_SCE ) - { - if ( transient_analysis( st->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) - - { - smc_dec = SPEECH; - } - } - else if ( element_mode == IVAS_CPE_DFT ) - { - for ( i = 0; i < CPE_CHANNELS; i++ ) - { - if ( smc_dec != SPEECH && transient_analysis( hCPE->hCoreCoder[i]->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) - { - smc_dec = SPEECH; /* overwrite initial music decision, initial SPEECH_MUSIC never changed */ - } - } - } -#endif } #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS #define ATT_SEG_LEN ( L_FRAME / ATT_NSEG ) - relE_fx = float_to_fix16( *relE, Q8 ); - Etot16_fx = float_to_fix16( Etot, Q8 ); - // Q_new = s_min(Q_factor_arr( inp_12k8, ATT_NSEG * ATT_SEG_LEN ), Q_factor_arr( st->Bin_E, 256 )) - 1; Q_new = 0; /* Dynamic Q_new used above causes overflow issues */ for ( int k = 0; k < ATT_NSEG * ATT_SEG_LEN; k++ ) { @@ -3006,21 +2688,9 @@ 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 ); - floatToFixed_arrL( st->hSpMusClas->tod_lt_Bin_E, st->hSpMusClas->tod_lt_Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); - floatToFixed_arr( S_map, S_map_fx, Q7, L_FFT / 2 ); - floatToFixed_arrL( st->hSpMusClas->finc_prev, st->hSpMusClas->finc_prev_fx, 2 * Q_new, ATT_NSEG ); - st->hSpMusClas->lt_finc_fx = floatToFixed( st->hSpMusClas->lt_finc, 2 * Q_new ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS - /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ - ivas_smc_mode_selection_fx( st, element_brate, smc_dec, relE_fx, Etot16_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hSpMusClas->finc_prev_fx, st->hSpMusClas->finc_prev, 2 * Q_new, ATT_NSEG ); - st->hSpMusClas->lt_finc = fixedToFloat( st->hSpMusClas->lt_finc_fx, 2 * Q_new ); - fixedToFloat_arrL( st->hSpMusClas->tod_lt_Bin_E_fx, st->hSpMusClas->tod_lt_Bin_E, Q_new + Q_SCALE - 2, TOD_NSPEC ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - + 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 /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ ivas_smc_mode_selection( st, element_brate, smc_dec, *relE, Etot, attack_flag, inp_12k8, S_map, flag_spitch ); @@ -3043,11 +2713,6 @@ ivas_error pre_proc_front_ivas_fx( mvr2r( &old_inp_12k8[L_FRAME], st->old_inp_12k8, L_INP_MEM ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 tmp = norm_s( A_fx[0] ); - fixedToFloat_arr( A_fx, A, Q14 - tmp, NB_SUBFR16k * ( M + 1 ) ); -#endif - #ifdef IVAS_FLOAT_FIXED free( enerBuffer_fx ); free( old_inp_16k_fx ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 7948c6e17..3d6e11ebc 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -96,6 +96,7 @@ ivas_error ivas_cpe_enc_fx( #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 */ @@ -103,23 +104,31 @@ ivas_error ivas_cpe_enc_fx( 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 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 vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ - Word16 attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ - float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ - float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ - 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 vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ - float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ - float currFlatness[CPE_CHANNELS] = { 0 }; /* flatness parameter */ + 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 */ + Word16 attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ + float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + Word32 realBuffer_fx[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + Word32 imagBuffer_fx[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + 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 */ #ifdef IVAS_FLOAT_FIXED Word16 currFlatness_fx[CPE_CHANNELS]; /* flatness parameter Q7 */ #endif @@ -129,7 +138,7 @@ ivas_error ivas_cpe_enc_fx( Word16 nb_bits; /* number of DFT stereo side bits */ float fr_bands[CPE_CHANNELS][2 * NB_BANDS]; /* energy in frequency bands */ - float Etot_LR[CPE_CHANNELS]; /* total energy */ + Word16 Etot_LR_fx[CPE_CHANNELS]; /* total energy Q8 */ float lf_E[CPE_CHANNELS][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ Word16 localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ float band_energies_LR[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ @@ -222,6 +231,15 @@ ivas_error ivas_cpe_enc_fx( #endif } + FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + { + FOR( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ ) + { + set_zero_fx( realBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( imagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); + } + } + /*----------------------------------------------------------------* * Stereo technology selection * Front-VAD on input L and R channels @@ -239,7 +257,6 @@ ivas_error ivas_cpe_enc_fx( move16(); Word16 Q_buffer[2]; Word32 band_energies_LR_fx[2 * NB_BANDS]; - Word16 Etot_LR_fx[CPE_CHANNELS]; Word32 lf_E_fx[CPE_CHANNELS][2 * VOIC_BINS]; Word32 fr_bands_fx[CPE_CHANNELS][2 * NB_BANDS]; Word16 band_ener_guardbits = find_guarded_bits_fx( 2 * NB_BANDS ); @@ -297,7 +314,6 @@ ivas_error ivas_cpe_enc_fx( fixedToFloat_arrL( fr_bands_fx[n], fr_bands[n], Q_buffer[n] + QSCALE, 40 ); fixedToFloat_arrL( lf_E_fx[n], lf_E[n], Q_buffer[n] + QSCALE - 2, 148 ); - Etot_LR[n] = fixedToFloat( Etot_LR_fx[n], Q8 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, hCPE->hFrontVad[n]->hNoiseEst->bckr, Q_new_old + QSCALE, 20 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, hCPE->hFrontVad[n]->hNoiseEst->enrO, Q_new_old + QSCALE, 20 ); if ( front_create_flag ) @@ -448,7 +464,8 @@ ivas_error ivas_cpe_enc_fx( { IF( sts[n]->hTranDet == NULL ) { - currFlatness[n] = 0; + currFlatness_fx[n] = 0; + move16(); CONTINUE; } @@ -467,24 +484,13 @@ ivas_error ivas_cpe_enc_fx( currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[n] = fix16_to_float( currFlatness_fx[n], Q7 ); -#endif } /* Synchonize detection for downmix-based stereo */ test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness_fx[0] = float_to_fix16( currFlatness[0], Q7 ); - currFlatness_fx[1] = float_to_fix16( currFlatness[1], Q7 ); -#endif set_transient_stereo_fx( hCPE, currFlatness_fx ); -#else - set_transient_stereo( hCPE, currFlatness ); -#endif } /*----------------------------------------------------------------* @@ -616,12 +622,6 @@ ivas_error ivas_cpe_enc_fx( hCPE->hStereoClassif->xtalk_score_fx = floatToFixed( hCPE->hStereoClassif->xtalk_score, 31 ); #endif // !MSAN_FIX - for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) - { - f2me( hCPE->hStereoDft->res_cod_NRG_M[i], &hCPE->hStereoDft->res_cod_NRG_M_fx[i], &hCPE->hStereoDft->res_cod_NRG_M_fx_e[i] ); - f2me( hCPE->hStereoDft->res_cod_NRG_S[i], &hCPE->hStereoDft->res_cod_NRG_S_fx[i], &hCPE->hStereoDft->res_cod_NRG_S_fx_e[i] ); - } - /* flt2fix: to be removed */ floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, 15, 3 ); /* flt2fix end */ @@ -824,13 +824,6 @@ ivas_error ivas_cpe_enc_fx( me2f_buf( hCPE->hStereoDft->DFT_fx[i], hCPE->hStereoDft->DFT_fx_e[i], hCPE->hStereoDft->DFT[i], STEREO_DFT_N_MAX_ENC ); } /*local fix2flt*/ - - for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) - { - hCPE->hStereoDft->res_cod_NRG_M[i] = me2f( hCPE->hStereoDft->res_cod_NRG_M_fx[i], hCPE->hStereoDft->res_cod_NRG_M_fx_e[i] ); - hCPE->hStereoDft->res_cod_NRG_S[i] = me2f( hCPE->hStereoDft->res_cod_NRG_S_fx[i], hCPE->hStereoDft->res_cod_NRG_S_fx_e[i] ); - } - /*fix2flt: dft_synthesize*/ fixedToFloat_arrL( sts[0]->input32_fx + out_start_ind, sts[0]->input + out_start_ind, 16, out_end_ind - out_start_ind ); fixedToFloat_arrL( old_inp_12k8_fx[0] + L_INP_MEM + out_12k8_start_ind[0], old_inp_12k8[0] + L_INP_MEM + out_12k8_start_ind[0], 16, out_12k8_end_ind[0] - out_12k8_start_ind[0] ); @@ -887,13 +880,35 @@ ivas_error ivas_cpe_enc_fx( * Front Pre-processing *----------------------------------------------------------------*/ - for ( n = 0; n < n_CoreChannels; n++ ) + 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 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[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], - realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], - fft_buff[n], fft_buff_fx[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, 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 ); + &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++ ) + { + realBuffer[n][i][j] = fixedToFloat( realBuffer_fx[n][i][j], q_re_im_buf ); + imagBuffer[n][i][j] = fixedToFloat( imagBuffer_fx[n][i][j], q_re_im_buf ); + } + } +#endif #else error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index e1b06984b..ff557c150 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -1090,13 +1090,8 @@ ivas_error front_vad_spar_fx( Word16 e_esp; f2me_buf( epsP, epsP_fx, &e_esp, M + 1 ); Q_esp = sub( 31, e_esp ); - Word16 Qfact_PS_past = Q_factor_arrL( hSpMusClas->past_PS, 67 ); - floatToFixed_arr32( hSpMusClas->past_PS, hSpMusClas->past_PS_fx, Qfact_PS_past, 67 ); -#endif - ivas_smc_gmm_fx( st, NULL, localVAD_HE_SAD[0], Etot_fx_0, lsp_new_fx, cor_map_sum_fx, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, Qfact_PS_past ); -#if 1 - fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); #endif + ivas_smc_gmm_fx( st, NULL, localVAD_HE_SAD[0], Etot_fx_0, lsp_new_fx, cor_map_sum_fx, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, hSpMusClas->past_PS_Q ); #endif /* long-term energy update */ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 335b524a3..2d7ba881e 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -445,34 +445,44 @@ ivas_error ivas_ism_enc_fx( 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 */ + 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 - 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 vad_hover_flag[MAX_NUM_OBJECTS][1]; /* VAD hangover flag */ - Word16 attack_flag[MAX_NUM_OBJECTS][1]; /* attack flag (GSC or TC) */ - 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 loc_harm[MAX_NUM_OBJECTS][1]; /* harmonicity flag */ - float cor_map_sum[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter */ - 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 */ - Word16 currFlatness_fx[1]; /* flatness parameter */ - float currFlatness[1]; /* flatness parameter */ - float fft_buff[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ - Word16 fft_buff_fx[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ - float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ - float Etot_LR[1]; /* total energy; correlation shift */ - float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - Word16 localVAD_HE_SAD[1]; /* local HE VAD */ + 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 */ + Word16 attack_flag[MAX_NUM_OBJECTS][1]; /* attack flag (GSC or TC) */ + Word16 q_re_im_buf = 0; + move16(); + Word32 realBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + Word32 imagBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + 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 */ + Word16 currFlatness_fx[1]; /* flatness parameter */ + float fft_buff[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ + Word16 fft_buff_fx[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ + float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ + Word16 Etot_LR_fx[1]; /* total energy; correlation shift Q8 */ + float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + Word16 localVAD_HE_SAD[1]; /* local HE VAD */ Word16 nchan_ism, dtx_flag, sid_flag, flag_noisy_speech; Word16 md_diff_flag[MAX_NUM_OBJECTS]; Encoder_State *prev_st = NULL; @@ -533,6 +543,11 @@ ivas_error ivas_ism_enc_fx( st->element_mode = IVAS_SCE; move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + set_zero_fx( realBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( imagBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX ); + } /*------------------------------------------------------------------* * SCE initialization - core coder *-----------------------------------------------------------------*/ @@ -566,9 +581,6 @@ ivas_error ivas_ism_enc_fx( currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[0] = me2f_16( currFlatness_fx[0], 15 - Q7 ); -#endif /*----------------------------------------------------------------* * Configuration of core encoder @@ -583,10 +595,37 @@ 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 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[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], - realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[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[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); + &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++ ) + { + realBuffer[sce_id][0][i][j] = fixedToFloat( realBuffer_fx[sce_id][0][i][j], q_re_im_buf ); + imagBuffer[sce_id][0][i][j] = fixedToFloat( imagBuffer_fx[sce_id][0][i][j], q_re_im_buf ); + } + } +#endif IF( NE_32( error, IVAS_ERR_OK ) ) { diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index a6d14e723..e45170c6d 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -85,12 +85,25 @@ ivas_error ivas_sce_enc_fx( 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 currFlatness[1]; /* flatness parameter */ float fft_buff[1][2 * L_FFT]; /* FFT buffer */ float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ - float Etot_LR[1]; /* total energy */ float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ #endif + Word16 A_fx[1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ + Word16 Aw_fx[1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ + Word16 lsp_new_fx[1][M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[1][M]; /* ISPs in the middle of the frame Q15 */ + Word16 pitch_fr_fx[1][NB_SUBFR]; /* fractional pitch values */ + Word16 voicing_fr_fx[1][NB_SUBFR]; /* fractional pitch gains */ + Word16 relE_fx[1]; /* frame relative energy Q8 */ + Word16 currFlatness_fx[1]; /* flatness parameter Q7 */ + Word16 Etot_LR_fx[1]; /* total energy Q8 */ + Word32 realBuffer_fx[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + Word32 imagBuffer_fx[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + Word16 q_re_im_buf = Q31; + move16(); + Word16 cor_map_sum_fx[1]; /* speech/music clasif. parameter Q8 */ + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ Word16 vad_hover_flag[1]; /* VAD hangover flag */ Word16 attack_flag[1]; /* attack flag (GSC or TC) */ @@ -134,6 +147,15 @@ ivas_error ivas_sce_enc_fx( st->element_mode = IVAS_SCE; move16(); + set16_fx( A_fx[0], 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( Aw_fx[0], 0, NB_SUBFR16k * ( M + 1 ) ); + + FOR( Word16 i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + set_zero_fx( realBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( imagBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX ); + } + /*------------------------------------------------------------------* * SCE initialization - core coder *-----------------------------------------------------------------*/ @@ -166,10 +188,8 @@ ivas_error ivas_sce_enc_fx( move16(); } - Word16 tmp = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - currFlatness[0] = me2f_16( tmp, 15 - Q7 ); -#endif + currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + move16(); /*----------------------------------------------------------------* * Configuration of core encoder @@ -233,11 +253,34 @@ 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 + 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[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], - realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], - fft_buff[0], fft_buff_fx[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, + &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], + fft_buff[0], fft_buff_fx[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, 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++ ) + { + realBuffer[0][i][j] = fixedToFloat( realBuffer_fx[0][i][j], q_re_im_buf ); + imagBuffer[0][i][j] = fixedToFloat( imagBuffer_fx[0][i][j], q_re_im_buf ); + } + } +#endif #else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 515008c0f..681de918c 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -330,10 +330,10 @@ typedef struct stereo_dft_enc_data_struct int16_t res_cod_mode[STEREO_DFT_ENC_DFT_NB]; /* mode from 0 (off) to 3 */ int16_t res_cod_band_max; /* Band max for coding of residual */ int16_t res_cod_line_max; /* Maximum number of MDCT lines to code for the residual coding */ - float res_cod_NRG_M[STEREO_DFT_BAND_MAX]; - float res_cod_NRG_S[STEREO_DFT_BAND_MAX]; float res_cod_SNR_M[STEREO_DFT_BAND_MAX]; #ifndef IVAS_FLOAT_FIXED + float res_cod_NRG_M[STEREO_DFT_BAND_MAX]; + float res_cod_NRG_S[STEREO_DFT_BAND_MAX]; float old_snr; #endif int16_t first_frm_flag; /* ADAP first frame flag */ @@ -832,11 +832,10 @@ typedef struct ivas_stereo_classifier_data_structure // Above needs to remove once everything done - Word32 voicing_ch1_fx[3]; - Word16 voicing_ch1_e; + Word16 voicing_ch1_fx[3]; Word32 cor_map_sum_ch1_fx; Word16 cor_map_sum_ch1_e; - Word32 lsf_ch1_fx[M]; + Word16 lsf_ch1_fx[M]; Word32 lepsP_ch1_fx; Word16 lepsP_ch1_e; Word32 dE1_ch1_fx, dE1_ch2_fx; @@ -845,8 +844,7 @@ typedef struct ivas_stereo_classifier_data_structure Word16 nchar_ch1_e, nchar_ch2_e; Word32 non_sta_ch1_fx; Word16 non_sta_ch1_e; - Word32 sp_div_ch1_fx; - Word16 sp_div_ch1_e; + Word16 sp_div_ch1_fx; Word32 ps_sta_ch1_fx, ps_sta_ch2_fx; Word16 ps_sta_ch1_e, ps_sta_ch2_e; Word32 prev_g_IPD_fx; // Q29 @@ -1107,23 +1105,24 @@ typedef struct ivas_spar_enc_lib_t ivas_enc_cov_handler_state_t *hCovEnc; ivas_trans_det_state_t *hTranDet; ivas_agc_enc_state_t *hAgcEnc; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; - int16_t enc_param_start_band; - int16_t AGC_Enable; + Word16 dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + Word16 enc_param_start_band; + Word16 AGC_Enable; PCA_ENC_STATE *hPCA; - int32_t core_nominal_brate; /* Nominal bitrate for core coding */ + Word32 core_nominal_brate; /* Nominal bitrate for core coding */ FRONT_VAD_ENC_HANDLE hFrontVad; /* front-VAD handle */ ENC_CORE_HANDLE hCoreCoderVAD; /* core-coder handle for front-VAD module */ #ifndef EVS_FLOAT_ENC // ENC_CORE_HANDLE_FX hCoreCoderVAD_fx; /* core coder handle */ #endif - int16_t spar_reconfig_flag; - int16_t front_vad_flag; - int16_t front_vad_dtx_flag; - int16_t force_front_vad; - + Word16 spar_reconfig_flag; + Word16 front_vad_flag; + Word16 front_vad_dtx_flag; + Word16 force_front_vad; +#ifndef IVAS_FLOAT_FIXED float *input_data_mem[MAX_NUM_OBJECTS]; +#endif } SPAR_ENC_DATA, *SPAR_ENC_HANDLE; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index a0872c08e..b85e182f3 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -492,12 +492,10 @@ void stereo_classifier_init_fx( hStereoClassif->clas_ch1 = 0; move16(); set16_fx( hStereoClassif->pitch_ch1, 0, 3 ); - set_zero_fx( hStereoClassif->voicing_ch1_fx, 3 ); - hStereoClassif->voicing_ch1_e = 0; - move16(); + set16_fx( hStereoClassif->voicing_ch1_fx, 0, 3 ); hStereoClassif->cor_map_sum_ch1_fx = 0; move32(); - set_zero_fx( hStereoClassif->lsf_ch1_fx, M ); + set16_fx( hStereoClassif->lsf_ch1_fx, 0, M ); hStereoClassif->lepsP_ch1_fx = 0; move32(); hStereoClassif->dE1_ch1_fx = 0; @@ -522,8 +520,6 @@ void stereo_classifier_init_fx( move16(); hStereoClassif->sp_div_ch1_fx = 0; move32(); - hStereoClassif->sp_div_ch1_e = 0; - move16(); hStereoClassif->ps_diff_ch1_fx = 0; move32(); hStereoClassif->ps_diff_ch1_e = 0; @@ -632,9 +628,9 @@ void stereo_classifier_init_fx( /* Information on ouputs: hStereoClassif->Etot_buf_fx has expoenent hStereoClassif->e_Etot_buf_fx hStereoClassif->relE_buf_fx has expoenent hStereoClassif->relE_buf_e -hStereoClassif->lsf_ch1_fx has exponent 16 +hStereoClassif->lsf_ch1_fx has Q1*1.28 hStereoClassif->xtalk_fv_fx has exponent 16 -hStereoClassif->voicing_ch1_fx has exponent hStereoClassif->voicing_ch1_e +hStereoClassif->voicing_ch1_fx has Q-factor Q15 hStereoClassif->lepsP_ch1_fx has exponent 16 hStereoClassif->Etot_up_fx has exponent hStereoClassif->Etot_up_e hStereoClassif->Etot_dn_fx has exponent hStereoClassif->Etot_dn_e @@ -642,7 +638,7 @@ hStereoClassif->relE_0_1_fx has exponent hStereoClassif->relE_buf_e hStereoClassif->relE_0_1_LT_fx has exponent hStereoClassif->relE_buf_e hStereoClassif->cor_map_sum_ch1_fx has exponent hStereoClassif->cor_map_sum_ch1_e hStereoClassif->non_sta_ch1_fx has exponent hStereoClassif->non_sta_ch1_e -hStereoClassif->sp_div_ch1_fx has exponent hStereoClassif->sp_div_ch1_e +hStereoClassif->sp_div_ch1_fx has exponent sp_div_e hStereoClassif->nchar_ch1_fx has exponent hStereoClassif->nchar_ch1_e hStereoClassif->nchar_ch2_fx has exponent hStereoClassif->nchar_ch2_e hStereoClassif->dE1_ch1_fx has exponent hStereoClassif->dE1_ch1_e @@ -658,16 +654,15 @@ void stereo_classifier_features_ivas_fx( const Word16 idchan, /* i : channel ID */ const Word16 element_mode, /* i : element mode */ const Word16 vad_flag, /* i : VAD flag */ - Word32 lsf_new_fx[], /* i : LSFs at the end of the frame */ + Word16 lsf_new_fx[], /* i : LSFs at the end of the frame Q1*1.28 */ Word32 epsP_fx[], /* i : LP analysis residual energies for each iteration*/ - Word16 pitch[], /*q0 i : open-loop pitch values for quantiz. */ - Word16 voicing_fx[], /* i : OL maximum normalized correlation */ + Word16 pitch[], /* i : open-loop pitch values for quantiz. Q0 */ + Word16 voicing_fx[], /* i : OL maximum normalized correlation Q15 */ Word32 cor_map_sum_fx, /* i : speech/music clasif. parameter */ Word32 non_staX_fx, /* i : unbound non-stationarity for sp/mu clas. */ - Word32 sp_div_fx, /* i : spectral diversity feature */ + Word16 sp_div_fx, /* i : spectral diversity feature */ const Word16 clas, /* i : signal class */ Word16 epsP_e, /*exponent for epsP_fx */ - Word16 voicing_e, /*exponent for voicing_fx */ Word16 cor_map_sum_e, /*exponent for cor_map_sum_fx */ Word16 non_staX_e, /*exponent for non_staX_fx */ Word16 sp_div_e /*exponent for sp_div_fx */ @@ -833,16 +828,16 @@ void stereo_classifier_features_ivas_fx( IF( idchan == 0 ) { - Copy32( lsf_new_fx, hStereoClassif->lsf_ch1_fx, M ); + Copy( lsf_new_fx, hStereoClassif->lsf_ch1_fx, M ); hStereoClassif->lepsP_ch1_fx = L_shr( L_sub( BASOP_Util_Loge( L_add( epsP_fx[13], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ), BASOP_Util_Loge( L_add( epsP_fx[0], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ) ), 10 ); /*q15*/ move32(); move16(); - hStereoClassif->xtalk_fv_fx[E_lsf_1] = lsf_new_fx[0]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lsf_4] = lsf_new_fx[3]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lsf_9] = lsf_new_fx[8]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lsf_14] = lsf_new_fx[13]; /*q15*/ - hStereoClassif->xtalk_fv_fx[E_lepsP_13] = hStereoClassif->lepsP_ch1_fx; /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_1] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[0] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_4] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[3] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_9] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[8] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lsf_14] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[13] ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_lepsP_13] = hStereoClassif->lepsP_ch1_fx; /*q15*/ move32(); move32(); move32(); @@ -863,7 +858,7 @@ void stereo_classifier_features_ivas_fx( } FOR( i = 0; i < M; i++ ) { - hStereoClassif->xtalk_fv_fx[E_sum_d_LSF] = L_add( hStereoClassif->xtalk_fv_fx[E_sum_d_LSF], L_abs( L_sub( lsf_new_fx[i], hStereoClassif->lsf_ch1_fx[i] ) ) ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_sum_d_LSF] = L_add( hStereoClassif->xtalk_fv_fx[E_sum_d_LSF], L_abs( Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, sub( lsf_new_fx[i], hStereoClassif->lsf_ch1_fx[i] ) ) ) ); /*q15*/ move32(); } @@ -882,12 +877,10 @@ void stereo_classifier_features_ivas_fx( IF( idchan == 0 ) { Copy( pitch, hStereoClassif->pitch_ch1, 3 ); - Copy_Scale_sig_16_32_no_sat( voicing_fx, hStereoClassif->voicing_ch1_fx, 3, 16 ); - hStereoClassif->voicing_ch1_e = voicing_e; - move16(); + Copy( voicing_fx, hStereoClassif->voicing_ch1_fx, 3 ); - hStereoClassif->xtalk_fv_fx[E_pitch] = Mult_32_16( L_shl( add( pitch[0], add( pitch[1], pitch[2] ) ), 15 ), 10923 ); /*q15*/ - hStereoClassif->xtalk_fv_fx[E_voicing] = Mult_32_16( L_add( voicing_fx[0], L_add( voicing_fx[1], voicing_fx[2] ) ), 10923 ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_pitch] = Mpy_32_16_1( L_shl( add( pitch[0], add( pitch[1], pitch[2] ) ), 15 ), 10923 ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_voicing] = Mpy_32_16_1( L_add( voicing_fx[0], L_add( voicing_fx[1], voicing_fx[2] ) ), 10923 ); /*q15*/ move32(); move32(); } @@ -898,7 +891,7 @@ void stereo_classifier_features_ivas_fx( FOR( i = 0; i < 3; i++ ) { hStereoClassif->xtalk_fv_fx[E_d_pitch] = L_add( hStereoClassif->xtalk_fv_fx[E_d_pitch], L_shl( abs_s( sub( pitch[i], hStereoClassif->pitch_ch1[i] ) ), Q15 ) ); - hStereoClassif->xtalk_fv_fx[E_d_voicing] = L_add( hStereoClassif->xtalk_fv_fx[E_d_voicing], L_abs( L_sub( L_shl( voicing_fx[i], voicing_e ), L_shr( hStereoClassif->voicing_ch1_fx[i], sub( 16, hStereoClassif->voicing_ch1_e ) ) ) ) ); + hStereoClassif->xtalk_fv_fx[E_d_voicing] = L_add( hStereoClassif->xtalk_fv_fx[E_d_voicing], L_abs( L_sub( voicing_fx[i], hStereoClassif->voicing_ch1_fx[i] ) ) ); move32(); move32(); } @@ -930,11 +923,10 @@ void stereo_classifier_features_ivas_fx( hStereoClassif->non_sta_ch1_fx = non_staX_fx; hStereoClassif->non_sta_ch1_e = non_staX_e; hStereoClassif->sp_div_ch1_fx = sp_div_fx; - hStereoClassif->sp_div_ch1_e = sp_div_e; hStereoClassif->xtalk_fv_fx[E_cor_map_sum] = L_shr( cor_map_sum_fx, sub( 16, cor_map_sum_e ) ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_nchar] = L_shr( BASOP_Util_Loge( L_add( L_shr( hStereoClassif->nchar_ch1_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->nchar_ch1_e ) ) ), add( hStereoClassif->nchar_ch1_e, 1 ) ) /*q25*/, 10 ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_non_sta] = L_shr( non_staX_fx, sub( 16, non_staX_e ) ); /*q15*/ - hStereoClassif->xtalk_fv_fx[E_sp_div] = L_shr( BASOP_Util_Loge( L_add( L_shr( sp_div_fx, 1 ), L_shl( 1, sub( 31, add( sp_div_e, 1 ) ) ) ), add( sp_div_e, 1 ) ), 10 ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_sp_div] = L_shr( BASOP_Util_Loge( L_deposit_h( add( shr( sp_div_fx, 1 ), shl( 1, sub( 15 - 1, sp_div_e ) ) ) ), add( sp_div_e, 1 ) ), 10 ); /*q15*/ move32(); move32(); move32(); @@ -951,7 +943,7 @@ void stereo_classifier_features_ivas_fx( hStereoClassif->xtalk_fv_fx[E_d_cor_map_sum] = L_abs( L_sub( L_shr( hStereoClassif->cor_map_sum_ch1_fx, sub( 16, hStereoClassif->cor_map_sum_ch1_e ) ) /*q15*/, L_shr( cor_map_sum_fx, sub( 16, cor_map_sum_e ) ) /*q15*/ ) ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_d_nchar] = L_abs( L_shr( L_sub( BASOP_Util_Loge( L_add( L_shr( hStereoClassif->nchar_ch1_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->nchar_ch1_e ) ) ), add( hStereoClassif->nchar_ch1_e, 1 ) ), BASOP_Util_Loge( L_add( L_shr( hStereoClassif->nchar_ch2_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->nchar_ch2_e ) ) ), add( hStereoClassif->nchar_ch2_e, 1 ) ) ) /*q25*/, 10 ) ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_d_non_sta] = L_abs( L_sub( L_shr( hStereoClassif->non_sta_ch1_fx, sub( 16, hStereoClassif->non_sta_ch1_e ) ) /*q15*/, L_shr( non_staX_fx, sub( 16, non_staX_e ) ) /*q15*/ ) ); /*q15*/ - hStereoClassif->xtalk_fv_fx[E_d_sp_div] = L_abs( L_shr( L_sub( BASOP_Util_Loge( L_add( L_shr( hStereoClassif->sp_div_ch1_fx, 1 ), L_shl( 1, sub( 30, hStereoClassif->sp_div_ch1_e ) ) ), add( hStereoClassif->sp_div_ch1_e, 1 ) ), BASOP_Util_Loge( L_add( L_shr( sp_div_fx, 1 ), L_shl( 1, sub( 30, sp_div_e ) ) ), add( sp_div_e, 1 ) ) ) /*q25*/, 10 ) ); /*q15*/ + hStereoClassif->xtalk_fv_fx[E_d_sp_div] = L_abs( L_shr( L_sub( BASOP_Util_Loge( L_deposit_h( add( shr( hStereoClassif->sp_div_ch1_fx, 1 ), shl( 1, sub( 15 - 1, sp_div_e ) ) ) ), add( sp_div_e, 1 ) ), BASOP_Util_Loge( L_deposit_h( add( shr( sp_div_fx, 1 ), shl( 1, sub( 15 - 1, sp_div_e ) ) ) ), add( sp_div_e, 1 ) ) ) /*q25*/, 10 ) ); /*q15*/ move32(); move32(); move32(); diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 24d57bb0e..901b4855e 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -980,9 +980,9 @@ void stereo_dft_enc_reset( STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ) { - int16_t i; /*reset parameters*/ #ifndef IVAS_FLOAT_FIXED + int16_t i; set_zero( hStereoDft->side_gain, STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX ); #endif set_s( hStereoDft->side_gain_index_EC, 15, STEREO_DFT_BAND_MAX ); @@ -1040,12 +1040,12 @@ void stereo_dft_enc_reset( hStereoDft->switch_fade_factor = 0.5f; #endif hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1] = STEREO_DFT_RES_COD_1kHz; +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { hStereoDft->res_cod_NRG_M[i] = 0; hStereoDft->res_cod_NRG_S[i] = 0; } -#ifndef IVAS_FLOAT_FIXED hStereoDft->old_snr = 0.f; #endif diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index d19c753c8..d558a4c34 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -1424,6 +1424,8 @@ void stereo_dft_enc_compute_itd_fx( Word16 q_temp; Word64 W_temp; Word16 W_temp_q; + Word64 W_temp1; + Word16 W_temp_q1; Word32 tmp; Word16 exp; IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) @@ -1498,30 +1500,34 @@ void stereo_dft_enc_compute_itd_fx( // log_prod_L = logf( max( FLT_MIN, ABSVAL( pDFT_L[0] ) ) ); IF( L_abs( pDFT_L[0] ) <= 0 ) { - log_prod_L = -1272712205; + log_prod_L = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); + log_prod_L_e = 7; + move16(); } ELSE { // log_prod_L = Mpy_32_32( L_add( BASOP_Util_Log2( L_abs( pDFT_L[0] ) ), L_shl( DFT_L_e_tmp[0], 25 ) ), LOG_E_2 ); log_prod_L = BASOP_Util_Loge( L_abs( pDFT_L[0] ), DFT_L_e[0] ); + log_prod_L_e = 6; + move16(); } - log_prod_L_e = 6; - move16(); // log_prod_R = logf( max( FLT_MIN, ABSVAL( pDFT_R[0] ) ) ); IF( L_abs( pDFT_R[0] ) <= 0 ) { - log_prod_R = -1272712205; + log_prod_R = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); + log_prod_R_e = 7; + move16(); } ELSE { // log_prod_R = Mpy_32_32( L_add( BASOP_Util_Log2( L_abs( pDFT_R[0] ) ), L_shl( DFT_R_e_tmp[0], 25 ) ), LOG_E_2 ); log_prod_R = BASOP_Util_Loge( L_abs( pDFT_R[0] ), DFT_R_e[0] ); + log_prod_R_e = 6; + move16(); } - log_prod_R_e = 6; - move16(); prod_L = MAX_32; // Q31 move32(); @@ -1576,17 +1582,49 @@ void stereo_dft_enc_compute_itd_fx( i = i; }*/ // xcorr[2 * i] = pDFT_L[2 * i] * pDFT_R[2 * i] + pDFT_L[2 * i + 1] * pDFT_R[2 * i + 1]; - xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ), add( DFT_L_e[2 * i], DFT_R_e[2 * i] ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i] ); move32(); // xcorr[2 * i + 1] = pDFT_L[2 * i + 1] * pDFT_R[2 * i] - pDFT_L[2 * i] * pDFT_R[2 * i + 1]; - xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ), L_negate( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i + 1] ) ), add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i + 1] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( L_negate( pDFT_L[2 * i] ), pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i + 1] ); move32(); // pNrgL[i] = pDFT_L[2 * i] * pDFT_L[2 * i] + pDFT_L[2 * i + 1] * pDFT_L[2 * i + 1]; - pNrgL[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ), shl( DFT_L_e[2 * i], 1 ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ), shl( DFT_L_e[2 * i + 1], 1 ), &pNrgL_e[i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ); // Q62 - (DFT_L_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_L_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_L_e[2 * i + 1], 1 ) ) ); + pNrgL[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgL_e[i] ); move32(); // pNrgR[i] = pDFT_R[2 * i] * pDFT_R[2 * i] + pDFT_R[2 * i + 1] * pDFT_R[2 * i + 1]; - pNrgR[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ), shl( DFT_R_e[2 * i], 1 ), Mpy_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ), shl( DFT_R_e[2 * i + 1], 1 ), &pNrgR_e[i] ); + W_temp = W_mult0_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_R_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_R_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_R_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_R_e[2 * i + 1], 1 ) ) ); + pNrgR[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgR_e[i] ); move32(); Spd_L[i] = pNrgL[i]; @@ -1615,11 +1653,17 @@ void stereo_dft_enc_compute_itd_fx( // sum_abs_R += abs_R; sum_abs_R = BASOP_Util_Add_Mant32Exp( sum_abs_R, sum_abs_R_e, abs_R, abs_R_e, &sum_abs_R_e ); // prod_L *= abs_L; - prod_L = Mpy_32_32( prod_L, abs_L ); - prod_L_e = add( prod_L_e, abs_L_e ); + W_temp = W_mult0_32_32( prod_L, abs_L ); // Q62 - (prod_L_e + abs_L_e) + W_temp_q = W_norm( W_temp ); + prod_L = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (prod_L_e + abs_L_e) + (W_temp_q - Q32) = Q30 + W_temp_q - (prod_L_e + abs_L_e) + W_temp_q = add( Q30, sub( W_temp_q, add( prod_L_e, abs_L_e ) ) ); + prod_L_e = sub( Q31, W_temp_q ); // prod_R *= abs_R; - prod_R = Mpy_32_32( prod_R, abs_R ); - prod_R_e = add( prod_R_e, abs_R_e ); + W_temp = W_mult0_32_32( prod_R, abs_R ); // Q62 - (prod_R_e + abs_R_e) + W_temp_q = W_norm( W_temp ); + prod_R = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (prod_R_e + abs_R_e) + (W_temp_q - Q32) = Q30 + W_temp_q - (prod_R_e + abs_R_e) + W_temp_q = add( Q30, sub( W_temp_q, add( prod_R_e, abs_R_e ) ) ); + prod_R_e = sub( Q31, W_temp_q ); // grand_dot_prod_real += xcorr[2 * i]; grand_dot_prod_real = BASOP_Util_Add_Mant32Exp( grand_dot_prod_real, grand_dot_prod_real_e, xcorr[2 * i], xcorr_e[2 * i], &grand_dot_prod_real_e ); @@ -1648,9 +1692,9 @@ void stereo_dft_enc_compute_itd_fx( prod_R = L_max( 0, prod_R ); IF( prod_L <= 0 ) { - L_temp = -1272712205; + L_temp = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); - L_temp_e = 6; + L_temp_e = 7; move16(); } ELSE @@ -1664,9 +1708,9 @@ void stereo_dft_enc_compute_itd_fx( IF( L_abs( prod_R ) <= 0 ) { - L_temp = -1272712205; + L_temp = -1465264128; /* logf(FLT_MIN) in Q24 */ move32(); - L_temp_e = 6; + L_temp_e = 7; move16(); } ELSE @@ -1839,7 +1883,7 @@ void stereo_dft_enc_compute_itd_fx( move32(); L_temp_e = 0; move16(); - FOR( i = 0; i < 11; i++ ) + FOR( Word16 ii = 0; ii < 11; ii++ ) { L_temp = BASOP_Util_Add_Mant32Exp( L_temp, L_temp_e, Spd_L[i + 1], Spd_L_e[i + 1], &L_temp_e ); } @@ -1912,17 +1956,49 @@ void stereo_dft_enc_compute_itd_fx( FOR( ; i < NFFT / 2; i++ ) { // xcorr[2 * i] = pDFT_L[2 * i] * pDFT_R[2 * i] + pDFT_L[2 * i + 1] * pDFT_R[2 * i + 1]; - xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ), add( DFT_L_e[2 * i], DFT_R_e[2 * i] ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i] ); move32(); // xcorr[2 * i + 1] = pDFT_L[2 * i + 1] * pDFT_R[2 * i] - pDFT_L[2 * i] * pDFT_R[2 * i + 1]; - xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ), add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ), L_negate( Mpy_32_32( pDFT_L[2 * i], pDFT_R[2 * i + 1] ) ), add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ), &xcorr_e[2 * i + 1] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_R[2 * i] ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] + DFT_R_e[2 * i]) + W_temp_q = add( Q30, sub( W_temp_q, add( DFT_L_e[2 * i + 1], DFT_R_e[2 * i] ) ) ); + W_temp1 = W_mult0_32_32( L_negate( pDFT_L[2 * i] ), pDFT_R[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] + DFT_R_e[2 * i + 1]) + W_temp_q1 = add( Q30, sub( W_temp_q1, add( DFT_L_e[2 * i], DFT_R_e[2 * i + 1] ) ) ); + xcorr[2 * i + 1] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &xcorr_e[2 * i + 1] ); move32(); // pNrgL[i] = pDFT_L[2 * i] * pDFT_L[2 * i] + pDFT_L[2 * i + 1] * pDFT_L[2 * i + 1]; - pNrgL[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ), shl( DFT_L_e[2 * i], 1 ), Mpy_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ), shl( DFT_L_e[2 * i + 1], 1 ), &pNrgL_e[i] ); + W_temp = W_mult0_32_32( pDFT_L[2 * i], pDFT_L[2 * i] ); // Q62 - (DFT_L_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_L_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_L_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_L[2 * i + 1], pDFT_L[2 * i + 1] ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_L_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_L_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_L_e[2 * i + 1], 1 ) ) ); + pNrgL[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgL_e[i] ); move32(); // pNrgR[i] = pDFT_R[2 * i] * pDFT_R[2 * i] + pDFT_R[2 * i + 1] * pDFT_R[2 * i + 1]; - pNrgR[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ), shl( DFT_R_e[2 * i], 1 ), Mpy_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ), shl( DFT_R_e[2 * i + 1], 1 ), &pNrgR_e[i] ); + W_temp = W_mult0_32_32( pDFT_R[2 * i], pDFT_R[2 * i] ); // Q62 - (DFT_R_e[2 * i] * 2) + W_temp_q = W_norm( W_temp ); + L_temp = W_extract_h( W_shl( W_temp, W_temp_q ) ); // Q62 - (DFT_R_e[2 * i] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i] * 2) + W_temp_q = add( Q30, sub( W_temp_q, shl( DFT_R_e[2 * i], 1 ) ) ); + W_temp1 = W_mult0_32_32( pDFT_R[2 * i + 1], pDFT_R[2 * i + 1] ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = W_norm( W_temp1 ); + L_temp2 = W_extract_h( W_shl( W_temp1, W_temp_q1 ) ); // Q62 - (DFT_R_e[2 * i + 1] * 2) + (W_temp_q - Q32) = Q30 + W_temp_q - (DFT_R_e[2 * i + 1] * 2) + W_temp_q1 = add( Q30, sub( W_temp_q1, shl( DFT_R_e[2 * i + 1], 1 ) ) ); + pNrgR[i] = BASOP_Util_Add_Mant32Exp( L_temp, sub( Q31, W_temp_q ), L_temp2, sub( Q31, W_temp_q1 ), &pNrgR_e[i] ); move32(); /* Calculate L and R energy power spectrum */ Spd_L[i] = pNrgL[i]; @@ -2318,7 +2394,7 @@ void stereo_dft_enc_compute_itd_fx( hItd->xcorr_smooth_fx[i] = L_shr_r( hItd->xcorr_smooth_fx[i], sub( hItd->xcorr_smooth_fx_e, xcorr_smooth_fx_tmp_e[i] ) ); move32(); } - max_exp = 0; + max_exp = MIN_16; move16(); FOR( i = 0; i < STEREO_DFT_N_32k_ENC; i++ ) { diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index a61ee2250..3462f614b 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -141,7 +141,7 @@ static void stereo_td_get_td_itd_fx( d = BASOP_Util_Divide3232_Scale( input_Fs, 16000, &d_e ); temp_div = BASOP_Util_Divide3232_Scale( itd, L_deposit_h( d ), &temp_e ); temp_e = add( temp_e, sub( sub( 31, q_itd ), d_e ) ); // e+(e1-e2)// - temp_add = add_sat( temp_div, shr( FLR_FX, temp_e ) ); + temp_add = add_sat( temp_div, shr_sat( FLR_FX, temp_e ) ); *td_itd_32 = shl( shr( temp_add, sub( 15, temp_e ) ), 1 ); move16(); diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index 6cad92d83..bd8a947d7 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -1821,9 +1821,20 @@ static void estDownmixGain_fx( currentGain = BASOP_Util_Divide3232_Scale( tempN, tempD, &exp ); currentGain_e = exp; move16(); + if ( currentGain == 0 ) + { + currentGain_e = 0; + move16(); + } } - currentGain = s_max( EPSILON_FX, currentGain ); + IF( GT_32( EPSILON_FX, currentGain ) ) + { + currentGain = EPSILON_FX; + move16(); + currentGain_e = 0; + move16(); + } hStereoTCA->instTargetGain_fx = L_shl_sat( L_deposit_h( currentGain ), sub( currentGain_e, 2 ) ); move32(); prevTargetGain_log10 = BASOP_Util_Log10( hStereoTCA->prevTargetGain_fx, 2 ); // Output in Q25 @@ -1845,6 +1856,11 @@ static void estDownmixGain_fx( tempD = BASOP_util_Pow2( L_mult( currentGain, 27213 ), add( currentGain_e, Q2 ), &exp ); unclr_instTargetGain = L_deposit_h( BASOP_Util_Divide3232_Scale( tempN, L_add( tempD, EPSILON_FX ), &exp_div ) ); exp = add( sub( exp_chan, exp ), exp_div ); + if ( unclr_instTargetGain == 0 ) + { + exp = 0; + move16(); + } unclr_instTargetGain = BASOP_Util_Log10( L_add( unclr_instTargetGain, L_shr( MAX_32, sub( Q31, exp ) ) ), exp ); // unclr_fv_fx is expected in Q15 - log result will be in Q25 - hence rightshift by 10. hStereoClassif->unclr_fv_fx[E_ica_instTargetGain] = L_shr( unclr_instTargetGain, Q10 ); @@ -2314,8 +2330,8 @@ void stereo_tca_enc_fx( } /* populate L/R memories into current buffers */ - Word16 tempp_scale = getScaleFactor32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ); - tempp_scale = s_min( tempp_scale, getScaleFactor32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ) ); + Word16 tempp_scale = L_norm_arr( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ); + tempp_scale = s_min( tempp_scale, L_norm_arr( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ) ); scale_sig32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); scale_sig32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); hStereoTCA->memChan_q = add( hStereoTCA->memChan_q, tempp_scale ); @@ -2684,14 +2700,18 @@ void stereo_tca_enc_fx( /* quantize the corrStats */ Word16 temp_exp, tempF_16fx; - Word16 scalar_value = BASOP_Util_Divide3232_Scale( currentNCShift, dsFactor, &temp_exp ); - if ( scalar_value == 0 ) + Word16 scalar_value = BASOP_Util_Divide1616_Scale( currentNCShift, dsFactor, &temp_exp ); + IF( temp_exp < 0 ) { - temp_exp = 14; + scalar_value = shl( scalar_value, sub( temp_exp, Q3 ) ); // Q12 + hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, ONE_IN_Q11, 1 << STEREO_BITS_TCA_CORRSTATS ); + move16(); + } + ELSE + { + hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, shl( 1, sub( 14, temp_exp ) ), 1 << STEREO_BITS_TCA_CORRSTATS ); move16(); } - hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, shl( 1, sub( 14, temp_exp ) ), 1 << STEREO_BITS_TCA_CORRSTATS ); - move16(); tempF_fx = tempF_16fx; move32(); } diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index c745013c2..20bc57c1d 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -2823,8 +2823,8 @@ Word16 tdm_lp_comparison_fx( const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ const Word16 m, /* i : filter length */ - const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ - const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 *isp_PCh_fx, /* i : primary channel LSPs Q15 */ + const Word16 *isp_SCh_fx, /* i : secondary channel LSPs Q15 */ const Word16 L_frame, /* i : frame length */ const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ Word16 Q_speech ) @@ -2879,7 +2879,7 @@ Word16 tdm_lp_comparison_fx( FOR( i = 0; i < m; i++ ) { // ftmp = isp_SCh[i] - isp_PCh[i]; - ftmp_fx = L_sub( isp_SCh_fx[i], isp_PCh_fx[i] ); + ftmp_fx = L_deposit_h( sub( isp_SCh_fx[i], isp_PCh_fx[i] ) ); // dist += ftmp * ftmp; dist_fx = L_add( dist_fx, L_shr( Mpy_32_32( ftmp_fx, ftmp_fx ), gb ) ); // Q31-gb } diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index c2635ec42..8cc57eb2d 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -579,11 +579,11 @@ void lsf_enc_ivas_fx( } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); } ELSE { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); } /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index d5f2028f0..eb04543a4 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2153,7 +2153,7 @@ void noise_est_ivas_fx( Word16 *ncharX, /* o : Q11 */ Word16 *sp_div, /* o : Q_sp_div */ Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16 *non_staX, /* o : non-stationarity for sp/mus classifier Q8 */ Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 1e937bf73..bf74ed5ad 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -142,6 +142,8 @@ void speech_music_clas_init( #endif hSpMusClas->sp_mus_state = -8; + set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); + hSpMusClas->past_PS_Q = Q31; #ifndef IVAS_FLOAT_FIXED hSpMusClas->wdrop = 0.0f; hSpMusClas->wrise = 0.0f; @@ -150,9 +152,7 @@ void speech_music_clas_init( set_f( hSpMusClas->last_lsp, 0.0f, M_LSP_SPMUS ); hSpMusClas->last_cor_map_sum = 0.0f; hSpMusClas->last_non_sta = 0.0f; -#endif set_f( hSpMusClas->past_PS, 0.0f, HIGHEST_FBIN - LOWEST_FBIN ); -#ifndef IVAS_FLOAT_FIXED hSpMusClas->past_ps_diff = 0; hSpMusClas->past_epsP2 = 01; hSpMusClas->past_epsP = 0; @@ -232,17 +232,18 @@ void speech_music_clas_init( hSpMusClas->mov_log_max_spl = 200.0f; hSpMusClas->old_lt_diff[0] = 0.0f; hSpMusClas->old_lt_diff[1] = 0.0f; -#endif - set_f( hSpMusClas->finc_prev, 0.0f, ATT_NSEG ); hSpMusClas->lt_finc = 0.0f; +#endif + hSpMusClas->last_strong_attack = 0; #ifdef IVAS_FLOAT_FIXED hSpMusClas->tdm_lt_Etot_fx = 328 /* 0.01 in Q15*/; + set32_fx( hSpMusClas->tod_lt_Bin_E_fx, 0, TOD_NSPEC ); #else hSpMusClas->tdm_lt_Etot = 0.01f; -#endif set_f( hSpMusClas->tod_lt_Bin_E, 0.0f, TOD_NSPEC ); +#endif #ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->tod_S_map_lt, 0.0f, TOD_NSPEC ); hSpMusClas->tod_thr_lt = TOD_THR_MASS; diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index cc240abe4..b7c079905 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -1740,15 +1740,14 @@ Word16 ivas_smc_gmm_fx( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ const Word16 Etot_fx, /* i : total frame energy */ - Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ - Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ - Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ - Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ - const Word16 non_sta_fx, /* i : unbound non-stationarity */ - const Word16 relE_fx, /* i : relative frame energy */ + const Word16 lsp_new_fx[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) Q8 */ + const Word32 epsP_fx[M + 1], /* i : LP prediciton error */ + const Word32 PS_fx[], /* i : energy spectrum */ + const Word16 non_sta_fx, /* i : unbound non-stationarity Q8 */ + const Word16 relE_fx, /* i : relative frame energy Q8 */ Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ - const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ - , + const Word16 flag_spitch, /* i : flag to indicate very short stable pitch */ Word16 Qfact_PS, Word16 Q_esp, Word16 Qfact_PS_past ) @@ -2020,11 +2019,11 @@ Word16 ivas_smc_gmm_fx( *pFV++ = acosf( lsp_new[6] );*/ /* [7] cor_map_sum */ - *pFV_fx++ = L_shl( cor_map_sum_fx, Q12 ); + *pFV_fx++ = L_shl( cor_map_sum_fx, Q12 ); /*scaling from Q8 to Q20*/ move32(); /* [8] non_sta */ - *pFV_fx++ = L_shl( non_sta_fx, Q14 ); /*scaling from 6 to 20*/ + *pFV_fx++ = L_shl( non_sta_fx, Q12 ); /*scaling from Q8 to Q20*/ move32(); /* [9] epsP */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 605fbbdbe..223778e89 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -394,21 +394,21 @@ typedef struct cldfb_vad_structure typedef struct td_cng_enc_structure { - int16_t lp_cng_mode2; + Word16 lp_cng_mode2; #ifndef IVAS_FLOAT_FIXED float lp_ener; /* CNG and DTX - low-pass filtered energy for CNG */ #else Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG Q6 */ #endif - int16_t cng_seed; /* CNG and DTX - seed for white noise random generator */ - int16_t old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ + Word16 cng_seed; /* CNG and DTX - seed for white noise random generator */ + Word16 old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ #ifndef IVAS_FLOAT_FIXED float Enew; /* CNG and DTX - CNG target residual energy */ #else Word32 Enew_fx; /* CNG and DTX - CNG target residual energy Q6 */ #endif - int16_t cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + Word16 cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED float cng_lsp_hist[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float cng_ener_hist[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ @@ -416,17 +416,17 @@ typedef struct td_cng_enc_structure Word16 cng_lsp_hist_fx[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging Q15 */ Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging Q8 */ #endif - int16_t cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ - int16_t cng_ener_seed1; + Word16 cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ + Word16 cng_ener_seed1; #ifndef IVAS_FLOAT_FIXED float lp_sp_enr; #else Word16 lp_sp_enr_fx; /* Q8 */ #endif - int16_t last_allow_cn_step; - int16_t ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ - int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + Word16 last_allow_cn_step; + Word16 ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + int32_t ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_hist[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_hist[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ @@ -437,9 +437,9 @@ typedef struct td_cng_enc_structure Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ #endif - int16_t act_cnt; /* CNG and DTX - counter of active frames */ - int16_t ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + Word16 act_cnt; /* CNG and DTX - counter of active frames */ + Word16 ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_circ[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_circ[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ @@ -449,8 +449,8 @@ typedef struct td_cng_enc_structure Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging Q6 */ Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; /* Q6 */ #endif - int16_t burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ - int16_t cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ + Word16 burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ + Word16 cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ float cng_exc2_buf_flt[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ @@ -460,32 +460,32 @@ typedef struct td_cng_enc_structure #else Word16 CNG_att_fx; /* CNG and DTX - attenuation factor for CNG, in dB Q7 */ #endif - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ - int16_t act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ + Word16 ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ + Word16 act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ #else Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs Q15 */ #endif - int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ + Word16 num_ho; /* CNG and DTX - number of selected hangover frames */ #ifndef IVAS_FLOAT_FIXED float old_env[NUM_ENV_CNG]; float lp_env[NUM_ENV_CNG]; float cng_res_env[NUM_ENV_CNG * HO_HIST_SIZE]; + float exc_mem[24]; + float exc_mem1[30]; + float exc_mem2[30]; #else Word32 old_env_fx[NUM_ENV_CNG]; /* Q6 */ Word32 lp_env_fx[NUM_ENV_CNG]; /* Q6 */ Word32 cng_res_env_fx[NUM_ENV_CNG * HO_HIST_SIZE]; /* Q6 */ #endif - float exc_mem[24]; - float exc_mem1[30]; - float exc_mem2[30]; Word16 exc_mem_fx[24]; Word16 exc_mem1_fx[30]; Word16 exc_mem2_fx[30]; /* SWB DTX/CNG parameters */ - int16_t last_vad; + Word16 last_vad; #ifndef IVAS_FLOAT_FIXED float last_wb_cng_ener; float last_shb_cng_ener; @@ -497,10 +497,10 @@ typedef struct td_cng_enc_structure Word16 mov_wb_cng_ener_fx; /* Q8 */ Word16 mov_shb_cng_ener_fx; /* Q8 */ #endif - int16_t last_idx_ener; - int16_t shb_cng_ini_cnt; - int16_t last_SID_bwidth; - int16_t shb_NO_DATA_cnt; + Word16 last_idx_ener; + Word16 shb_cng_ini_cnt; + Word16 last_SID_bwidth; + Word16 shb_NO_DATA_cnt; } TD_CNG_ENC_DATA, *TD_CNG_ENC_HANDLE; @@ -647,7 +647,6 @@ typedef struct igf_enc_private_data_struct IGF_INFO igfInfo; Word16 igfScfQuantized[IGF_MAX_SFB]; IGFSCFENC_INSTANCE hIGFSCFArithEnc; -#ifdef IVAS_FLOAT_FIXED Word16 prevSFM_FIR_SFB_TB_fx[IGF_MAX_SFB]; Word16 prevSFB_FIR_TB_e[IGF_MAX_SFB]; Word16 prevSFB_IIR_TB_e[IGF_MAX_SFB]; @@ -663,7 +662,6 @@ typedef struct igf_enc_private_data_struct Word16 prevDampingFactor_IIR_fx[IGF_MAX_SFB]; Word16 prevDampingFactor_IIR_e[IGF_MAX_SFB]; Word16 igfPastSFM_fx[IGF_MAX_TILES][IGF_PAST_SFM_LEN]; /*2Q13*/ -#endif // IVAS_FLOAT_FIXED Word16 logSpec[L_FRAME_PLUS]; @@ -810,9 +808,10 @@ typedef struct sp_mus_clas_structure #else Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ #endif - float past_PS[HIGHEST_FBIN - LOWEST_FBIN]; + Word16 past_PS_Q; Word32 past_PS_fx[HIGHEST_FBIN - LOWEST_FBIN]; #ifndef IVAS_FLOAT_FIXED + float past_PS[HIGHEST_FBIN - LOWEST_FBIN]; float past_ps_diff; float prev_FV[N_SMC_FEATURES]; float past_epsP; @@ -823,7 +822,7 @@ typedef struct sp_mus_clas_structure Word16 past_epsP_fx; Word16 past_epsP2_fx; /* Q10 */ #endif - int16_t inact_cnt; + Word16 inact_cnt; #ifndef IVAS_FLOAT_FIXED float wdrop; float wrise; @@ -836,8 +835,8 @@ typedef struct sp_mus_clas_structure Word32 wdlp_0_95_sp_32fx; /* IVAS - Q24 */ Word32 wdlp_xtalk_fx; /* Q19 */ #endif - int16_t sp_mus_state; - int16_t past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ + Word16 sp_mus_state; + Word16 past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ #ifndef IVAS_FLOAT_FIXED float past_dlp[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions */ float past_dlp_mean_ST[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ @@ -847,7 +846,7 @@ typedef struct sp_mus_clas_structure Word32 past_dlp_mean_ST_fx[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) Q19 */ Word32 dlp_mean_ST_fx; /* Q19 */ #endif - int16_t flag_spitch_cnt; + Word16 flag_spitch_cnt; #ifndef IVAS_FLOAT_FIXED float dlp_mean_LT; float dlp_var_LT; @@ -870,9 +869,9 @@ typedef struct sp_mus_clas_structure Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory Q8 */ #endif - int16_t gsc_last_music_flag; /* Speech/music classifier - last music flag */ - int16_t gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ - int16_t gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ + Word16 gsc_last_music_flag; /* Speech/music classifier - last music flag */ + Word16 gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ + Word16 gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ #ifndef IVAS_FLOAT_FIXED float mold_corr; float mean_avr_dyn; /* Speech/music classifier - long term average dynamic */ @@ -887,7 +886,7 @@ typedef struct sp_mus_clas_structure Word16 ener_RAT_fx; /* Speech/music classifier - LF/to total energy ratio Q15 */ #endif - int16_t relE_attack_cnt; + Word16 relE_attack_cnt; #ifndef IVAS_FLOAT_FIXED float prev_relE; float prev_Etot; @@ -895,8 +894,8 @@ typedef struct sp_mus_clas_structure Word16 prev_relE_fx; /* Q8 */ Word16 prev_Etot_fx; /* Q8 */ #endif - int16_t prev_vad; - int16_t vad_0_1_cnt; + Word16 prev_vad; + Word16 vad_0_1_cnt; #ifndef IVAS_FLOAT_FIXED float relE_attack_sum; #else @@ -926,13 +925,13 @@ typedef struct sp_mus_clas_structure Word16 buf_dlp_fx[10]; /* Q9 */ #endif - int16_t onset_cnt; + Word16 onset_cnt; #ifndef IVAS_FLOAT_FIXED float buf_etot[4]; #else Word16 buf_etot_fx[4]; /* Q8 */ #endif - int16_t attack_hangover; + Word16 attack_hangover; #ifndef IVAS_FLOAT_FIXED float dec_mov; float dec_mov1; @@ -944,21 +943,23 @@ typedef struct sp_mus_clas_structure Word16 mov_log_max_spl_fx; /* Q7 */ Word16 old_lt_diff_fx[2]; /* Q7 */ #endif - int16_t UV_cnt1; + Word16 UV_cnt1; #ifndef IVAS_FLOAT_FIXED float LT_UV_cnt1; #else Word16 LT_UV_cnt1_fx; /* Q6 */ #endif - float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ - float lt_finc; /* strong attack detection - long-term finc energy */ +#ifndef IVAS_FLOAT_FIXED + float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ + float lt_finc; /* strong attack detection - long-term finc energy */ +#endif Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (Q_new * 2) */ Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, (Q_new * 2) */ int16_t last_strong_attack; /* strong attack detection - last strong attack flag */ - float tod_lt_Bin_E[TOD_NSPEC]; /* tonal detector - long-term energy spectrum */ Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_new + Q_SCALE - 2 */ #ifndef IVAS_FLOAT_FIXED + float tod_lt_Bin_E[TOD_NSPEC]; /* tonal detector - long-term energy spectrum */ float tod_S_map_lt[TOD_NSPEC]; /* tonal detector - long-term correlation map */ float tod_thr_lt; /* tonal detector - adaptive threshold */ float tod_weight; /* tonal detector - adaptive weight */ @@ -972,7 +973,7 @@ typedef struct sp_mus_clas_structure Word32 tod_S_mass_lt_fx; /* Q22 */ #endif - int16_t lt_music_hangover; + Word16 lt_music_hangover; #ifndef IVAS_FLOAT_FIXED float tonality2_buf[HANG_LEN_INIT]; float tonality3_buf[HANG_LEN_INIT]; @@ -982,9 +983,9 @@ typedef struct sp_mus_clas_structure Word16 tonality3_buf_fx[HANG_LEN_INIT]; /* Q14 */ Word16 LPCErr_buf_fx[HANG_LEN_INIT]; /* Q10 */ #endif - int16_t lt_music_state; - int16_t lt_speech_state; - int16_t lt_speech_hangover; + Word16 lt_music_state; + Word16 lt_speech_state; + Word16 lt_speech_hangover; #ifndef IVAS_FLOAT_FIXED float lpe_buf[HANG_LEN_INIT]; float voicing_buf[HANG_LEN_INIT]; @@ -992,7 +993,7 @@ typedef struct sp_mus_clas_structure Word16 lpe_buf_fx[HANG_LEN_INIT]; /* Q10 */ Word16 voicing_buf_fx[HANG_LEN_INIT]; /* Q13 */ #endif - int16_t gsc_hangover; + Word16 gsc_hangover; #ifndef IVAS_FLOAT_FIXED float sparse_buf[HANG_LEN_INIT]; float hf_spar_buf[HANG_LEN_INIT]; @@ -1002,11 +1003,11 @@ typedef struct sp_mus_clas_structure Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ Word16 LT_sparse_fx; /* Q8 */ #endif - int16_t gsc_cnt; + Word16 gsc_cnt; /* speech/music classification */ - int16_t last_vad_spa; - int16_t lt_old_mode[3]; + Word16 last_vad_spa; + Word16 lt_old_mode[3]; #ifndef IVAS_FLOAT_FIXED float lt_voicing_flt; float lt_corr_flt; @@ -1016,8 +1017,8 @@ typedef struct sp_mus_clas_structure Word16 lt_corr; /* Q15 */ Word32 lt_tonality; /* Q15 */ #endif - int16_t lt_corr_pitch[3]; - int16_t lt_hangover; + Word16 lt_corr_pitch[3]; + Word16 lt_hangover; #ifndef IVAS_FLOAT_FIXED float lowrate_pitchGain_flt; float tdm_lt_Etot; @@ -1027,7 +1028,7 @@ typedef struct sp_mus_clas_structure Word16 tdm_lt_Etot_fx; /* Q8 */ Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ #endif - int16_t high_stable_cor; + Word16 high_stable_cor; #ifndef IVAS_FLOAT_FIXED float lps; @@ -1130,7 +1131,8 @@ typedef struct gsc_enc_structure #ifndef IVAS_FLOAT_FIXED float mem_w0_tmp; float mem_syn_tmp[M]; - float mid_dyn; /* AC mode (GSC) - signal dynamic */ + float mid_dyn; /* AC mode (GSC) - signal dynamic */ + float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ #else Word16 mem_w0_tmp_fx; Word16 mem_syn_tmp_fx[M]; @@ -1138,7 +1140,6 @@ typedef struct gsc_enc_structure #endif int16_t noise_lev; /* AC mode (GSC) - noise level */ int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ - float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ 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 */ @@ -1507,7 +1508,7 @@ typedef struct td_bwe_enc_structure Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; Word16 prev_Q_bwe_exc_fb; Word16 fb_tbe_demph_fx; - Word16 tilt_mem_fx; /* Q12 */ + Word16 tilt_mem_fx; /* Q12 */ #endif int16_t prev_coder_type; @@ -1515,10 +1516,10 @@ typedef struct td_bwe_enc_structure float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; #else + float cur_sub_Aq[M + 1]; Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ Word16 prev_tilt_para_fx; /* Q10 */ #endif - float cur_sub_Aq[M + 1]; Word16 cur_sub_Aq_fx[M + 1]; /* Q12 */ /* quantized data */ @@ -2009,8 +2010,7 @@ typedef struct enc_core_structure int16_t pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ float voicing[3]; /* open-loop normalized correlation values for three half-frames */ // Word16 pitch_fx[3]; - Word16 voicing_fx[3]; - Word16 voicing_e; + Word16 voicing_fx[3]; /* Q15 */ LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 52ac2398d..3974a326d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -3560,7 +3560,7 @@ void swb_tbe_enc_ivas_fx( res_e = sub( add( res_e, 31 ), tmp_e ); - acorr_v2a_fx = sub( acorr_v2a_fx, shl( 1, sub( 15, res_e ) ) ); + res_e = BASOP_Util_Add_MantExp( acorr_v2a_fx, res_e, -1, 15, &acorr_v2a_fx ); /* limit in the range 0.0 - 1.0 */ // acorr_v2a = min( 1.0f, max( 0.0f, acorr_v2a ) ); -- GitLab