From 051c900bd6747a4e7c68172ef8aed4f02809b668 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 27 Nov 2024 21:03:56 +0530 Subject: [PATCH] Encoder LTV crash fixes and float code clean up --- lib_com/cnst.h | 1 + lib_com/core_com_config.c | 22 +- lib_com/ivas_prot.h | 35 +- lib_com/ivas_prot_fx.h | 17 +- lib_com/lerp.c | 2 +- lib_com/prot.h | 10 +- lib_com/prot_fx.h | 66 +- lib_com/stat_com.h | 77 +- lib_com/swb_tbe_com_fx.c | 1241 ++++++++++++++++++++++++- lib_com/syn_filt_fx.c | 2 +- lib_com/tcx_utils.c | 2 + lib_dec/swb_tbe_dec.c | 20 +- lib_dec/tonalMDCTconcealment.c | 7 +- lib_enc/analy_sp.c | 2 + lib_enc/analy_sp_fx.c | 5 +- lib_enc/cod_tcx.c | 2 + lib_enc/cod_tcx_fx.c | 21 +- lib_enc/core_enc_init.c | 48 +- lib_enc/core_enc_ol.c | 7 - lib_enc/core_enc_switch.c | 10 - lib_enc/core_switching_enc.c | 33 +- lib_enc/dtx.c | 105 +-- lib_enc/dtx_fx.c | 97 ++ lib_enc/init_enc.c | 79 +- lib_enc/init_enc_fx.c | 49 + lib_enc/ivas_core_enc.c | 369 ++++---- lib_enc/ivas_core_pre_proc.c | 22 +- lib_enc/ivas_core_pre_proc_front.c | 100 +- lib_enc/ivas_cpe_enc.c | 145 +-- lib_enc/ivas_front_vad.c | 274 ++---- lib_enc/ivas_ism_enc.c | 71 +- lib_enc/ivas_sce_enc.c | 41 +- lib_enc/ivas_spar_encoder.c | 4 - lib_enc/ivas_spar_md_enc.c | 4 +- lib_enc/ivas_stat_enc.h | 42 +- lib_enc/ivas_stereo_dft_enc.c | 279 ++---- lib_enc/ivas_stereo_dft_enc_itd.c | 28 +- lib_enc/ivas_stereo_icbwe_enc.c | 2 +- lib_enc/ivas_stereo_mdct_stereo_enc.c | 18 +- lib_enc/ivas_stereo_switching_enc.c | 198 ++-- lib_enc/ivas_stereo_td_enc.c | 9 - lib_enc/ivas_tcx_core_enc.c | 73 +- lib_enc/nois_est_fx.c | 19 +- lib_enc/prot_fx_enc.h | 10 + lib_enc/speech_music_classif.c | 56 -- lib_enc/speech_music_classif_fx.c | 2 + lib_enc/stat_enc.h | 94 +- lib_enc/swb_bwe_enc.c | 2 + lib_enc/swb_bwe_enc_fx.c | 4 + lib_enc/swb_tbe_enc.c | 119 +-- lib_enc/swb_tbe_enc_fx.c | 35 +- 51 files changed, 2403 insertions(+), 1577 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index ef9e41faf..718ee3ac5 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -751,6 +751,7 @@ enum #define E_MIN_Q11_FX 7 /* minimum allowable energy in Q11*/ #define E_MIN 0.0035f /* minimum allowable energy */ #define E_MIN_Q11_FX 7 /* minimum allowable energy in Q11*/ +#define E_MIN_Q16_FX 229 /* minimum allowable energy in Q16*/ #define STEP_DELTA 0.0625f /* quantization step for tilt compensation of gaussian cb. excitation */ #define GAMMA_EV 0.92f /* weighting factor for core synthesis error weighting */ #define FORMANT_SHARPENING_NOISE_THRESHOLD 21.0f /* lp_noise level above which formant sharpening is deactivated */ diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index a87ab8e40..8a0c058aa 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -1257,6 +1257,7 @@ Word16 getTcxLpcShapedAri( } +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * init_tcx_window_cfg() * @@ -1362,6 +1363,7 @@ void init_tcx_window_cfg( return; } +#endif /*-----------------------------------------------------------------------* * init_tcx() @@ -1369,6 +1371,7 @@ void init_tcx_window_cfg( * Initialization of TCX *-----------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void init_tcx_cfg( TCX_CONFIG_HANDLE hTcxCfg, const int32_t total_brate, @@ -1405,22 +1408,14 @@ void init_tcx_cfg( init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); /* SQ deadzone & memory quantization*/ -#ifndef IVAS_FLOAT_FIXED hTcxCfg->sq_rounding_flt = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ -#else - hTcxCfg->sq_rounding = 12288; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ -#endif /* TCX rate loop */ hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0; hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt; /* TCX bandwidth */ -#ifndef IVAS_FLOAT_FIXED hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( bwidth ); -#else - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); -#endif /* set number of coded lines */ hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); @@ -1464,11 +1459,7 @@ void init_tcx_cfg( } /* Scale TCX for non-active frames to adjust loudness with ACELP*/ -#ifndef IVAS_FLOAT_FIXED hTcxCfg->na_scale_flt = 1.f; -#else - hTcxCfg->na_scale = 32767; -#endif if ( na_scale_bwidth < SWB && !tcxonly ) { @@ -1482,11 +1473,7 @@ void init_tcx_cfg( { i--; } -#ifndef IVAS_FLOAT_FIXED hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt; -#else - hTcxCfg->na_scale = scaleTcxTable[i].scale; -#endif break; } } @@ -1503,8 +1490,7 @@ void init_tcx_cfg( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void init_tcx_cfg_ivas_fx( TCX_CONFIG_HANDLE hTcxCfg, const Word32 total_brate, /*Q0*/ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 4aec876ef..48ea0c2b2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -236,7 +236,7 @@ ivas_error pre_proc_front_ivas_fx( 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 */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ 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 */ @@ -254,9 +254,10 @@ ivas_error pre_proc_front_ivas_fx( 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 */ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ + Word16 *fft_buff_fx_q, /* 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 */ @@ -285,13 +286,13 @@ ivas_error pre_proc_ivas( Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float **inp, /* o : ptr. to inp. signal in the current frame*/ - float *ener, /* o : residual energy from Levinson-Durbin */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q6 */ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ float epsP[M + 1], /* i/o: LP prediction errors */ Word16 lsp_new[M], /* i/o: LSPs at the end of the frame */ Word16 lsp_mid[M], /* i/o: LSPs in the middle of the frame */ - float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ float old_wsp[], /* i : weighted input signal buffer */ const int16_t loc_harm, /* i : harmonicity flag */ @@ -525,7 +526,7 @@ ivas_error ivas_core_enc( const int16_t n_CoreChannels, /* i : number of core channels to be coded */ float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */ float old_inp_16k[][L_INP], /* i : buffer of old input signal */ - float ener[], /* i : residual energy from Levinson-Durbin */ + Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6*/ Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes*/ float epsP[][M + 1], /* i : LP prediction errors */ @@ -533,14 +534,16 @@ ivas_error ivas_core_enc( Word16 lsp_mid[][M], /* i : LSPs in the middle of the frame Q15 */ const int16_t vad_hover_flag[], /* i : VAD hanglover flag */ int16_t attack_flag[], /* i : attack flag (GSC or TC) */ - float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ - float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + Word16 q_re_im_buf, float old_wsp[][L_WSP], /* i : weighted input signal buffer */ const int16_t loc_harm[], /* i : harmonicity flag */ const Word16 cor_map_sum[], /* i : speech/music clasif. parameter Q8 */ const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ - float enerBuffer[][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ - float fft_buff[][2 * L_FFT], /* i : FFT buffer */ + Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + Word16 enerBuffer_fx_exp[], /* o : energy buffer */ + Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer */ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ const int16_t ivas_format, /* i : IVAS format */ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ @@ -1390,6 +1393,7 @@ void ivas_ism_dtx_limit_noise_energy_for_near_silence( * DFT Stereo prototypes *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error stereo_dft_enc_create( STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* o : encoder DFT stereo handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -1404,16 +1408,15 @@ void stereo_enc_itd_init( ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ ); -#ifndef IVAS_FLOAT_FIXED void stereo_dft_enc_update( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ const int16_t max_bwidth /* i : maximum encoded bandwidth */ ); -#endif void stereo_dft_enc_destroy( STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle */ ); +#endif void stereo_dft_enc_analyze( Encoder_State **sts, /* i/o: encoder state structure */ @@ -1816,6 +1819,12 @@ int16_t read_BS_adapt_GR_sg( int16_t *GR_ord, /* o : GR order to be used */ const int16_t *map0 /* i : mapping array for side gains */ ); + +void stereo_dft_hybrid_ITD_flag( + STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ + const int32_t input_Fs, /* i : CPE element sampling rate */ + const int16_t hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ +); #endif void stereo_dft_enc_compute_itd( @@ -4643,11 +4652,13 @@ void ivas_spar_dec_upmixer( ); /* MD module */ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_open( ivas_spar_md_enc_state_t **hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ const int16_t sba_order /* i : Ambisonic (SBA) order */ ); +#endif void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 788d2353b..c477b0baf 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1395,6 +1395,15 @@ void stereo_tdm_downmix_ivas_fx( const Word16 tdm_ratio_idx_SM /* i : TDM ratio index for SM mode */ ); +ivas_error initMdctItdHandling_fx( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const Word32 input_Fs /* i : input sampling rate */ +); + +void stereo_mdct_enc_destroy_fx( + STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */ +); + void stereo_mdct_init_bands_fx( const Word16 L_frame, /* i : frame length */ const Word16 tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame */ @@ -4244,6 +4253,10 @@ void stereo_dft_enc_update_fx( const Word16 max_bwidth /* i : maximum encoded bandwidth */ ); +void stereo_dft_enc_destroy_fx( + STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle */ +); + void stereo_dft_quantize_res_gains_fx( const Word32 *g, // Q31 const Word32 *r, // Q31 @@ -4337,7 +4350,7 @@ Word16 write_bitstream_GR( const Word16 GR_ord /* i : GR order */ ); -void stereo_dft_hybrid_ITD_flag( +void stereo_dft_hybrid_ITD_flag_fx( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ const Word32 input_Fs, /* i : CPE element sampling rate */ const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ @@ -5838,7 +5851,7 @@ ivas_error ivas_compute_core_buffers_fx( const Word16 input_frame, /* i : frame length */ const Word16 last_element_mode, /* i : last element mode */ const Word32 sr_core, /* i : core-coder sampling rate */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ Word32 epsP[M + 1], /* i/o: LP prediction errors */ diff --git a/lib_com/lerp.c b/lib_com/lerp.c index 96c130491..ed2ee211c 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -496,7 +496,7 @@ void L_lerp_fx( Word32 *f /*q*/, Word32 *f_out /*q*/, Word16 bufferNewSize /*Q0* IF( LT_16( getScaleFactor32( f, bufferOldSize ), guard_bits ) ) { *q = sub( *q, guard_bits ); - FOR( Word16 ind = 0; ind < bufferNewSize; ind++ ) + FOR( Word16 ind = 0; ind < bufferOldSize; ind++ ) { f[ind] = L_shr( f[ind], guard_bits ); /*Q(guard_bits)*/ move32(); diff --git a/lib_com/prot.h b/lib_com/prot.h index 17abc65e8..f7bc0463b 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -5996,9 +5996,11 @@ float env_stab_smo( ); void core_switching_pre_enc( - Encoder_State *st, /* i/o: encoder state structure */ - const float *old_inp_12k8, /* i : old input signal @12.8kHz */ - const float *old_inp_16k, /* i : old input signal @16kHz */ + Encoder_State *st, /* i/o: encoder state structure */ +#ifndef IVAS_FLOAT_FIXED + const float *old_inp_12k8, /* i : old input signal @12.8kHz */ + const float *old_inp_16k, /* i : old input signal @16kHz */ +#endif const int16_t active_cnt, /* i : Active frame counter */ const int16_t last_element_mode /* i : last_element_mode */ ); @@ -7712,6 +7714,7 @@ int16_t tcx_ari_res_invQ_spec_flt( const float x_fac[] /* i : spectrum post-quantization factors */ ); +#ifndef IVAS_FLOAT_FIXED int16_t tcx_res_Q_gain( float sqGain, float *gain_tcx, @@ -7760,6 +7763,7 @@ void SetTnsConfig_flt( TCX_CONFIG_HANDLE hTcxCfg, const int16_t isTCX20, const int16_t isAfterACELP ); +#endif void ari_copy_states( Tastat *source, diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 64650f629..2c3a6d593 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2382,7 +2382,7 @@ void Syn_filt_s( const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ ); -#ifndef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED void syn_filt_fx( const Word16 shift, /* i : scaling to apply Q0 */ const Word16 a[], /* i : LP filter coefficients Q12 */ @@ -2883,7 +2883,8 @@ void PostShortTerm_fx( const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); -void PostShortTerm_ivas_fx( +#ifdef IVAS_FLOAT_FIXED +void PostShortTerm_ivas_enc_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -2894,6 +2895,18 @@ void PostShortTerm_ivas_fx( const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); +void PostShortTerm_ivas_dec_fx( + Word16 *sig_in, /* i : i signal (pointer to current subframe */ + Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ + Word16 *sig_out, /* o : postfiltered output */ + Word16 *mem_stp, /* i/o: postfilter memory*/ + Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ + Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ + Word16 *mem_zero, /* i/o: null memory to compute h_st*/ + const Word16 formant_fac_fx /* i : Strength of post-filter*/ +); +#endif + void flip_spectrum_and_decimby4_fx( const Word16 i[], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ @@ -2972,7 +2985,8 @@ void GenShapedSHBExcitation_fx( #endif ); -void GenShapedSHBExcitation_ivas_fx( +#ifdef IVAS_FLOAT_FIXED +void GenShapedSHBExcitation_ivas_enc_fx( Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ @@ -3017,6 +3031,52 @@ void GenShapedSHBExcitation_ivas_fx( #endif ); +void GenShapedSHBExcitation_ivas_dec_fx( + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32 *mem_csfilt, /* i/o: memory */ + Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ + Word16 *state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16 *tbe_demph, /* i/o: de-emphasis memory */ + Word16 *tbe_premph, /* i/o: pre-emphasis memory */ + Word16 *lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *shb_res, + Word16 *vf_ind, + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + Word16 *Q_bwe_exc, + Word16 *Q_bwe_exc_fb, + const Word16 Q_shb, + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + const Word32 bitrate, + const Word16 prev_bfi +#if 1 // def ADD_IVAS_TBE_CODE + , /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ +#endif +); +#endif + void GenSHBSynth_fx( const Word16 *shb_target_speech, /* i : i synthesized speech */ Word16 *shb_syn_speech_32k, /* o : output highband component */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 2bdba82b2..ae26bea01 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -58,8 +58,8 @@ typedef struct float a[MAXLAG_WI]; float b[MAXLAG_WI]; #else - Word16 a_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ - Word16 b_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ + Word16 a_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ + Word16 b_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ #endif Word16 lag; Word16 nH; @@ -73,8 +73,8 @@ typedef struct float upper_cut_off_freq_of_interest; float upper_cut_off_freq; #else - Word16 upper_cut_off_freq_of_interest_fx; /* Q0 */ - Word16 upper_cut_off_freq_fx; /* Q0 */ + Word16 upper_cut_off_freq_of_interest_fx; /* Q0 */ + Word16 upper_cut_off_freq_fx; /* Q0 */ #endif Word32 sampling_rate; Word16 Fs_fx; /* Q0 */ @@ -138,8 +138,8 @@ typedef struct float formant_enh_num_flt; float formant_enh_den_flt; #else - Word16 formant_enh_num; /* Q15 */ - Word16 formant_enh_den; /* Q15 */ + Word16 formant_enh_num; /* Q15 */ + Word16 formant_enh_den; /* Q15 */ #endif Word16 bpf_mode; @@ -211,8 +211,8 @@ typedef struct TNS_filter_structure float predictionGain_flt; /* Prediction gain. The ratio of a signal and TNS residual energy. */ float avgSqrCoef_flt; /* Average squared filter coefficient. */ #else - Word16 predictionGain; /* Prediction gain. The ratio of a signal and TNS residual energy. E(PRED_GAIN_E), Q7 */ - Word16 avgSqrCoef; /* Average squared filter coefficient. E(0), Q15 */ + Word16 predictionGain; /* Prediction gain. The ratio of a signal and TNS residual energy. E(PRED_GAIN_E), Q7 */ + Word16 avgSqrCoef; /* Average squared filter coefficient. E(0), Q15 */ #endif } STnsFilter; @@ -245,23 +245,28 @@ typedef struct typedef struct TCX_config_structure { /* TCX mdct window */ +#ifndef IVAS_FLOAT_FIXED float tcx_mdct_window_flt[L_MDCT_OVLP_MAX_CORE_FS]; /* Sine window for OL decision and DTX transitions*/ float tcx_aldo_window_1_flt[L_ALDO_WIN1_MAX_CORE_FS]; /* ALDO window long slope */ float tcx_aldo_window_2_flt[L_MDCT_OVLP_MAX_CORE_FS]; /* ALDO window short slope */ float *tcx_aldo_window_1_trunc_flt; /* ALDO window truncated long slope */ - PWord16 tcx_mdct_window[L_MDCT_OVLP_MAX_CORE_FS]; - PWord16 tcx_mdct_window_half[L_MDCT_HALF_OVLP_MAX_CORE_FS]; - PWord16 tcx_mdct_window_minimum[L_MDCT_MIN_OVLP_MAX_CORE_FS]; - PWord16 tcx_mdct_window_trans[L_MDCT_MIN_OVLP_MAX_CORE_FS]; - Word16 tcx_aldo_window_1[L_FRAME32k * 9 / 32]; /*Q15*/ - PWord16 tcx_aldo_window_1_trunc[L_FRAME32k * 7 / 32]; - PWord16 tcx_aldo_window_2[L_FRAME32k * 7 / 32]; - +#else + PWord16 tcx_mdct_window[L_MDCT_OVLP_MAX_CORE_FS]; /* Sine window for OL decision and DTX transitions*/ + Word16 tcx_aldo_window_1[L_FRAME32k * 9 / 32]; /* ALDO window long slope Q15 */ + PWord16 tcx_aldo_window_2[L_FRAME32k * 7 / 32]; /* ALDO window short slope */ + PWord16 tcx_aldo_window_1_trunc[L_FRAME32k * 7 / 32]; /* ALDO window truncated long slope */ +#endif Word16 last_aldo; +#ifndef IVAS_FLOAT_FIXED float tcx_mdct_window_half_flt[L_MDCT_HALF_OVLP_MAX_CORE_FS]; float tcx_mdct_window_minimum_flt[L_MDCT_MIN_OVLP_MAX_CORE_FS]; float tcx_mdct_window_trans_flt[L_MDCT_MIN_OVLP_MAX_CORE_FS]; /* transition window for ACELP->TCX */ +#else + PWord16 tcx_mdct_window_half[L_MDCT_HALF_OVLP_MAX_CORE_FS]; + PWord16 tcx_mdct_window_minimum[L_MDCT_MIN_OVLP_MAX_CORE_FS]; + PWord16 tcx_mdct_window_trans[L_MDCT_MIN_OVLP_MAX_CORE_FS]; /* transition window for ACELP->TCX */ +#endif Word16 tcx5Size; /* Size of the TCX5 spectrum in number of samples. Always 5ms. */ @@ -276,23 +281,27 @@ typedef struct TCX_config_structure Word16 tcx_mdct_window_delay; /* length of window delay */ Word16 tcx_offset; /* Offset of the folding point relative to the end of the previous synthetised frame */ Word16 tcx_mdct_window_length_old; /* for keeping old value for sample rate switching */ +#ifndef IVAS_FLOAT_FIXED float tcx_mdct_windowFB_flt[L_MDCT_OVLP_MAX]; float tcx_aldo_window_1_FB_flt[L_ALDO_WIN1_FB_MAX]; /* ALDO window long slope */ float tcx_aldo_window_2_FB_flt[L_MDCT_OVLP_MAX]; /* ALDO window short slope */ float *tcx_aldo_window_1_FB_trunc_flt; /* ALDO window truncated long slope */ +#else + PWord16 tcx_mdct_windowFB[L_MDCT_OVLP_MAX]; + Word16 tcx_aldo_window_1_FB[L_FRAME_MAX * 9 / 32]; /* ALDO window long slope Q15 */ + PWord16 tcx_aldo_window_2_FB[L_FRAME_MAX * 7 / 32]; /* ALDO window short slope */ + PWord16 tcx_aldo_window_1_FB_trunc[L_FRAME_MAX * 7 / 32]; /* ALDO window truncated long slope */ +#endif +#ifndef IVAS_FLOAT_FIXED float tcx_mdct_window_halfFB_flt[L_MDCT_HALF_OVLP_MAX]; float tcx_mdct_window_minimumFB_flt[L_MDCT_MIN_OVLP_MAX]; float tcx_mdct_window_transFB_flt[L_MDCT_TRANS_OVLP_MAX]; /* transition window for ACELP->TCX */ - - /* TCX mdct window */ - PWord16 tcx_mdct_windowFB[L_MDCT_OVLP_MAX]; +#else PWord16 tcx_mdct_window_halfFB[L_MDCT_HALF_OVLP_MAX]; PWord16 tcx_mdct_window_minimumFB[L_MDCT_MIN_OVLP_MAX]; - PWord16 tcx_mdct_window_transFB[L_MDCT_TRANS_OVLP_MAX]; - Word16 tcx_aldo_window_1_FB[L_FRAME_MAX * 9 / 32]; /*Q15*/ - PWord16 tcx_aldo_window_1_FB_trunc[L_FRAME_MAX * 7 / 32]; - PWord16 tcx_aldo_window_2_FB[L_FRAME_MAX * 7 / 32]; + PWord16 tcx_mdct_window_transFB[L_MDCT_TRANS_OVLP_MAX]; /* transition window for ACELP->TCX */ +#endif Word16 tcx5SizeFB; /* Size of the TCX5 spectrum in number of samples. Always 5ms. */ @@ -319,17 +328,17 @@ typedef struct TCX_config_structure #ifndef IVAS_FLOAT_FIXED float sq_rounding_flt; /* set the sq deadzone (no deadzone=0.5f) */ #else - Word16 sq_rounding; /* set the sq deadzone (no deadzone=0.5f) Q15 */ + Word16 sq_rounding; /* set the sq deadzone (no deadzone=0.5f) Q15 */ #endif Word16 tcxRateLoopOpt; /*Bandwidth*/ - float preemph_fac_flt; /* preemphasis factor */ - Word16 preemph_fac; /* preemphasis factor Q15 */ #ifndef IVAS_FLOAT_FIXED + float preemph_fac_flt; /* preemphasis factor */ float bandwidth_flt; #else - Word16 bandwidth; /* Q15 */ + Word16 preemph_fac; /* preemphasis factor Q15 */ + Word16 bandwidth; /* Q15 */ #endif /* Context HM - Residual Quantization*/ @@ -340,13 +349,13 @@ typedef struct TCX_config_structure #ifndef IVAS_FLOAT_FIXED float na_scale_flt; #else - Word16 na_scale; /* Q15 */ + Word16 na_scale; /* Q15 */ #endif #ifndef IVAS_FLOAT_FIXED float SFM2_flt; #else - Word32 SFM2; /* Q31 */ + Word32 SFM2; /* Q31 */ #endif /* Psychoacoustic parameters for LPC in TCX */ @@ -397,8 +406,8 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float scale_flt; #else - Word16 scale; /* EVS implementation Q14 */ - Word16 scale_ivas; /* IVAS implementation Q14 */ + Word16 scale; /* EVS implementation Q14 */ + Word16 scale_ivas; /* IVAS implementation Q14 */ #endif } SCALE_SETUP; @@ -686,7 +695,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float scale_flt; #else - Word16 scale; /* Q15 */ + Word16 scale; /* Q15 */ #endif } SCALE_TCX_SETUP; @@ -733,8 +742,8 @@ typedef struct cldfb_filter_bank_struct const float *rot_vec_syn_re; const float *rot_vec_syn_im; #else - const Word32 *rot_vec_syn_re_fx; // Q29 - const Word32 *rot_vec_syn_im_fx; // Q29 + const Word32 *rot_vec_syn_re_fx; // Q29 + const Word32 *rot_vec_syn_im_fx; // Q29 const Word32 *rot_vec_syn_delay_re_fx; // Q31 const Word32 *rot_vec_syn_delay_im_fx; // Q31 diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index b95ee921b..fcdb9f10d 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -854,7 +854,48 @@ static void Calc_st_filt_tbe( } } -static void Calc_st_filt_tbe_ivas_fx( +#ifdef IVAS_FLOAT_FIXED +static void Calc_st_filt_tbe_ivas_enc_fx( + Word16 *apond2, /* i : coefficients of numerator */ + Word16 *apond1, /* i : coefficients of denominator */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *mem_zero /* i : All zero memory */ +) +{ + Word32 L_g0; + + Word16 h[LONG_H_ST]; + + Word16 g0, temp; + Word16 i; + temp = sub( 2, norm_s( apond2[0] ) ); + /* compute i.r. of composed filter apond2 / apond1 */ + syn_filt_fx( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + /* compute 1st parcor */ + Calc_rc0_h( h, parcor0 ); + + /* compute g0 */ + L_g0 = L_mult0( 1, abs_s( h[0] ) ); + FOR( i = 1; i < LONG_H_ST; i++ ) + { + L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); + } + g0 = extract_h( L_shl( L_g0, 14 ) ); + + /* Scale signal i of 1/A(gamma1) */ + IF( GT_16( g0, 1024 ) ) + { + temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + FOR( i = 0; i < L_SUBFR16k; i++ ) + { + sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); + move16(); + } + } +} + +static void Calc_st_filt_tbe_ivas_dec_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ @@ -893,6 +934,7 @@ static void Calc_st_filt_tbe_ivas_fx( } } } +#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ @@ -1127,7 +1169,68 @@ void PostShortTerm_fx( return; } -void PostShortTerm_ivas_fx( +#ifdef IVAS_FLOAT_FIXED +void PostShortTerm_ivas_enc_fx( + Word16 *sig_in, /* i : input signal (pointer to current subframe */ + Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ + Word16 *sig_out, /* o : postfiltered output */ + Word16 *mem_stp, /* i/o: postfilter memory*/ + Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ + Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ + Word16 *mem_zero, /* i/o: null memory to compute h_st*/ + const Word16 formant_fac_fx /* i : Strength of post-filter*/ +) +{ + Word16 apond1_fx[LPC_SHB_ORDER + 1]; /* denominator coeff.*/ + Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ + Word16 sig_ltp_fx[L_SUBFR16k + 1]; /* residual signal */ + /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */ + Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ + Word16 tmp; + + parcor0_fx = 0; + move16(); + set16_fx( apond1_fx, 0, LPC_SHB_ORDER + 1 ); + set16_fx( apond2_fx, 0, LONG_H_ST ); + set16_fx( sig_ltp_fx, 0, L_SUBFR16k + 1 ); + + /* Obtain post-filter weights */ + tmp = extract_h( L_mult( GAMMA_SHARP_FX, formant_fac_fx ) ); /*Q15 */ + g1_fx = add( GAMMA0_FX, tmp ); /*Q15 */ + g2_fx = sub( GAMMA0_FX, tmp ); /*Q15 */ + + /* Compute weighted LPC coefficients */ + weight_a_fx( lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER ); + weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); + /* o: apond1_fx, apond2_fx in Q12 */ + + /* Compute A(gamma2) residual */ + Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); + /* o: sig_ltp_fx in Q_bwe_exc */ + + /* Save last output of 1/A(gamma1) */ + sig_ltp_fx[0] = *ptr_mem_stp; + move16(); + + /* Control short term pst filter gain and compute parcor0 */ + Calc_st_filt_tbe_ivas_enc_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); + /* o: parcor0 in Q15 */ + /* i/o: sig_ltp_fx in Q_bwe_exc */ + + /* 1/A(gamma1) filtering, mem_stp is updated */ + syn_filt_fx( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); + + /* (1 + mu z-1) tilt filtering */ + filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); + /* o: sig_out in Q_bwe_exc */ + + /* gain control */ + scale_st_swb( sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); + + return; +} + +void PostShortTerm_ivas_dec_fx( Word16 *sig_in, /* i : input signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -1170,7 +1273,7 @@ void PostShortTerm_ivas_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe_ivas_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); + Calc_st_filt_tbe_ivas_dec_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ @@ -1186,6 +1289,7 @@ void PostShortTerm_ivas_fx( return; } +#endif void flip_spectrum_and_decimby4_fx( const Word16 input[], /* i : input spectrum Q_inp */ @@ -2864,7 +2968,8 @@ void GenShapedSHBExcitation_fx( return; } -void GenShapedSHBExcitation_ivas_fx( +#ifdef IVAS_FLOAT_FIXED +void GenShapedSHBExcitation_ivas_enc_fx( Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ @@ -3828,7 +3933,7 @@ void GenShapedSHBExcitation_ivas_fx( IF( LT_32( bitrate, ACELP_24k40 ) ) #endif { - Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); + syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); /* i: exc16kWhtnd in Q_bwe_exc */ /* o: excSHB in Q_bwe_exc */ } @@ -3836,7 +3941,7 @@ void GenShapedSHBExcitation_ivas_fx( { set16_fx( zero_mem, 0, LPC_SHB_ORDER ); - Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); + syn_filt_fx( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3844,7 +3949,7 @@ void GenShapedSHBExcitation_ivas_fx( syn_shb_ener_sf_q[0] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); move16(); - Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); + syn_filt_fx( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3852,7 +3957,7 @@ void GenShapedSHBExcitation_ivas_fx( syn_shb_ener_sf_q[1] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); move16(); - Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); + syn_filt_fx( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3860,7 +3965,7 @@ void GenShapedSHBExcitation_ivas_fx( syn_shb_ener_sf_q[2] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); move16(); - Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); + syn_filt_fx( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3923,10 +4028,10 @@ void GenShapedSHBExcitation_ivas_fx( } /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); + syn_filt_fx( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); + syn_filt_fx( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); + syn_filt_fx( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); + syn_filt_fx( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); /* i: exc16kWhtnd in (Q_bwe_exc) */ /* o: excSHB in (Q_bwe_exc) */ } @@ -3936,7 +4041,7 @@ void GenShapedSHBExcitation_ivas_fx( tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); Scale_sig( fb_tbe_demph, 1, tmp ); - Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); + syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); /* i: White_exc16k_FB in (14-n2) */ /* o: White_exc16k_FB_temp in (14-n2) */ @@ -3971,6 +4076,1114 @@ void GenShapedSHBExcitation_ivas_fx( return; } +void GenShapedSHBExcitation_ivas_dec_fx( + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32 *mem_csfilt, /* i/o: memory */ + Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ + Word16 *state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16 *tbe_demph, /* i/o: de-emphasis memory */ + Word16 *tbe_premph, /* i/o: pre-emphasis memory */ + Word16 *lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *shb_res, + Word16 *vf_ind, + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + Word16 *Q_bwe_exc, + Word16 *Q_bwe_exc_fb, + const Word16 Q_shb, + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + const Word32 bitrate, /* i : bitrate */ + const Word16 prev_bfi, /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling Q0 */ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling Q0 */ +) +{ + Word16 i, j, k; + Word16 wht_fil_mem[LPC_WHTN_ORDER]; + Word16 lpc_whtn[LPC_WHTN_ORDER + 1]; + Word16 R_h[LPC_WHTN_ORDER + 2]; /* Autocorrelations of windowed speech MSB */ + Word16 R_l[LPC_WHTN_ORDER + 2]; /* Autocorrelations of windowed speech LSB */ + Word16 Q_R; + Word32 LepsP[LPC_WHTN_ORDER + 1]; + Word16 exc32k[L_FRAME32k], exc16k[L_FRAME16k]; + Word32 pow1, pow22; + Word16 scale, temp1, temp2, temp3; + + Word16 excTmp2[L_FRAME16k]; + Word16 *White_exc16k; + Word16 excNoisyEnv[L_FRAME16k]; + Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ + move16(); + Word16 neg_csfilt_den2[2] = { -32767, 26214 }; /* {1.0f, -0.8f} */ + move16(); + move16(); + Word16 varEnvShape; + Word16 fb_deemph_fac = 15729; /*0.48f in Q15 */ + Word16 exc16kWhtnd[L_FRAME16k]; + + Word32 L_tmp; + Word16 vf_tmp; + Word16 tmp, exp, tmp2 = 0; + move16(); + Word16 voiceFacEst[NB_SUBFR16k]; + Word16 zero_mem[LPC_SHB_ORDER]; + Word32 syn_shb_ener_sf[4]; + Word16 syn_shb_ener_sf_q[4]; + Word16 tempSHB[80]; + Word16 Q_pow1, Q_pow22; + + Word32 L_tmp2, L_tmp3, L_tmp4; + Word16 temp; + + Word16 White_exc16k_FB_temp[L_FRAME16k]; + Word32 White_exc16k_32[L_FRAME16k]; + Word16 White_exc16k_tmp[L_FRAME16k]; + Word16 Q_temp; + Word16 prev_Q_bwe_exc_fb; + Word16 chk1, chk2; + chk1 = 0; + chk2 = 0; + move16(); + move16(); + +#if 1 // def ADD_IVAS_TBE_CODE + Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; + Word16 cbsize; + Word16 mix_factor, old_fact, new_fact, fact, old_scale, new_scale, step_scale; + Word32 c0, c1, c2, c3, c4, c5, den; + Word16 g1, g2, g, g1_e, g2_e, g_e, den_e, shift, tmp_e, tmp1_e; + Word16 EnvWhiteExc16k[L_FRAME16k], EnvExc16kWhtnd[L_FRAME16k]; + Word16 EnvWhiteExc16k_4k[L_FRAME4k] = { 0 }, EnvExc16kWhtnd_4k[L_FRAME4k] = { 0 }; + Word16 flag_plosive; + Word16 delta; + Word32 c0_part[NUM_SHB_SUBGAINS], c1_part[NUM_SHB_SUBGAINS], c2_part[NUM_SHB_SUBGAINS], c3_part[NUM_SHB_SUBGAINS], c4_part[NUM_SHB_SUBGAINS], c5_part[NUM_SHB_SUBGAINS]; + Word64 W_tmp; + + mix_factor = 0; /* Q15 */ + move16(); +#endif + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); + set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); + FOR( i = 0; i < L_FRAME32k; i = i + 2 ) + { + exc32k[i] = negate( bwe_exc_extended[i] ); // Q_bwe_exc + move16(); + exc32k[i + 1] = bwe_exc_extended[i + 1]; // Q_bwe_exc + move16(); + } + + /* Decimate by 2 */ + Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2 * L_FRAME16k, exc16k ); // Q_bwe_exc + /* i: exc32k in Q_bwe_exc */ + /* o: exc16k in Q_bwe_exc */ + + autocorr_fx( exc16k, LPC_WHTN_ORDER + 1, R_h, R_l, &Q_R, L_FRAME16k, win_flatten_fx, 0, 1 ); // Q_R + /* Ensure R[0] isn't zero when entering Levinson Durbin */ + R_l[0] = s_max( R_l[0], 1 ); + move16(); + FOR( i = 1; i <= LPC_WHTN_ORDER; i++ ) + { + L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); + L_Extract( L_tmp, &R_h[i], &R_l[i] ); // Q_R + } + E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); + Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); // Q12 + fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); // Q_bwe_exc + + /* i: exc16k in Q_bwe_exc */ + /* o: exc16kWhtnd in Q_bwe_exc */ + +#if 1 // def ADD_IVAS_TBE_CODE + IF( GE_32( extl_brate, SWB_TBE_2k8 ) ) +#else + IF( GE_32( bitrate, ACELP_24k40 ) ) +#endif + { + temp2 = 0; + move16(); + FOR( j = 0; j < 4; j++ ) + { + temp1 = shb_res_gshape[j]; + move16(); + FOR( i = 0; i < 80; i++ ) + { + exc16kWhtnd[temp2 + i] = round_fx( L_shl( L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1 ) ); // Q_bwe_exc + move16(); + /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */ + } + temp2 = add( temp2, 80 ); + } + } + + /* Estimate pow1 associated with Low band nonlinear extended excitation */ + /* pow1=0.00001f */ + tmp = sub( shl( *Q_bwe_exc, 1 ), 31 ); +#ifdef BASOP_NOGLOB + pow1 = L_shl_sat( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ +#else + pow1 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ +#endif + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ + excTmp2[k] = abs_s( exc16kWhtnd[k] ); + move16(); + chk1 = s_or( chk1, exc16kWhtnd[k] ); + + /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ +#ifdef BASOP_NOGLOB + pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ +#else + pow1 = L_mac0( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ +#endif + } + Q_pow1 = shl( *Q_bwe_exc, 1 ); + + test(); +#if 1 // ADD_IVAS_TBE_CODE + IF( flag_ACELP16k == 0 ) +#else + IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) ) +#endif + { + /* varEnvShape = mean_fx(voice_factors, 4); */ + /* unroll the loop */ + L_tmp = L_mult( voice_factors[0], 8192 /*0.25 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 /*0.25 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 /*0.25 in Q15 */ ); + varEnvShape = mac_r( L_tmp, voice_factors[3], 8192 /*0.25 in Q15 */ ); /* varEnvShape in Q15 */ + } + ELSE /* 16k core */ + { + /* varEnvShape = mean_fx(voice_factors, 5); */ + /* unroll the loop */ + L_tmp = L_mult( voice_factors[0], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[1], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[2], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[3], 6554 /*0.2 in Q15 */ ); + varEnvShape = mac_r( L_tmp, voice_factors[4], 6554 /*0.2 in Q15 */ ); /* varEnvShape in Q15 */ + } + + IF( EQ_16( extl, FB_TBE ) ) + { + /*pow(varEnvShape,3) */ + tmp = mult_r( varEnvShape, varEnvShape ); + tmp = mult_r( tmp, varEnvShape ); + + /* max_val((0.68f - (float)pow(varEnvShape, 3)), 0.48f); */ + fb_deemph_fac = sub( 22282 /*0.68f Q15*/, tmp ); + fb_deemph_fac = s_max( fb_deemph_fac, 15729 /*0.48f Q15*/ ); + } + + /*varEnvShape = 1.09875f - 0.49875f * varEnvShape; */ + varEnvShape = msu_r( 1179773824l /*0.549375f Q31*/, 8172 /*0.249375f Q15*/, varEnvShape ); + + /*varEnvShape = min( max_val(varEnvShape, 0.6f), 0.999f); */ + varEnvShape = s_max( varEnvShape, 9830 /*0.3f Q15*/ ); + varEnvShape = s_min( varEnvShape, 16368 /*0.4995f Q15*/ ); + varEnvShape = shl( varEnvShape, 1 ); + csfilt_num2[0] = sub( MAX_16, varEnvShape ); // Q15 + move16(); + neg_csfilt_den2[1] = varEnvShape; // Q15 + move16(); + + test(); + test(); + test(); +#if 1 // def ADD_IVAS_TBE_CODE + test(); + IF( EQ_16( element_mode, EVS_MONO ) && *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) +#else + IF( *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) +#endif + { + /* pre-init smoothing filter to avoid energy drop outs */ + L_tmp = L_mult( excTmp2[0], 1638 ); + FOR( i = 1; i < L_SUBFR16k / 4; i++ ) + { + L_tmp = L_mac( L_tmp, excTmp2[i], 1638 ); /*1638 = 1/20 in Q15*/ + } + /*L_tmp = sum(excTmp2, L_SUBFR16k/4)*(1/20) where L_SUBFR16k/4 =20 */ + + /* don't apply for FB in case the FB start-frame was potentially lost - White_exc16k is very sensitive to enery mismatch between enc - dec */ + /* rather stick to the more conservative approach, to avoid potential clippings */ + test(); + IF( !( prev_bfi && EQ_16( extl, FB_TBE ) ) ) + { + /* use weak smoothing for 1st frame after switching to make filter recover more quickly */ + varEnvShape = 26214 /*0.8f Q15*/; + move16(); + csfilt_num2[0] = sub( MAX_16, varEnvShape ); + move16(); + neg_csfilt_den2[1] = varEnvShape; + move16(); + } + + *mem_csfilt = Mult_32_16( L_tmp, varEnvShape ); + move32(); + } +#if 1 // def ADD_IVAS_TBE_CODE + IF( MSFlag > 0 ) + { + // varEnvShape = 0.995f; + varEnvShape = 32604; + move16(); + csfilt_num2[0] = 32768 - varEnvShape; + // csfilt_num2[0] = sub( 32767, varEnvShape ); + move16(); + neg_csfilt_den2[1] = varEnvShape; + move16(); + } + + White_exc16k = exc16k; + move16(); + Word16 Q_excTmp2 = add( getScaleFactor16( excTmp2, L_FRAME16k ), *Q_bwe_exc ); + IF( *mem_csfilt ) + { + Q_excTmp2 = s_min( Q_excTmp2, sub( add( norm_l( *mem_csfilt ), *Q_bwe_exc ), 1 ) ); + } + test(); + /* Track the low band envelope */ + IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + test(); + IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) + { + mem_csfilt_left = 0; + mem_csfilt_right = 0; + move16(); + move16(); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + // excNoisyEnvLeft[k] = mem_csfilt_left + csfilt_num2[0] * excTmp2[k]; + excNoisyEnvLeft[k] = add( mem_csfilt_left, mult_r( csfilt_num2[0], shl( excTmp2[k], sub( Q_excTmp2, *Q_bwe_exc ) ) ) ); // Q_excTmp2 + move16(); + // mem_csfilt_left = -csfilt_den2[1] * excNoisyEnvLeft[k]; + mem_csfilt_left = mult_r( neg_csfilt_den2[1], excNoisyEnvLeft[k] ); // Q_excTmp2 + // excNoisyEnvRight[L_FRAME16k - k - 1] = mem_csfilt_right + csfilt_num2[0] * excTmp2[L_FRAME16k - k - 1]; + excNoisyEnvRight[L_FRAME16k - k - 1] = add( mem_csfilt_right, mult_r( csfilt_num2[0], shl( excTmp2[L_FRAME16k - k - 1], sub( Q_excTmp2, *Q_bwe_exc ) ) ) ); // Q_excTmp2 + move16(); + // mem_csfilt_right = -csfilt_den2[1] * excNoisyEnvRight[L_FRAME16k - k - 1]; + mem_csfilt_right = mult_r( neg_csfilt_den2[1], excNoisyEnvRight[L_FRAME16k - k - 1] ); // Q_excTmp2 + } + + alpha = 0; + move16(); + // step = 1.0f / L_FRAME16k; + step = 102; // Q15 + move16(); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + // excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + (1 - alpha) * excNoisyEnvRight[k]; + excNoisyEnv[k] = add( mult_r( alpha, excNoisyEnvLeft[k] ), mult_r( sub( 32767, alpha ), excNoisyEnvRight[k] ) ); // Q_excTmp2 + move16(); + alpha = add( alpha, step ); + } + } + } + ELSE +#endif + { + /* Track the low band envelope */ + L_tmp = L_shl( *mem_csfilt, sub( Q_excTmp2, *Q_bwe_exc ) ); + move32(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], shl( excTmp2[i], sub( Q_excTmp2, *Q_bwe_exc ) ) ); + move16(); + /* Work-around to avoid 0s for very small value*/ + test(); + test(); + test(); + test(); + if ( excNoisyEnv[i] == 0 && ( L_tmp != 0 || ( csfilt_num2[0] != 0 && excTmp2[i] != 0 ) ) ) + { + excNoisyEnv[i] = 1; + move16(); + } + /* excNoisyEnv : Q_excTmp2, + *mem_csfilt: Q_excTmp2+16, excTmp2: Q_excTmp2, csfilt_num2[0] Q_excTmp2 */ + L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_excTmp2 + 16 */ + } + *mem_csfilt = L_shr( L_tmp, sub( Q_excTmp2, *Q_bwe_exc ) ); + move32(); + } +#if 1 // def ADD_IVAS_TBE_CODE + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) + { + /* generate gaussian (white) excitation */ + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k[k] = own_random( &bwe_seed[0] ); + move16(); + } + + /* normalize the amplitude of the gaussian excitation to that of the LB exc. */ + Word32 pow22_inv = POW_EXC16k_WHTND_FX_INV_SQRT; + move32(); + move32(); + pow22 = POW_EXC16k_WHTND_FX; + Q_pow22 = -6; + move16(); + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); + Word16 pow1_exp = sub( Q31, Q_pow1 ); + Word32 temp_pow = Sqrt32( pow1, &pow1_exp ); + temp_pow = L_shl( Mpy_32_32( temp_pow, pow22_inv ), pow1_exp ); + /*Word16 out_exp; + Word32 temp_pow1 = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &out_exp); + temp_pow1 = L_shl(temp_pow1, out_exp);*/ + // v_multc_fixed_16_16(White_exc16k, round_fx(temp_pow), White_exc16k, L_FRAME16k); + L_tmp = 0; + move32(); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k_32[k] = Mpy_32_16_1( temp_pow, White_exc16k[k] ); + move32(); + White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], sub( *Q_bwe_exc, NOISE_QADJ ) ) ); // Q_bwe_exc - NOISE_QADJ + move16(); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); + } + Q_temp = norm_l( L_tmp ); + IF( L_tmp == 0 ) + { + Q_temp = 31; + move16(); + } + } + ELSE +#endif + { + /* create a random excitation - Reuse exc16k memory */ + White_exc16k = exc16k; + move16(); + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); // Q5 + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); // Q5 + + L_tmp = L_deposit_l( 0 ); + tmp = add( *Q_bwe_exc, 1 ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + L_tmp4 = L_mult( excNoisyEnv[k], White_exc16k[k] ); /* (Q_excTmp2) +5 +1*/ + White_exc16k_32[k] = L_tmp4; /* (Q_excTmp2) +5 +1*/ + move32(); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); + } + Q_temp = norm_l( L_tmp ); + IF( L_tmp == 0 ) + { + Q_temp = 31; + move16(); + } + /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ + /* White_exc16k in Q6 */ + + /* calculate pow22 */ + /* pow22=0.00001f */ + tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); + pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /* White_exc16k[k] *= excNoisyEnv[k]; */ + White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], 1 ) ); // Q_excTmp2 + 5 + 1 - 15 ==> Q_excTmp2 - 9 + move16(); + chk2 = s_or( chk2, White_exc16k[k] ); + /* i: excNoisyEnv in (Q_excTmp2) */ + /* i: White_exc16k in Q6 */ + /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ + /* pow22 += White_exc16k[k] * White_exc16k[k]; */ +#ifdef BASOP_NOGLOB + pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2-NOISE_QADJ)*/ +#else + pow22 = L_mac0( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ +#endif + } + /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ + Q_pow22 = shl( sub( Q_excTmp2, NOISE_QADJ ), 1 ); + Scale_sig( White_exc16k, L_FRAME16k, sub( *Q_bwe_exc, Q_excTmp2 ) ); + } + +#if 1 // def ADD_IVAS_TBE_CODE + flag_plosive = 0; + move16(); + test(); + test(); + test(); + IF( GE_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) +#else + IF( GE_32( bitrate, ACELP_24k40 ) ) +#endif + { + IF( EQ_16( *vf_ind, 20 ) ) /* encoder side */ + { +#ifndef ADD_IVAS_TBE_CODE // BELOW PART WILL NEED TO BE CONVERTED FOR ENCODER!! + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) + { + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k_tmp[k] = round_fx( L_shl( White_exc16k_32[k], *Q_bwe_exc ) ); + move16(); + } + + /* calculate TD envelopes of exc16kWhtnd and White_exc16k */ + find_td_envelope_fx( White_exc16k_tmp, L_FRAME16k, 20, NULL, EnvWhiteExc16k ); /* Q_bwe_exc */ + find_td_envelope_fx( exc16kWhtnd, L_FRAME16k, 20, NULL, EnvExc16kWhtnd ); /* Q_bwe_exc */ + + FOR( k = 0; k < L_FRAME4k; k++ ) + { + EnvWhiteExc16k_4k[k] = EnvWhiteExc16k[4 * k]; /* Q_bwe_exc */ + move16(); + EnvExc16kWhtnd_4k[k] = EnvExc16kWhtnd[4 * k]; /* Q_bwe_exc */ + move16(); + } + + /* calculate the optimal mix factor */ + c0 = c1 = c2 = c3 = c4 = c5 = 0; /* Q0 */ + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + + temp1 = add( shl( *Q_bwe_exc, 1 ), 1 ); + temp2 = add( add( Q_shb, *Q_bwe_exc ), 1 ); + temp3 = add( shl( Q_shb, 1 ), 1 ); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + // c0_part[i] = sum2_f( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c0_part[i] = L_shr( sum2_fx( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ), temp1 ); /* Q0 */ + move32(); + // c1_part[i] = -2.0f * dotp( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c1_part[i] = L_shr( L_negate( Dot_product( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ) ), sub( temp2, 1 ) ); /* Q0 */ + move32(); + // c2_part[i] = sum2_f( &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c2_part[i] = L_shr( sum2_fx( &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ), temp1 ); /* Q0 */ + move32(); + // c3_part[i] = -2.0f * dotp( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c3_part[i] = L_shr( L_negate( Dot_product( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ) ), sub( temp2, 1 ) ); /* Q0 */ + move32(); + // c4_part[i] = 2.0f * dotp( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c4_part[i] = L_shr( Dot_product( &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ), sub( temp1, 1 ) ); /* Q0 */ + move32(); + // c5_part[i] = sum2_f( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ); + c5_part[i] = L_shr( sum2_fx( &EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS ), temp3 ); /* Q0 */ + move32(); + + c0 = L_add( c0, c0_part[i] ); + c1 = L_add( c1, c1_part[i] ); + c2 = L_add( c2, c2_part[i] ); + c3 = L_add( c3, c3_part[i] ); + c4 = L_add( c4, c4_part[i] ); + c5 = L_add( c5, c5_part[i] ); + } + + // den = 4.0f * c0 * c2 - c4 * c4; + W_tmp = W_sub( W_shl( W_mult0_32_32( c0, c2 ), 2 ), W_mult0_32_32( c4, c4 ) ); + den_e = 63; + move16(); + shift = W_norm( W_tmp ); + den = W_extract_h( W_shl( W_tmp, shift ) ); + den_e = sub( den_e, shift ); + + IF( den == 0 ) + { + den = 1; + move32(); + den_e = 31; + move16(); + } + + // g1 = ( c3 * c4 - 2 * c1 * c2 ) / den; + W_tmp = W_sub( W_mult0_32_32( c3, c4 ), W_shl( W_mult0_32_32( c1, c2 ), 1 ) ); + g1_e = 63; + move16(); + shift = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, shift ) ); + g1_e = sub( g1_e, shift ); + + g1 = BASOP_Util_Divide3232_Scale( L_tmp, den, &tmp_e ); + g1_e = sub( add( tmp_e, g1_e ), den_e ); + + // g2 = ( c1 * c4 - 2 * c0 * c3 ) / den; + W_tmp = W_sub( W_mult0_32_32( c1, c4 ), W_shl( W_mult0_32_32( c0, c3 ), 1 ) ); + g2_e = 63; + move16(); + shift = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, shift ) ); + g2_e = sub( g2_e, shift ); + + g2 = BASOP_Util_Divide3232_Scale( L_tmp, den, &tmp_e ); + g2_e = sub( add( tmp_e, g2_e ), den_e ); + + // *Env_error = 0.0f; + *Env_error = 0; + move16(); + flag_plosive = 0; + move16(); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + // Env_error_part[i] = c5_part[i] + g1 * g1 * c0_part[i] + g1 * c1_part[i] + g2 * g2 * c2_part[i] + g2 * c3_part[i] + g1 * g2 * c4_part[i]; + L_tmp = BASOP_Util_Add_Mant32Exp( c5_part[i], 31, Mpy_32_32( L_mult( g1, g1 ), c0_part[i] ), add( shl( g1_e, 1 ), 31 ), &tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, tmp_e, Mpy_32_16_1( c1_part[i], g1 ), add( 31, g1_e ), &tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, tmp_e, Mpy_32_32( L_mult( g2, g2 ), c2_part[i] ), add( shl( g2_e, 1 ), 31 ), &tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, tmp_e, Mpy_32_16_1( c3_part[i], g2 ), add( 31, g2_e ), &tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, tmp_e, Mpy_32_32( L_mult( g1, g2 ), c4_part[i] ), add( add( g1_e, g2_e ), 31 ), &tmp_e ); + + // Env_error_part[i] = L_shr( L_tmp, 31 - tmp_e ); // Check Exponent + Env_error_part[i] = extract_h( L_shr_sat( L_tmp, sub( Q15, tmp_e ) ) ); /* Q0 */ + move16(); + + // *Env_error += Env_error_part[i]; + *Env_error = add_sat( *Env_error, Env_error_part[i] ); /* Q0 */ + move16(); + + if ( GT_16( Env_error_part[i], THR_ENV_ERROR_PLOSIVE_FX ) ) // Check which Q + { + /* envelope error is too high -> likely a plosive */ + flag_plosive = 1; + move16(); + } + } + + IF( flag_plosive ) + { + /* plosive detected -> set the mixing factor to 0 */ + *vf_ind = 0; + move16(); + mix_factor = 0; + move16(); + } + ELSE + { + /* normalize gain */ + // g = g2 / ( g1 + g2 ); + tmp1_e = BASOP_Util_Add_MantExp( g1, g1_e, g2, g2_e, &tmp ); + IF( tmp == 0 ) + { + tmp = 1; + move16(); + tmp1_e = 15; + move16(); + } + g = BASOP_Util_Divide1616_Scale( g2, tmp, &tmp_e ); + g_e = sub( add( tmp_e, g2_e ), tmp1_e ); + + /* quantization of the mixing factor */ + cbsize = 1 << NUM_BITS_SHB_VF; + move16(); + // delta = 1.0f / ( cbsize - 1 ); + delta = 2341; /* Q14 */ + move16(); + // if ( g > 1.0f ) + IF( BASOP_Util_Cmp_Mant32Exp( g, add( 16, g_e ), ONE_IN_Q31, 0 ) > 0 ) + { + // g = 1.0f; + g = MAX16B; /* Q15 */ + } + // else if ( g < shl( delta, ( 15 - g_e ) - 14 ) ) + ELSE IF( BASOP_Util_Cmp_Mant32Exp( g, add( 16, g_e ), delta, 17 ) < 0 ) + { + /* prevent low gains to be quantized to 0 as this is reserved for plosives */ + // g = delta; + g = shl( delta, 1 ); /* Q15 */ + } + + *vf_ind = usquant_fx( g, &mix_factor, 0, delta, cbsize ); + move16(); + } + } + ELSE +#else + UNUSED_PARAM( Env_error_part ); + UNUSED_PARAM( Env_error ); + UNUSED_PARAM( EnvSHBres_4k ); + UNUSED_PARAM( c5_part ); + UNUSED_PARAM( c1 ); + UNUSED_PARAM( den ); + UNUSED_PARAM( c3_part ); + UNUSED_PARAM( c0 ); + UNUSED_PARAM( delta ); + UNUSED_PARAM( c3 ); + UNUSED_PARAM( c2_part ); + UNUSED_PARAM( c1_part ); + UNUSED_PARAM( EnvWhiteExc16k ); + UNUSED_PARAM( g2 ); + UNUSED_PARAM( c5 ); + UNUSED_PARAM( c4_part ); + UNUSED_PARAM( EnvWhiteExc16k_4k ); + UNUSED_PARAM( c2 ); + UNUSED_PARAM( g ); + UNUSED_PARAM( cbsize ); + UNUSED_PARAM( g1 ); + UNUSED_PARAM( EnvExc16kWhtnd ); + UNUSED_PARAM( c0_part ); + UNUSED_PARAM( EnvExc16kWhtnd_4k ); + UNUSED_PARAM( c4 ); +#endif + { + Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, + ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); + tmp = voiceFacEst[0]; + tmp2 = MAX_16; + move16(); + move16(); + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) + { + tmp2 = 26214 /*0.8f Q15*/; + move16(); + } + } + } + ELSE /* decoder side */ + { + test(); +#if 1 // def ADD_IVAS_TBE_CODE + IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) + { + IF( *vf_ind == 0 ) + { + // mix_factor = 0.0f; + mix_factor = 0; + move16(); + flag_plosive = 1; + move16(); + } + ELSE + { + // mix_factor = usdequant(*vf_ind, 0.0f, 1.0f / ((1 << NUM_BITS_SHB_VF) - 1)); + mix_factor = usdequant_fx( *vf_ind, 0, 2341 ); + } + } + ELSE +#endif + { + /* *vf_ind is an integer scale by 0.125f*/ + tmp = shl( *vf_ind, ( 15 - 3 ) ); + tmp2 = MAX_16; + move16(); + IF( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) + { + tmp2 = 26214 /*0.8f Q15*/; + move16(); + } + } + } +#if 1 // def ADD_IVAS_TBE_CODE + test(); + IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) +#endif + { + voice_factors[0] = mult_r( voice_factors[0], tmp2 ); + move16(); + voice_factors[1] = mult_r( voice_factors[1], tmp2 ); + move16(); + voice_factors[2] = mult_r( voice_factors[2], tmp2 ); + move16(); + voice_factors[3] = mult_r( voice_factors[3], tmp2 ); + move16(); + voice_factors[4] = mult_r( voice_factors[4], tmp2 ); + move16(); + } + } +#if 1 // def ADD_IVAS_TBE_CODE + test(); + IF( GE_16( element_mode, IVAS_CPE_DFT ) && nlExc16k != NULL ) + { + /* save buffers for IC-BWE */ + // mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); + Copy( exc16kWhtnd, nlExc16k, L_FRAME16k ); + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); + /*Word16 temp_fac = divide3232(L_shr(pow1, Q_pow1), pow22); + Word16 temp_fac_exp = 0; + temp_fac = Sqrt16(temp_fac, &temp_fac_exp);*/ + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + Word16 temp_fac = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 + // v_multc_fixed_16_16(White_exc16k,shr(temp_fac, temp_fac_exp) , mixExc16k, L_FRAME16k); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); + move16(); + } + } +#endif + + tmp = sub( Q_temp, 3 ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k_FB[k] = White_exc16k[k]; /* Q_bwe_exc-NOISE_QADJ */ + } + prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; + move16(); + *Q_bwe_exc_fb = sub( *Q_bwe_exc, NOISE_QADJ ); + move16(); + deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); + /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ + /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ + +#if 1 // def ADD_IVAS_TBE_CODE + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) + { + IF( !flag_plosive ) /* use only LB excitation in case of plosives */ + { + /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */ + // old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1); + // old_scale = divide3232(*prev_pow_exc16kWhtnd, pow1); // exp = Q15 - (Q_pow1) + // Word16 old_scale_exp = Q15 - (Q_pow1); + // old_scale = Sqrt16(old_scale, &old_scale_exp); + // old_scale = shl(old_scale, old_scale_exp); //Q15 + L_tmp = root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ); + old_scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 + // new_scale = 1.0f; + new_scale = 32767; + move16(); + // step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); + step_scale = mult_r( sub( new_scale, old_scale ), 205 ); + scale = old_scale; + move16(); + /* interpolate between the old and the new value of the mixing factor */ + old_fact = *prev_mix_factor; + move16(); + new_fact = mix_factor; + move16(); + // step = (new_fact - old_fact) / (L_FRAME16k / 2); + step = mult_r( sub( new_fact, old_fact ), 205 ); + fact = old_fact; + move16(); + /* mixing of LB and gaussian excitation in the first half of the frame */ + FOR( k = 0; k < L_FRAME16k / 2; k++ ) + { + // exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; + // exc16kWhtnd[k] = add(mult_r(fact, mult(shl(White_exc16k[k], *Q_bwe_exc), scale)), mult_r(sub(32767, fact), exc16kWhtnd[k])); + L_tmp = L_add( L_shl( L_mult( fact, mult_r( White_exc16k[k], scale ) ), NOISE_QADJ ), + L_mult( sub( 32767, fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc + exc16kWhtnd[k] = round_fx( L_tmp ); + move16(); + fact = add_sat( fact, step ); + scale = add_sat( scale, step_scale ); + } + + /* mixing of LB and gaussian excitation in the second half of the frame */ + FOR( ; k < L_FRAME16k; k++ ) + { + // exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; + // exc16kWhtnd[k] = add(mult_r(new_fact, shl(White_exc16k[k], *Q_bwe_exc)), mult_r(sub(32767, new_fact), exc16kWhtnd[k])); + L_tmp = L_add( L_shl( L_mult( new_fact, White_exc16k[k] ), NOISE_QADJ ), + mult_r( sub( 32767, new_fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc + exc16kWhtnd[k] = round_fx( L_tmp ); + move16(); + } + } + // preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); + PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); + } + ELSE +#endif + { +#if 1 // def ADD_IVAS_TBE_CODE + test(); + IF( EQ_16( coder_type, UNVOICED ) || EQ_16( MSFlag, 1 ) ) +#else + IF( EQ_16( coder_type, UNVOICED ) ) +#endif + { + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + test(); + if ( chk1 == 0 && chk2 == 0 ) + { + L_tmp = 0; + move32(); + } +#ifdef BASOP_NOGLOB + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ +#else + scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ +#endif + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ + L_tmp = L_mult( White_exc16k[k], scale ); + /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ + exc16kWhtnd[k] = round_fx_sat( L_shl_sat( L_tmp, NOISE_QADJ ) ); + move16(); + /* exc16kWhtnd: Q_bwe_exc */ + } + PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); + /* i/o: exc16kWhtnd (Q_bwe_exc) */ + /* i/o: tbe_premph (Q_bwe_exc) */ + } + ELSE + { + Word16 nbSubFr, lSubFr; + Word16 tempQ15; + Word32 tempQ31; + nbSubFr = NB_SUBFR16k; + lSubFr = ( L_FRAME16k / NB_SUBFR16k ); + move16(); + move16(); + IF( LT_32( extl_brate, SWB_TBE_2k8 ) ) + { + nbSubFr = NB_SUBFR; + move16(); + lSubFr = ( L_FRAME16k / NB_SUBFR ); + move16(); + } + k = 0; + move16(); + FOR( i = 0; i < nbSubFr; i++ ) + { + test(); + IF( EQ_16( coder_type, VOICED ) && ( LT_32( extl_brate, SWB_TBE_2k8 ) ) ) + { + exp = 0; + move16(); + tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ + temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ + exp = 0; + move16(); + tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ + + /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ + temp = sub( MAX_16, temp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); +#ifdef BASOP_NOGLOB + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ +#else + temp2 = round_fx( L_shl( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ +#endif + } + ELSE + { + /* Adjust noise mixing for formant sharpening filter */ + tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); + /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ + vf_tmp = sub( MAX_16, tempQ15 ); + vf_tmp = mult( voice_factors[i], vf_tmp ); + + exp = 0; + move16(); + tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ + + /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ + temp = sub( MAX_16, vf_tmp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); +#ifdef BASOP_NOGLOB + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ +#else + temp2 = round_fx( L_shl( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ +#endif + } + + FOR( j = 0; j < lSubFr; j++ ) + { + /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ + L_tmp = L_mult( temp2, White_exc16k[k + j] ); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); +#else + L_tmp = L_shl( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r( L_tmp, temp1, exc16kWhtnd[k + j] ); +#endif + move16(); + /* Q_bwe_exc */ + } + k = add( k, lSubFr ); + + /* estimate the pre-emph factor */ + tempQ15 = sub( MAX_16, voice_factors[i] ); + exp = 0; + move16(); + temp = Sqrt16( tempQ15, &exp ); + temp = shl( temp, sub( exp, 1 ) ); + + temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ + temp = div_s( temp, temp2 ); /* Q15 */ + temp = mult_r( PREEMPH_FAC, temp ); + + PREEMPH_FX( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); + /* exc16kWhtnd: Q_bwe_exc; + tbe_premph: Q_bwe_exc*/ + } + } + } + +#if 1 // def ADD_IVAS_TBE_CODE + IF( LT_32( extl_brate, SWB_TBE_2k8 ) ) +#else + IF( LT_32( bitrate, ACELP_24k40 ) ) +#endif + { + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: excSHB in Q_bwe_exc */ + } + ELSE + { + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); + + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); + syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); + syn_shb_ener_sf_q[0] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); + + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); + syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); + syn_shb_ener_sf_q[1] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); + + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); + syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); + syn_shb_ener_sf_q[2] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); + + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); + tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); + Scale_sig( tempSHB, 80, tmp ); + syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); + syn_shb_ener_sf_q[3] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); + move16(); + + tmp2 = s_min( s_min( syn_shb_ener_sf_q[0], syn_shb_ener_sf_q[1] ), s_min( syn_shb_ener_sf_q[3], syn_shb_ener_sf_q[2] ) ); + syn_shb_ener_sf[0] = L_shl( syn_shb_ener_sf[0], sub( tmp2, syn_shb_ener_sf_q[0] ) ); + move32(); + syn_shb_ener_sf[1] = L_shl( syn_shb_ener_sf[1], sub( tmp2, syn_shb_ener_sf_q[1] ) ); + move32(); + syn_shb_ener_sf[2] = L_shl( syn_shb_ener_sf[2], sub( tmp2, syn_shb_ener_sf_q[2] ) ); + move32(); + syn_shb_ener_sf[3] = L_shl( syn_shb_ener_sf[3], sub( tmp2, syn_shb_ener_sf_q[3] ) ); + move32(); + + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: tempSHB in Q_bwe_exc */ + /* o: syn_shb_ener_sf in tmp2 */ + IF( LE_32( bitrate, MAX_ACELP_BRATE ) ) + { + L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); + + /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ + tmp = shl( Q_shb, 1 ); + L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ + + *Q_bwe_exc = sub( *Q_bwe_exc, exp ); + move16(); /* compensate for the exp shift */ + tmp2 = add( prev_Q_bwe_syn, n_mem2 ); + IF( GT_16( *Q_bwe_exc, tmp2 ) ) + { + L_tmp2 = L_shl( L_tmp2, sub( tmp2, *Q_bwe_exc ) ); + *Q_bwe_exc = tmp2; + move16(); + } + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ + exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + move16(); + } + } + /* i: L_tmp2 in (Q31-exp) */ + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ + + /* Rescale the past memories: LP synth and SHB look ahead buffers */ + tmp = sub( *Q_bwe_exc, prev_Q_bwe_syn ); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + state_lpc_syn[i] = shl_sat( state_lpc_syn[i], tmp ); + move16(); + } + FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) + { + excSHB[i] = shl_sat( excSHB[i], tmp ); + move16(); + } + /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ + + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); + /* i: exc16kWhtnd in (Q_bwe_exc) */ + /* o: excSHB in (Q_bwe_exc) */ + } + + IF( EQ_16( extl, FB_TBE ) ) + { + tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); + Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); + Scale_sig( fb_tbe_demph, 1, tmp ); + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); + /* i: White_exc16k_FB in (14-n2) */ + /* o: White_exc16k_FB_temp in (14-n2) */ + + FOR( i = 0; i < 10; i++ ) + { + FOR( j = 0; j < 32; ++j ) + { +#ifndef FIX_875_SATURATION_DURING_ROUNDING + White_exc16k_FB_temp[i * 32 + j] = mult_r( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); +#else + White_exc16k_FB_temp[i * 32 + j] = mult_r_sat( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); +#endif + move16(); + } + } + + *Q_bwe_exc_fb = add( *Q_bwe_exc_fb, 20 ); + move16(); /**Q_bwe_exc_fb +35 +1 -16*/ + flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); + + deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); + } + ELSE + { + set16_fx( White_exc16k_FB, 0, L_FRAME16k ); + } + +#if 1 // def ADD_IVAS_TBE_CODE + *prev_pow_exc16kWhtnd = L_shr_sat( pow1, Q_pow1 ); // power goes above MAX_32 + *prev_mix_factor = mix_factor; +#endif + return; +} +#endif + /*====================================================================================*/ /* FUNCTION : void GenSHBSynth_fx() */ /*------------------------------------------------------------------------------------*/ diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 6b0ba4d03..f1fe24feb 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -186,7 +186,7 @@ void Syn_filt_s( } -#ifndef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------* * syn_filt_fx: * diff --git a/lib_com/tcx_utils.c b/lib_com/tcx_utils.c index 06d12bb36..942105a94 100644 --- a/lib_com/tcx_utils.c +++ b/lib_com/tcx_utils.c @@ -43,6 +43,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tcx_get_windows_flt() * @@ -1003,3 +1004,4 @@ void SetTnsConfig_flt( return; } +#endif diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index e80258462..87f22ae93 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -1773,14 +1773,14 @@ void ivas_swb_tbe_dec_fx( move16(); Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - GenShapedSHBExcitation_ivas_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, - hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, - shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, - st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, - NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); + GenShapedSHBExcitation_ivas_dec_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, + shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, + st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, + NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); *Q_white_exc = Q_bwe_exc_fb; move16(); @@ -1824,8 +1824,8 @@ void ivas_swb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { /* TD BWE post-processing */ - PostShortTerm_ivas_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); + PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 9bb027025..3f94e5108 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -376,9 +376,7 @@ static void CalcPowerSpecAndDetectTonalComponents( return; } -#endif -#ifndef IVAS_FLOAT_FIXED static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const char type, @@ -403,9 +401,7 @@ static void CalcMDXT( return; } -#endif -#ifndef IVAS_FLOAT_FIXED void TonalMDCTConceal_Detect_ivas( const TonalMDCTConcealPtr hTonalMDCTConc, const float pitchLag, @@ -935,8 +931,7 @@ void TonalMDCTConceal_Apply_ivas( return; } -#endif -#ifndef IVAS_FLOAT_FIXED + void TonalMDCTConceal_SaveTimeSignal_ivas( TonalMDCTConcealPtr hTonalMDCTConc, float *timeSignal, diff --git a/lib_enc/analy_sp.c b/lib_enc/analy_sp.c index b35099540..fef12fe32 100644 --- a/lib_enc/analy_sp.c +++ b/lib_enc/analy_sp.c @@ -45,6 +45,7 @@ #include #include "ivas_cnst.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------------*/ @@ -408,3 +409,4 @@ static void find_enr_dft( return; } +#endif diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 3386cdbe6..6215651cc 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -647,6 +647,7 @@ void ivas_analy_sp_fx_front( pt_bands += NB_BANDS; pt_fft += L_FFT; } + LEtot = L_shr( LEtot, Q1 ); // Q_new + Q_SCALE - 2 } ELSE { @@ -980,7 +981,7 @@ static void ivas_find_enr1( Word16 q_data, /* i : Q of fft result */ Word32 band[], /* o : per band energy Q_new + QSCALE */ Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ - Word32 *LEtot, /* o : total energy Q_new + QSCALE-2 */ + Word32 *LEtot, /* o : total energy Q_new + QSCALE-1 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word16 Q_new, /* i : scaling factor Q0 */ @@ -1116,7 +1117,7 @@ static void ivas_find_enr1( move32(); FOR( i = min_band; i <= max_band; i++ ) { - etot = L_add( etot, L_shr( band[i], Q2 ) ); // Q_new + QSCALE - 2 + etot = L_add( etot, L_shr( band[i], Q1 ) ); // Q_new + QSCALE - 1 } *LEtot = etot; move32(); diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index a5152dcb6..3e4e368b0 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -49,6 +49,7 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * HBAutocorrelation() * @@ -96,6 +97,7 @@ void HBAutocorrelation( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 04d572606..110e2a63c 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1304,12 +1304,23 @@ void ShapeSpectrum_ivas_fx( { Word16 fac; fac = divide3232( max_low2, max_high ); - fac = shl( mult_r( fac, max_fac_m ), max_fac_s ); - - FOR( i = 0; i < sub( L_spec, L_frame ); i++ ) + IF( GE_16( norm_s( fac ), max_fac_s ) ) { - spectrum[L_frame + i] = Mpy_32_16_1( spectrum[L_frame + i], fac ); - move32(); + fac = shl( mult_r( fac, max_fac_m ), max_fac_s ); + FOR( i = 0; i < ( L_spec - L_frame ); i++ ) + { + spectrum[L_frame + i] = Mpy_32_16_1( spectrum[L_frame + i], fac ); + move32(); + } + } + ELSE + { + fac = mult_r( fac, max_fac_m ); + FOR( i = 0; i < ( L_spec - L_frame ); i++ ) + { + spectrum[L_frame + i] = L_shl( Mpy_32_16_1( spectrum[L_frame + i], fac ), max_fac_s ); + move32(); + } } } } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 02f6a2ad8..c8ddd7ccd 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -722,8 +722,7 @@ static void init_tcx_ivas_fx( return; } -#endif -#ifndef IVAS_FLOAT_FIXED +#else static void init_tcx( Encoder_State *st, const int16_t L_frame_old, @@ -734,26 +733,6 @@ static void init_tcx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ -#ifdef IVAS_FLOAT_FIXED - hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx; - hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX; - st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_e[1] = 0; - move16(); - move16(); - -#ifdef MSAN_FIX - set_zero_fx( hTcxEnc->spectrum_fx[0], N_TCX10_MAX ); - set_zero_fx( hTcxEnc->spectrum_fx[1], N_TCX10_MAX ); -#endif - init_tcx_cfg_ivas_fx( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, - st->fscale, st->preemph_fac, st->tcxonly, st->rf_mode, st->igf, - st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag ); -#else -#ifdef MSAN_FIX - set_zero( hTcxEnc->spectrum[0], N_TCX10_MAX ); - set_zero( hTcxEnc->spectrum[1], N_TCX10_MAX ); -#endif - hTcxEnc->spectrum[0] = hTcxEnc->spectrum_long; hTcxEnc->spectrum[1] = hTcxEnc->spectrum_long + N_TCX10_MAX; @@ -761,25 +740,14 @@ static void init_tcx( st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, st->fscale, st->encoderLookahead_enc, st->encoderLookahead_FB, st->preemph_fac_flt, st->tcxonly, st->rf_mode, st->igf, st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag ); -#endif /* Init TCX target bits correction factor */ -#ifndef IVAS_FLOAT_FIXED hTcxEnc->tcx_target_bits_fac_flt = 1.0f; hTcxEnc->measuredBwRatio_flt = 1.0f; hTcxEnc->noiseTiltFactor_flt = 0.5625f; -#else - hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14; - hTcxEnc->measuredBwRatio = ONE_IN_Q14; - hTcxEnc->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ -#endif hTcxEnc->noiseLevelMemory_cnt = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hTcxEnc->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS ); -#else - set16_fx( hTcxEnc->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); -#endif set_c( hTcxEnc->memQuantZeros, 0, L_FRAME_PLUS ); /* TCX-LTP */ @@ -789,24 +757,13 @@ static void init_tcx( { hTcxEnc->tcxltp_pitch_int_past = st->L_frame; hTcxEnc->tcxltp_pitch_fr_past = 0; -#ifndef IVAS_FLOAT_FIXED hTcxEnc->tcxltp_gain_past_flt = 0.f; hTcxEnc->tcxltp_norm_corr_past_flt = 0.f; hTcxEnc->tcxltp_norm_corr_mem_flt = 0.f; hTcxEnc->kernel_switch_corr_past_flt = 0.f; -#else - hTcxEnc->tcxltp_gain_past = 0; - hTcxEnc->tcxltp_norm_corr_past = 0; - hTcxEnc->tcxltp_norm_corr_mem = 0; - hTcxEnc->kernel_switch_corr_past = 0; -#endif hTcxEnc->kernel_symmetry_past = 0; /* MDCT_IV & 1 */ hTcxEnc->enc_ste_pre_corr_past = 0; -#ifndef IVAS_FLOAT_FIXED hTcxEnc->tfm_mem = 0.75f; -#else - hTcxEnc->tfm_mem_fx = 1610612736; /* 0.75 in Q31 */ -#endif hTcxEnc->tcxltp_on_mem = 0; } else if ( st->L_frame != L_frame_old && !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) && @@ -842,6 +799,7 @@ static void init_tcx( return; } #endif + /*-----------------------------------------------------------------------* * init_sig_buffers() * @@ -1641,6 +1599,8 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh move16(); set16_fx( hLPDmem->mem_syn, 0, M ); set16_fx( hLPDmem->mem_syn2, 0, M ); + hLPDmem->q_mem_syn = Q15; + move16(); } /* unquantized LPC*/ diff --git a/lib_enc/core_enc_ol.c b/lib_enc/core_enc_ol.c index 562e28d77..9251d9311 100644 --- a/lib_enc/core_enc_ol.c +++ b/lib_enc/core_enc_ol.c @@ -265,14 +265,7 @@ void core_encode_openloop( /* reset TBE buffers previous frame frame wasn't ACELP*/ if ( st->last_core != ACELP_CORE ) { -#ifdef IVAS_FLOAT_FIXED - TBEreset_enc_fx( st, st->bwidth ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - TBEreset_enc( st->hBWE_TD, st->last_core, st->bwidth ); -#endif -#else TBEreset_enc( st->hBWE_TD, st->last_core, st->bwidth ); -#endif } /* Run ACELP encoder */ diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index ba14a213c..e107c064e 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -238,9 +238,6 @@ void core_coder_mode_switch_ivas_fx( ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - TBEreset_enc( st->hBWE_TD, st->last_core, st->bwidth ); -#endif TBEreset_enc_fx( st, st->bwidth ); } ELSE @@ -401,14 +398,7 @@ void core_coder_mode_switch( ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ) ) { -#ifdef IVAS_FLOAT_FIXED - TBEreset_enc_fx( st, st->bwidth ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS TBEreset_enc( st->hBWE_TD, st->last_core, st->bwidth ); -#endif -#else - TBEreset_enc( st->hBWE_TD, st->last_core, st->bwidth ); -#endif } else { diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 1c408062d..ee73fd8b2 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -56,15 +56,22 @@ *---------------------------------------------------------------------*/ void core_switching_pre_enc( - Encoder_State *st, /* i/o: encoder state structure */ - const float *old_inp_12k8, /* i : old input signal @12.8kHz */ - const float *old_inp_16k, /* i : old input signal @16kHz */ + Encoder_State *st, /* i/o: encoder state structure */ +#ifndef IVAS_FLOAT_FIXED + const float *old_inp_12k8, /* i : old input signal @12.8kHz */ + const float *old_inp_16k, /* i : old input signal @16kHz */ +#endif const int16_t active_cnt, /* i : active frame counter */ const int16_t last_element_mode /* i : last_element_mode */ ) { - int16_t Sample_Delay_HP, Sample_Delay_LP; - + int16_t Sample_Delay_HP +#ifndef IVAS_FLOAT_FIXED + , + Sample_Delay_LP; +#else + ; +#endif HQ_ENC_HANDLE hHQ_core = st->hHQ_core; LPD_state_HANDLE hLPDmem = st->hLPDmem; @@ -364,7 +371,9 @@ void core_switching_pre_enc( if ( st->L_frame == L_FRAME ) { Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); +#ifndef IVAS_FLOAT_FIXED Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); +#endif if ( st->element_mode > EVS_MONO ) { @@ -375,12 +384,16 @@ void core_switching_pre_enc( Sample_Delay_HP -= NS2SA( 16000, DELAY_FIR_RESAMPL_NS ); } +#ifndef IVAS_FLOAT_FIXED mvr2r( old_inp_12k8 + L_INP_MEM + L_FRAME - Sample_Delay_LP, st->hBWE_FD->old_input_lp, Sample_Delay_LP ); +#endif } else { Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); +#ifndef IVAS_FLOAT_FIXED Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); +#endif if ( st->element_mode > EVS_MONO ) { @@ -391,19 +404,15 @@ void core_switching_pre_enc( Sample_Delay_HP -= NS2SA( 16000, DELAY_FIR_RESAMPL_NS ); } +#ifndef IVAS_FLOAT_FIXED mvr2r( old_inp_16k + L_INP_MEM + L_FRAME - Sample_Delay_LP, st->hBWE_FD->old_input_lp, Sample_Delay_LP ); +#endif } #ifndef IVAS_FLOAT_FIXED mvr2r( st->hBWE_TD->old_speech_shb + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, st->hBWE_FD->new_input_hp, Sample_Delay_HP ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->hBWE_FD->new_input_hp, st->hBWE_FD->new_input_hp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); -#endif Copy( st->hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, st->hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hBWE_FD->new_input_hp_fx, st->hBWE_FD->new_input_hp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); -#endif #endif if ( st->last_extl != WB_BWE ) @@ -631,6 +640,8 @@ void core_switching_pre_enc_ivas_fx( set16_fx( hLPDmem->mem_syn2, 0, M ); set16_fx( hLPDmem->mem_syn, 0, M ); set16_fx( hLPDmem->mem_syn1_fx, 0, M ); + hLPDmem->q_mem_syn = Q15; + move16(); hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index 13ab05489..19cf29238 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -43,10 +43,9 @@ #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx.h" -#endif + +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -65,7 +64,6 @@ #define MAX_BRATE_DTX_EVS ACELP_24k40 /* maximum bitrate to which the default DTX is applied in EVS; otherwise DTX is applied only in silence */ #define MAX_BRATE_DTX_IVAS IVAS_80k /* maximum bitrate to which the default DTX is applied in IVAS; otherwise DTX is applied only in silence */ -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -750,7 +748,6 @@ void dtx_hangover_control( return; } -#endif /*-------------------------------------------------------------------* @@ -758,102 +755,7 @@ 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 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; - hTdCngEnc->lp_ener_fx = 0; - hTdCngEnc->old_enr_index = -1; - hTdCngEnc->Enew_fx = 0; - hTdCngEnc->lp_sp_enr_fx = 0; - hTdCngEnc->last_allow_cn_step = 0; - hTdCngEnc->CNG_att_fx = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - - IF( Opt_DTX_ON ) - { - hTdCngEnc->cng_hist_ptr = -1; - set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M ); - set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); - hTdCngEnc->ho_hist_ptr = -1; - hTdCngEnc->ho_sid_bw = 0; - 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 ); - hTdCngEnc->ho_hist_size = 0; - hTdCngEnc->act_cnt = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - } - - 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; - 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 ); - hTdCngEnc->ho_circ_size = 0; - hTdCngEnc->burst_ho_cnt = 0; - hTdCngEnc->cng_buf_cnt = 0; - move16(); - move16(); - move16(); - - set32_fx( hTdCngEnc->lp_env_fx, 0, 20 ); - set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 ); - 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 ); - set16_fx( hTdCngEnc->cng_exc2_buf, 0, HO_HIST_SIZE * L_FFT ); - set16_fx( hTdCngEnc->cng_Qexc_buf, Q15, HO_HIST_SIZE ); - - /* SWB CNG/DTX */ - hTdCngEnc->last_wb_cng_ener_fx = -1541; - hTdCngEnc->last_shb_cng_ener_fx = -1541; - hTdCngEnc->mov_wb_cng_ener_fx = -1541; - hTdCngEnc->mov_shb_cng_ener_fx = -1541; - move16(); - move16(); - move16(); - move16(); - hTdCngEnc->shb_cng_ini_cnt = 1; - hTdCngEnc->shb_NO_DATA_cnt = 0; - move16(); - move16(); - hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB ); - hTdCngEnc->last_vad = 0; - hTdCngEnc->last_idx_ener = 0; - move16(); - move16(); - move16(); - - return; -} -#else 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 */ @@ -920,9 +822,8 @@ void td_cng_enc_init( return; } -#endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------* * dtx_enc_init() * diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index d3867fc18..0797bd032 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -1662,6 +1662,103 @@ void td_cng_enc_init_fx( return; } +void td_cng_enc_init_ivas_fx( + TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +) +{ + + hTdCngEnc->cng_seed = RANDOM_INITSEED; + move16(); + hTdCngEnc->cng_ener_seed = RANDOM_INITSEED; + move16(); + hTdCngEnc->cng_ener_seed1 = RANDOM_INITSEED; + move16(); + hTdCngEnc->lp_ener_fx = 0; + move16(); + hTdCngEnc->old_enr_index = -1; + move16(); + hTdCngEnc->Enew_fx = 0; + move16(); + + hTdCngEnc->lp_sp_enr_fx = 0; + move16(); + hTdCngEnc->last_allow_cn_step = 0; + move16(); + + hTdCngEnc->CNG_att_fx = 0; + move16(); + + IF( Opt_DTX_ON ) + { + hTdCngEnc->cng_hist_ptr = -1; + move16(); + set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M ); + set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); + hTdCngEnc->ho_hist_ptr = -1; + move16(); + hTdCngEnc->ho_sid_bw = 0; + move32(); + 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 ); + hTdCngEnc->ho_hist_size = 0; + move16(); + hTdCngEnc->act_cnt = 0; + move16(); + } + + set16_fx( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE ); + hTdCngEnc->act_cnt2 = 0; + move16(); + hTdCngEnc->num_ho = 0; + move16(); + + hTdCngEnc->ho_circ_ptr = -1; + 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 ); + hTdCngEnc->ho_circ_size = 0; + move16(); + hTdCngEnc->burst_ho_cnt = 0; + move16(); + hTdCngEnc->cng_buf_cnt = 0; + move16(); + + set32_fx( hTdCngEnc->lp_env_fx, 0, 20 ); + set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 ); + 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 ); + set16_fx( hTdCngEnc->cng_exc2_buf, 0, HO_HIST_SIZE * L_FFT ); + set16_fx( hTdCngEnc->cng_Qexc_buf, Q15, HO_HIST_SIZE ); + + /* SWB CNG/DTX */ + hTdCngEnc->last_wb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->last_shb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->mov_wb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->mov_shb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->shb_cng_ini_cnt = 1; + move16(); + hTdCngEnc->shb_NO_DATA_cnt = 0; + move16(); + hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB ); + move16(); + hTdCngEnc->last_vad = 0; + move16(); + hTdCngEnc->last_idx_ener = 0; + move16(); + + return; +} + /*-------------------------------------------------------------------* * dtx_enc_init_fx() * diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index bea9bec38..8f8541724 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -584,8 +584,9 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } +#ifndef IVAS_FLOAT_FIXED speech_music_clas_init( st->hSpMusClas ); -#if 1 +#else speech_music_clas_init_ivas_fx( st->hSpMusClas ); #endif @@ -704,7 +705,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } +#ifndef IVAS_FLOAT_FIXED td_cng_enc_init( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); +#else + td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); +#endif } else { @@ -793,7 +798,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } +#ifndef IVAS_FLOAT_FIXED LPDmem_enc_init( st->hLPDmem ); +#else + LPDmem_enc_init_ivas_fx( st->hLPDmem ); +#endif } else { @@ -843,13 +852,11 @@ ivas_error init_encoder( return error; } - InitSWBencBuffer( st->hBWE_TD ); -#ifdef IVAS_FLOAT_FIXED - InitSWBencBuffer_ivas_fx( st ); -#endif #ifndef IVAS_FLOAT_FIXED + InitSWBencBuffer( st->hBWE_TD ); ResetSHBbuffer_Enc( st->hBWE_TD ); #else + InitSWBencBuffer_ivas_fx( st ); ResetSHBbuffer_Enc_fx( st ); #endif } @@ -870,7 +877,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } +#ifndef IVAS_FLOAT_FIXED fd_bwe_enc_init( st->hBWE_FD ); +#else + fd_bwe_enc_init_fx( st->hBWE_FD ); +#endif } else { @@ -1388,7 +1399,8 @@ ivas_error init_encoder_ivas_fx( move16(); st->mem_wsp_fx = 0; move16(); - + st->mem_wsp_q = 0; + move16(); set16_fx( st->mem_decim2_fx, 0, 3 ); set32_fx( st->Bin_E_fx, 0, L_FFT ); st->q_Bin_E = Q31; @@ -1712,9 +1724,6 @@ ivas_error init_encoder_ivas_fx( } speech_music_clas_init_ivas_fx( st->hSpMusClas ); -#if 1 - speech_music_clas_init( st->hSpMusClas ); -#endif st->sp_aud_decision0 = 0; move16(); st->sp_aud_decision1 = 0; @@ -1845,10 +1854,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); -#if 1 - td_cng_enc_init( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); -#endif + td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); } ELSE { @@ -1936,10 +1942,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_fx( st->hLPDmem ); -#if 1 - LPDmem_enc_init( st->hLPDmem ); -#endif + LPDmem_enc_init_ivas_fx( st->hLPDmem ); } ELSE { @@ -1990,9 +1993,6 @@ ivas_error init_encoder_ivas_fx( InitSWBencBuffer_ivas_fx( st ); ResetSHBbuffer_Enc_fx( st ); -#if 1 - InitSWBencBuffer( st->hBWE_TD ); -#endif } ELSE { @@ -2013,9 +2013,6 @@ ivas_error init_encoder_ivas_fx( } fd_bwe_enc_init_fx( st->hBWE_FD ); -#if 1 - fd_bwe_enc_init( st->hBWE_FD ); -#endif } ELSE { @@ -2383,6 +2380,8 @@ ivas_error init_encoder_ivas_fx( return error; } #endif + +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * LPDmem_enc_init() * @@ -2393,10 +2392,6 @@ void LPDmem_enc_init( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ) { -#ifdef IVAS_FLOAT_FIXED - Word16 i; -#endif -#ifndef IVAS_FLOAT_FIXED set_zero( hLPDmem->syn_flt, 1 + M ); set_f( hLPDmem->old_exc_flt, 0, L_EXC_MEM ); hLPDmem->mem_w0_flt = 0.0f; @@ -2405,42 +2400,14 @@ void LPDmem_enc_init( set_f( hLPDmem->mem_syn2_flt, 0, M ); set_f( hLPDmem->mem_syn3_flt, 0, M ); set_zero( hLPDmem->mem_syn_r_flt, L_SYN_MEM ); -#endif -#ifdef IVAS_FLOAT_FIXED -#ifdef MSAN_FIX - set16_fx( hLPDmem->syn, 0, 1 + M ); - set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - hLPDmem->mem_w0 = 0; - set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); - set16_fx( hLPDmem->mem_syn1_fx, 0, M ); - set16_fx( hLPDmem->mem_syn, 0, M ); - set16_fx( hLPDmem->mem_syn2, 0, M ); - set16_fx( hLPDmem->mem_syn3, 0, M ); -#endif -#endif - -#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = 0.0f; hLPDmem->gc_threshold_flt = 0.0f; set_f( hLPDmem->dispMem_flt, 0, 8 ); -#else - hLPDmem->tilt_code = 0; - hLPDmem->gc_threshold = 0; - hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); - - FOR( i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } -#endif return; } +#endif /*-----------------------------------------------------------------------* diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index d73173121..3c1124e95 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -215,6 +215,8 @@ ivas_error init_encoder_fx( st_fx->mem_wsp_fx = 0; move16(); + st_fx->mem_wsp_q = 0; + move16(); set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); st_fx->q_Bin_E = Q31; move16(); @@ -996,6 +998,53 @@ void LPDmem_enc_init_fx( #endif return; } + +void LPDmem_enc_init_ivas_fx( + LPD_state_HANDLE hLPDmem /* i/o: LP memories */ +) +{ + Word16 i; + + set16_fx( hLPDmem->syn, 0, 1 + M ); + set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); + set16_fx( hLPDmem->mem_syn, 0, M ); + set16_fx( hLPDmem->mem_syn1_fx, 0, M ); + set16_fx( hLPDmem->mem_syn2, 0, M ); + set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); + set16_fx( hLPDmem->mem_syn3, 0, M ); + + hLPDmem->mem_w0 = 0; + move16(); + hLPDmem->tilt_code = 0; + move16(); + hLPDmem->gc_threshold = 0; + move32(); +#if 0 + //set16_fx(hLPDmem->dispMem, 0, 8); +#else + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } +#endif + + hLPDmem->q_lpd_syn = Q15; + move16(); + hLPDmem->q_lpd_old_exc = Q15; + move16(); + hLPDmem->q_mem_syn = Q15; + move16(); + + + return; +} + /*-----------------------------------------------------------------------* * destroy_encoder_fx() * diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 3a4275988..9eac0ac78 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -57,64 +57,65 @@ *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_core_enc( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ - const int16_t n_CoreChannels, /* i : number of core channels to be coded */ - float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */ - float old_inp_16k[][L_INP], /* i : buffer of old input signal */ - float ener[], /* i : residual energy from Levinson-Durbin */ - Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */ - float epsP[][M + 1], /* i : LP prediction errors */ - Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15 */ - Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15 */ - const int16_t vad_hover_flag[], /* i : VAD hanglover flag */ - int16_t attack_flag[], /* i : attack flag (GSC or TC) */ - float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ - float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ - float old_wsp[][L_WSP], /* i : weighted input signal buffer */ - const int16_t loc_harm[], /* i : harmonicity flag */ - const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8 */ - const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ - float enerBuffer[][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ - float fft_buff[][2 * L_FFT], /* i : FFT buffer */ - const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag */ - const int16_t ivas_format, /* i : IVAS format */ - const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const int16_t n_CoreChannels, /* i : number of core channels to be coded */ + float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */ + float old_inp_16k[][L_INP], /* i : buffer of old input signal */ + Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6 */ + Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */ + float epsP[][M + 1], /* i : LP prediction errors */ + Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15 */ + const int16_t vad_hover_flag[], /* i : VAD hanglover flag */ + int16_t attack_flag[], /* i : attack flag (GSC or TC) */ + Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + Word16 q_re_im_buf, + float old_wsp[][L_WSP], /* i : weighted input signal buffer */ + const int16_t loc_harm[], /* i : harmonicity flag */ + const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8 */ + const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ + Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + Word16 enerBuffer_fx_exp[], /* o : energy buffer */ + Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer */ + const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag */ + const int16_t ivas_format, /* i : IVAS format */ + const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ) { - int16_t n, input_frame; - int16_t cpe_id, MCT_flag; + Word16 n, input_frame; + Word16 cpe_id, MCT_flag; Encoder_State **sts, *st; STEREO_ICBWE_ENC_HANDLE hStereoICBWE; STEREO_TD_ENC_DATA_HANDLE hStereoTD; float *inp[CPE_CHANNELS]; - float new_inp_resamp16k[CPE_CHANNELS][L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k] = { { 0 } }; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ Word16 Q_new[CPE_CHANNELS] = { 0 }; Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ #ifdef IVAS_FLOAT_FIXED Word32 *new_swb_speech_fx; + Word16 *inp_fx[CPE_CHANNELS]; Word16 shb_speech_fx[L_FRAME16k]; // Q_shb_spch Word16 Q_shb_spch; Word32 new_swb_speech_buffer_fx[L_FRAME48k + STEREO_DFT_OVL_MAX]; - Word16 new_inp_resamp16k_fx[CPE_CHANNELS][L_FRAME16k]; + Word16 new_inp_resamp16k_fx[CPE_CHANNELS][L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ Word16 hb_speech_fx[L_FRAME16k / 4]; Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; /* 2 * Q_new */ Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ Word16 *new_swb_speech_fx_16; Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; #endif - int16_t Voicing_flag[CPE_CHANNELS]; + Word16 Voicing_flag[CPE_CHANNELS]; Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q6 */ - int16_t unbits[CPE_CHANNELS]; + Word16 unbits[CPE_CHANNELS]; Word16 tdm_lspQ_PCh_fx[M], tdm_lsfQ_PCh_fx[M]; /* 1 : Q15, 2 : Q2.56 */ - int16_t last_element_mode, tdm_Pitch_reuse_flag; - int32_t element_brate, last_element_brate, input_Fs; - int16_t diff_nBits; + Word16 last_element_mode, tdm_Pitch_reuse_flag; + Word32 element_brate, last_element_brate, input_Fs; + Word16 diff_nBits; ivas_error error; - int16_t max_num_indices_BWE; + Word16 max_num_indices_BWE; Word16 i; set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); @@ -138,48 +139,63 @@ ivas_error ivas_core_enc( * General initialization *-----------------------------------------------------------------*/ - if ( hSCE != NULL ) + IF( hSCE != NULL ) { cpe_id = -1; + move16(); MCT_flag = 0; + move16(); sts = hSCE->hCoreCoder; hStereoTD = NULL; hStereoICBWE = NULL; element_brate = hSCE->element_brate; + move32(); last_element_brate = hSCE->last_element_brate; + move32(); last_element_mode = IVAS_SCE; + move16(); tdm_Pitch_reuse_flag = -1; + move16(); } - else + ELSE { cpe_id = hCPE->cpe_id; + move16(); MCT_flag = 0; + move16(); if ( hMCT != NULL ) { MCT_flag = 1; + move16(); } sts = hCPE->hCoreCoder; hStereoICBWE = hCPE->hStereoICBWE; element_brate = hCPE->element_brate; + move32(); last_element_brate = hCPE->last_element_brate; + move32(); last_element_mode = hCPE->last_element_mode; + move16(); - if ( hCPE->hStereoTD != NULL ) + IF( hCPE->hStereoTD != NULL ) { hStereoTD = hCPE->hStereoTD; tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag; + move16(); } - else + ELSE { hStereoTD = NULL; tdm_Pitch_reuse_flag = -1; + move16(); } } input_Fs = sts[0]->input_Fs; - input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + move32(); + input_frame = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; @@ -189,29 +205,28 @@ ivas_error ivas_core_enc( st->extl = -1; + move16(); unbits[n] = 0; + move16(); st->element_brate = element_brate; + move32(); /*---------------------------------------------------------------------* * Pre-processing, incl. Decision matrix *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 fft_buff_fx[2 * L_FFT]; - Word16 e_fft_buff; - Word16 e_enerBuffer; + Word16 tmp_shift = getScaleFactor32( enerBuffer_fx[n], CLDFB_NO_CHANNELS_MAX ); + tmp_shift = sub( tmp_shift, 5 ); + IF( tmp_shift < 0 ) + { + scale_sig32( enerBuffer_fx[n], CLDFB_NO_CHANNELS_MAX, tmp_shift ); + enerBuffer_fx_exp[n] = sub( enerBuffer_fx_exp[n], tmp_shift ); + move16(); + } - f2me_buf_16( fft_buff[n], fft_buff_fx, &e_fft_buff, ( 2 * L_FFT ) ); - Scale_sig( fft_buff_fx, ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum - e_fft_buff += 1; + Scale_sig( fft_buff_fx[n], ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum + // fft_buff_fx_exp = add(fft_buff_fx_exp,1); - f2me_buf( enerBuffer[n], enerBuffer_fx, &e_enerBuffer, (Word32) CLDFB_NO_CHANNELS_MAX ); - Word16 tmp_shift = find_guarded_bits_fx( 5 ); // Computing guraded bits necessary in the energyBuffer - scale_sig32( enerBuffer_fx, CLDFB_NO_CHANNELS_MAX, -tmp_shift ); // Computing the shift as per guarded bits in the energyBuffer - e_enerBuffer += tmp_shift; // Shifting the exponent of energyBuffer with the tmp_shift -#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 old_inp_12k8_fx[L_INP_12k8]; floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, -1, L_INP_12k8 ); @@ -222,7 +237,7 @@ ivas_error ivas_core_enc( Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_12k8_fx, old_inp_16k[n], - &inp[n], &ener[n], A_fx[n], Aw_fx[n], epsP[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], + &inp[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], #ifndef IVAS_FLOAT_FIXED cor_map_sum[n], #endif @@ -234,9 +249,9 @@ ivas_error ivas_core_enc( MCT_flag, vad_hover_flag[n], flag_16k_smc #ifdef IVAS_FLOAT_FIXED , - enerBuffer_fx, - e_enerBuffer, - fft_buff_fx, + enerBuffer_fx[n], + enerBuffer_fx_exp[n], + fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] #endif @@ -245,9 +260,11 @@ ivas_error ivas_core_enc( return error; } - if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, IVAS_SCE ) ) { st->enablePlcWaveadjust = 0; + move16(); } } @@ -255,7 +272,6 @@ ivas_error ivas_core_enc( * Sanity check in combined format coding *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED diff_nBits = 0; move16(); test(); @@ -264,18 +280,18 @@ ivas_error ivas_core_enc( { ivas_combined_format_brate_sanity_fx( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits ); } -#endif /*---------------------------------------------------------------------* * Core Encoding *---------------------------------------------------------------------*/ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; + test(); /* update pointer to the buffer of indices of the second channel */ - if ( n == 1 && st->element_mode == IVAS_CPE_TD ) + IF( EQ_16( n, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) { /* adjust the pointer to the buffer of indices of the secondary channel (make space for BWE indices) */ max_num_indices_BWE = get_BWE_max_num_indices( sts[0]->extl_brate ); @@ -293,7 +309,9 @@ ivas_error ivas_core_enc( * Write signaling info into the bitstream *---------------------------------------------------------------------*/ - if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) ) + test(); + test(); + IF( !MCT_flag || ( MCT_flag && cpe_id == 0 ) ) { ivas_signaling_enc_fx( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag ); } @@ -303,37 +321,27 @@ ivas_error ivas_core_enc( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 last_core = st->last_core; - Word16 bwidth_sw_cnt = st->bwidth_sw_cnt; - Word16 q_old_inp_16k_fx; Word16 q_old_inp_12k8_fx; Word16 old_inp_16k_fx[L_INP]; Word16 old_inp_12k8_fx[L_INP_12k8]; + Word16 Q_old_syn_12k8_16k; + Word32 epsP_fx[CPE_CHANNELS][M + 1]; + Word16 e_epsP; + Word16 inp_buff[CPE_CHANNELS][L_FRAME16k + M + 1]; q_old_inp_12k8_fx = Q_factor_arr( old_inp_12k8[n], L_INP_12k8 ); q_old_inp_16k_fx = Q_factor_arr( old_inp_16k[n], L_INP ); - if ( st->hBWE_FD != NULL ) - { - st->hBWE_FD->prev_Q_input_lp = Q_factor_arr( st->hBWE_FD->old_input_lp, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); - floatToFixed_arr16( st->hBWE_FD->old_input_lp, st->hBWE_FD->old_input_lp_fx, st->hBWE_FD->prev_Q_input_lp, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); - } floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, q_old_inp_12k8_fx, L_INP_12k8 ); floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx, q_old_inp_16k_fx, L_INP ); - - - core_switching_pre_enc( st, old_inp_12k8[n], old_inp_16k[n], sts[0]->active_cnt, last_element_mode ); - - - st->last_core = last_core; - st->bwidth_sw_cnt = bwidth_sw_cnt; + f2me_buf( epsP[n], epsP_fx[n], &e_epsP, M + 1 ); + inp_fx[n] = &inp_buff[n][M + 1]; + floatToFixed_arr( &inp[n][-M - 1], &inp_fx[n][-M - 1], Q_new[n] - 1, L_FRAME16k + M + 1 ); #endif -#ifdef IVAS_FLOAT_FIXED core_switching_pre_enc_ivas_fx( st, old_inp_12k8_fx, q_old_inp_12k8_fx, old_inp_16k_fx, q_old_inp_16k_fx, sts[0]->active_cnt, last_element_mode ); -#endif /*---------------------------------------------------------------------* * ACELP core encoding @@ -341,36 +349,20 @@ ivas_error ivas_core_enc( * HQ core encoding *---------------------------------------------------------------------*/ - if ( st->core == ACELP_CORE ) + IF( st->core == ACELP_CORE ) { /* ACELP core encoder */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_old_syn_12k8_16k; - Word32 epsP_fx[CPE_CHANNELS][M + 1]; - Word16 e_epsP; - f2me_buf( epsP[n], epsP_fx[n], &e_epsP, M + 1 ); - Word16 inp_buff[CPE_CHANNELS][L_FRAME16k + M + 1]; - Word16 *inp_fx[CPE_CHANNELS]; - inp_fx[n] = &inp_buff[n][M + 1]; - floatToFixed_arr( &inp[n][-M - 1], &inp_fx[n][-M - 1], Q_new[n] - 1, L_FRAME16k + M + 1 ); -#endif -#ifndef IVAS_FLOAT_FIXED - if ( ( error = acelp_core_enc( st, inp[n], /*ener[n],*/ A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK ) -#else - if ( ( error = acelp_core_enc( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ) != IVAS_ERR_OK ) -#endif + IF( ( error = acelp_core_enc( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( old_syn_12k8_16k_fx[n], old_syn_12k8_16k[n], Q_old_syn_12k8_16k, st->L_frame ); -#endif + Scale_sig( old_syn_12k8_16k_fx[n], st->L_frame, sub( sub( Q_new[n], 1 ), Q_old_syn_12k8_16k ) ); } - if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) + test(); + test(); + IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < st->nb_subfr; i++ ) { Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 @@ -400,9 +392,6 @@ ivas_error ivas_core_enc( } #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // q_old_inp_12k8_fx = Q_factor_arr( old_inp_12k8[n], L_INP_12k8 ); - // q_old_inp_16k_fx = Q_factor_arr( old_inp_16k[n], L_INP ); - floatToFixed_arr( old_inp_12k8[n], old_inp_12k8_fx, 0, L_INP_12k8 ); floatToFixed_arr( old_inp_16k[n], old_inp_16k_fx, 0, L_INP ); #endif @@ -424,14 +413,11 @@ ivas_error ivas_core_enc( #endif } #endif // IVAS_FLOAT_FIXED_CONVERSIONS -#endif } - if ( st->core == HQ_CORE ) + IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core encoder */ - -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 q = 0; Word16 left_overlap, right_overlap; @@ -466,18 +452,16 @@ ivas_error ivas_core_enc( st->hTcxEnc->q_Txnq = 0; move16(); hq_core_enc_ivas_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); -#endif } /*---------------------------------------------------------------------* * TD stereo updates *---------------------------------------------------------------------*/ - if ( st->element_mode == IVAS_CPE_TD && n == 0 ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) { -#ifdef IVAS_FLOAT_FIXED td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, pitch_buf_fx[0], tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); -#endif } } @@ -486,11 +470,13 @@ ivas_error ivas_core_enc( * MDCT stereo: joint TCX Core Encoding *---------------------------------------------------------------------*/ - if ( sts[0]->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) ) { - if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 ) + test(); + test(); + IF( GT_32( sts[0]->core_brate, SID_2k40 ) && GT_32( sts[1]->core_brate, SID_2k40 ) ) { - if ( MCT_flag ) + IF( MCT_flag ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 old_inp_16k_fx[CPE_CHANNELS][L_INP]; @@ -512,85 +498,54 @@ ivas_error ivas_core_enc( } #endif } - else + ELSE { stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf_fx ); } } - else if ( sts[0]->core_brate == SID_2k40 && sts[1]->core_brate == SID_2k40 ) + ELSE IF( EQ_32( sts[0]->core_brate, SID_2k40 ) && EQ_32( sts[1]->core_brate, SID_2k40 ) ) { /* synch CNG configs between channels */ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { st = sts[n]; - if ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->bwidth ) ) + test(); + IF( ( NE_16( st->hFdCngEnc->hFdCngCom->frameSize, st->L_frame ) ) || ( NE_16( st->hFdCngEnc->hFdCngCom->CngBandwidth, st->bwidth ) ) ) { - configureFdCngEnc( st->hFdCngEnc, max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); + configureFdCngEnc( st->hFdCngEnc, s_max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); } } - if ( sts[0]->cng_sba_flag ) + IF( sts[0]->cng_sba_flag ) { FdCngEncodeDiracMDCTStereoSID_fx( hCPE ); } - else + ELSE { FdCngEncodeMDCTStereoSID_fx( hCPE ); } } } - - /*---------------------------------------------------------------------* - * Postprocessing, BWEs and Updates - *---------------------------------------------------------------------*/ - - FOR( n = 0; n < n_CoreChannels; n++ ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 shb_speech_fx32[L_FRAME16k]; + Word16 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8], old_inp_16k_fx[CPE_CHANNELS][L_INP]; + if ( hCPE && hCPE->hStereoDft ) + { + f2me_buf( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], &hCPE->hStereoDft->DFT_fx_e[0], STEREO_DFT_N_MAX_ENC ); + f2me_buf( hCPE->hStereoDft->DFT[1], hCPE->hStereoDft->DFT_fx[1], &hCPE->hStereoDft->DFT_fx_e[1], STEREO_DFT_N_MAX_ENC ); + } + for ( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; - - /*---------------------------------------------------------------------* - * Postprocessing for ACELP/HQ core switching - *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // conv params from float to fix - Word32 shb_speech_fx32[L_FRAME16k]; - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 q_realImagBuffer; - Word16 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8], old_inp_16k_fx[CPE_CHANNELS][L_INP]; floatToFixed_arr( st->old_input_signal, st->old_input_signal_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - floatToFixed_arr16( new_inp_resamp16k[n], new_inp_resamp16k_fx[n], -1, L_FRAME16k ); // prev_lsp_wb_temp_fx, prev_lsp_wb_fx and prev_lpc_wb_fx in Q15. No float counterparts if ( st->hBWE_FD != NULL ) { - floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, -1, L_FRAME48k ); + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); st->Q_old_wtda = -1; // This reset is required for resolving crash issue. Needs to be looked into further } - q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); - IF( st->cldfbSynTd ) - { - q_realImagBuffer = s_min( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ); - } - floatToFixed_arrL32( (float *) &realBuffer[n][0][0], (Word32 *) &realBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - floatToFixed_arrL32( (float *) &imagBuffer[n][0][0], (Word32 *) &imagBuffer_fx[0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - if ( st->element_mode == IVAS_CPE_DFT ) - { - f2me_buf( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], &hCPE->hStereoDft->DFT_fx_e[0], STEREO_DFT_N_MAX_ENC ); - f2me_buf( hCPE->hStereoDft->DFT[1], hCPE->hStereoDft->DFT_fx[1], &hCPE->hStereoDft->DFT_fx_e[1], STEREO_DFT_N_MAX_ENC ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_res_8k, hCPE->hStereoDft->output_mem_res_8k_fx, 16, STEREO_DFT_OVL_8k ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_fx, 16, STEREO_DFT_OVL_MAX ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_12k8, hCPE->hStereoDft->output_mem_dmx_12k8_fx, 16, STEREO_DFT_OVL_12k8 ); - } - if ( st->hBWE_FD ) - { - for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) - { - st->hBWE_FD->old_input_fx[ii] = (Word16) st->hBWE_FD->old_input[ii]; - } - } floatToFixed_arr( st->input_buff, st->input_buff_fx, 0 /*Q_input*/, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); f2me_buf_16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, &st->exp_buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); @@ -607,13 +562,22 @@ ivas_error ivas_core_enc( if ( st->hBWE_FD != NULL ) { - // floatToFixed_arr16( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); - floatToFixed_arr16( st->hBWE_FD->old_input_lp, st->hBWE_FD->old_input_lp_fx, Q_new[n] - 1, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); - floatToFixed_arr16( st->hBWE_FD->new_input_hp, st->hBWE_FD->new_input_hp_fx, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); + Scale_sig( st->hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( Q_new[n] - 1, st->hBWE_FD->prev_Q_input_lp ) ); + st->hBWE_FD->prev_Q_input_lp = Q_new[n] - 1; } - - floatToFixed_arr( old_syn_12k8_16k[n], old_syn_12k8_16k_fx[n], Q_new[n] - 1, L_FRAME16k ); + } #endif + /*---------------------------------------------------------------------* + * Postprocessing, BWEs and Updates + *---------------------------------------------------------------------*/ + + FOR( n = 0; n < n_CoreChannels; n++ ) + { + st = sts[n]; + + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ core_switching_post_enc_ivas_fx( st, old_inp_12k8_fx[n], old_inp_16k_fx[n], A_fx[n], Q_new[n] ); /*---------------------------------------------------------------------* @@ -663,12 +627,12 @@ ivas_error ivas_core_enc( { /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ /* Scaling cldfb_state_fx */ - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, sub( q_re_im_buf, st->cldfbSynTd->Q_cldfb_state ) ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer - swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx[n], imagBuffer_fx[n], q_re_im_buf, hCPE ); /* Re-scaling cldfb_state_fx */ - scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( sub( q_realImagBuffer, st->cldfbSynTd->Q_cldfb_state ) ) ); // q_realImagBuffer -> st->cldfbSynTd->Q_cldfb_state + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, negate( sub( q_re_im_buf, st->cldfbSynTd->Q_cldfb_state ) ) ); // q_realImagBuffer -> st->cldfbSynTd->Q_cldfb_state } ELSE IF( GE_32( input_Fs, 32000 ) ) { @@ -786,38 +750,6 @@ ivas_error ivas_core_enc( { updt_enc_common_ivas_fx( st ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->old_input_signal_fx, st->old_input_signal, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - fixedToFloat_arrL32( &realBuffer_fx[0][0], &realBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - fixedToFloat_arrL32( &imagBuffer_fx[0][0], &imagBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - - if ( st->element_mode == IVAS_CPE_DFT ) - { - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); - } - if ( st->hBWE_FD != NULL ) - { - fixedToFloat_arr( st->hBWE_FD->old_input_lp_fx, st->hBWE_FD->old_input_lp, Q_new[n] - 1, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ) ); - fixedToFloat_arr( st->hBWE_FD->new_input_hp_fx, st->hBWE_FD->new_input_hp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); - fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); - // fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); - for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) - { - st->hBWE_FD->old_input[ii] = (float) st->hBWE_FD->old_input_fx[ii]; - } - } - fixedToFloat_arr( st->input_fx, st->input, 0 /* Q_input*/, L_FRAME48k ); - me2f_buf_16( st->buf_speech_enc_pe, st->exp_buf_speech_enc_pe, st->buf_speech_enc_pe_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - me2f_buf_16( st->buf_speech_enc, st->exp_buf_speech_enc, st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - me2f_buf_16( st->buf_synth, st->exp_buf_synth, st->buf_synth_flt, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); - IF( st->hTcxEnc != NULL ) - { - me2f_buf_16( st->buf_wspeech_enc, st->exp_buf_wspeech_enc, st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); - me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - } -#endif } /*------------------------------------------------------------------* @@ -834,7 +766,28 @@ ivas_error ivas_core_enc( diff_nBits = sub( diff_nBits, n ); } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( n = 0; n < n_CoreChannels; n++ ) + { + st = sts[n]; + fixedToFloat_arr( st->old_input_signal_fx, st->old_input_signal, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + if ( st->hBWE_FD != NULL ) + { + st->hBWE_FD->prev_Q_input_lp = Q_new[n] - 1; + // fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); + } + fixedToFloat_arr( st->input_fx, st->input, 0 /* Q_input*/, L_FRAME48k ); + me2f_buf_16( st->buf_speech_enc_pe, st->exp_buf_speech_enc_pe, st->buf_speech_enc_pe_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + me2f_buf_16( st->buf_speech_enc, st->exp_buf_speech_enc, st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + me2f_buf_16( st->buf_synth, st->exp_buf_synth, st->buf_synth_flt, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); + IF( st->hTcxEnc != NULL ) + { + me2f_buf_16( st->buf_wspeech_enc, st->exp_buf_wspeech_enc, st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); + me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + } + } +#endif #ifdef DEBUG_MODE_INFO for ( n = 0; n < n_CoreChannels; n++ ) { diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 7610e5cb8..0b43fca8b 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -61,13 +61,13 @@ ivas_error pre_proc_ivas( Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float **inp, /* o : ptr. to inp. signal in the current frame*/ - float *ener, /* o : residual energy from Levinson-Durbin */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q6 */ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ float epsP[M + 1], /* i/o: LP prediction errors */ Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ - float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ float old_wsp[], /* i : weighted input signal buffer */ const Word16 loc_harm, /* i : harmonicity flag */ @@ -546,8 +546,6 @@ ivas_error pre_proc_ivas( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 old_inp_16k_fx[L_INP], Q_old_inp_16k = -1; - Word32 ener_fx = 0; - Word16 new_inp_resamp16k_fx[L_FRAME16k]; Word16 Q_r[2] = { 0 }, exp_wsp; Word32 epsP_fx[M + 1] = { 0 }; Word16 old_wsp_fx[L_WSP], wsp_fx[L_FRAME + L_LOOK_12k8]; @@ -573,13 +571,13 @@ ivas_error pre_proc_ivas( if ( st->hBWE_FD != NULL ) { - floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); st->Q_old_wtda = -1; // This reset needs to be looked into } #endif IF( !flag_16k_smc ) { - error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, &ener_fx, + error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); @@ -637,13 +635,7 @@ ivas_error pre_proc_ivas( st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) - { - *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); - } - fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, *Q_new - 1, L_INP ); - fixedToFloat_arr( new_inp_resamp16k_fx, new_inp_resamp16k, Q_old_inp_16k, L_FRAME16k ); fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); fixedToFloat_arr( st->old_wsp_fx, st->old_wsp, 15 - st->exp_old_wsp, L_WSP_MEM ); @@ -654,10 +646,6 @@ ivas_error pre_proc_ivas( fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, *Q_new - 1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - if ( st->hBWE_FD != NULL ) - { - fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); - } if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) { @@ -1142,7 +1130,7 @@ ivas_error ivas_compute_core_buffers_fx( const Word16 input_frame, /* i : frame length */ const Word16 last_element_mode, /* i : last element mode */ const Word32 sr_core, /* i : core-coder sampling rate */ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ Word32 epsP_fx[M + 1], /* i/o: LP prediction errors */ diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 3cea45ea4..f01635fab 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -885,7 +885,7 @@ ivas_error pre_proc_front_ivas_fx( 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 */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ 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 */ @@ -903,9 +903,10 @@ ivas_error pre_proc_front_ivas_fx( 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 */ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ + Word16 *fft_buff_fx_q, /* 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 */ @@ -1005,8 +1006,6 @@ ivas_error pre_proc_front_ivas_fx( Word32 *signal32_in_fx; Word16 *inp_12k8_fx, *new_inp_12k8_fx; /* pointers to current frame and new data */ CLDFB_SCALE_FACTOR cldfbScale; - Word32 *enerBuffer_fx; - Word16 enerBuffer_exp; /*[CLDFB_NO_CHANNELS_MAX];*/ Word16 *temp1F_icatdmResampBuf_fx; Word16 *old_inp_16k_fx; Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ @@ -1053,9 +1052,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - enerBuffer_exp = 0; - move16(); - enerBuffer_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) ); old_inp_16k_fx = (Word16 *) malloc( 880 * sizeof( Word16 * ) ); mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); @@ -1306,25 +1302,25 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( EQ_16( element_mode, IVAS_SCE ) || ( EQ_16( element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - analysisCldfbEncoder_ivas_fx( st, signal32_in_fx, 11, input_frame, realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, &enerBuffer_exp, &cldfbScale ); + analysisCldfbEncoder_ivas_fx( st, signal32_in_fx, 11, input_frame, realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, enerBuffer_fx_exp, &cldfbScale ); } ELSE IF( ( EQ_16( element_mode, IVAS_CPE_TD ) && st->idchan == 0 ) || ( EQ_16( st->idchan, 1 ) && st->tdm_LRTD_flag ) ) { /* cldfb analysis only for pri. channel */ - analysisCldfbEncoder_ivas_fx( st, signal32_in_fx - NS2SA_FX2( input_Fs, L_MEM_RECALC_TBE_NS ), 11, input_frame, realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, &enerBuffer_exp, &cldfbScale ); + analysisCldfbEncoder_ivas_fx( st, signal32_in_fx - NS2SA_FX2( input_Fs, L_MEM_RECALC_TBE_NS ), 11, input_frame, realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, enerBuffer_fx_exp, &cldfbScale ); } ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - calculate_energy_buffer_ivas_fx( hCPE, enerBuffer_fx, st->cldfbAnaEnc->no_channels, input_Fs, &enerBuffer_exp ); + calculate_energy_buffer_ivas_fx( hCPE, enerBuffer_fx, st->cldfbAnaEnc->no_channels, input_Fs, enerBuffer_fx_exp ); } ELSE { set32_fx( enerBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX ); - enerBuffer_exp = 31; + *enerBuffer_fx_exp = 31; move16(); } - *q_re_im_buf = sub( 16, cldfbScale.lb_scale ); + *q_re_im_buf = sub( Q31, cldfbScale.lb_scale ); move16(); /*----------------------------------------------------------------* @@ -1530,7 +1526,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, 15 - old_inp_12k8_e, L_INP_MEM + L_FRAME ); // To be removed cldfbScale.hb_scale = cldfbScale.lb_scale; - fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); #endif #if 0 @@ -1570,14 +1565,16 @@ ivas_error pre_proc_front_ivas_fx( } Word16 Q_new; Word16 Scale_fac[2]; - Q_new = 15 - old_inp_12k8_e; + set16_fx( Scale_fac, 0, 2 ); + Q_new = sub( Q15, old_inp_12k8_e ); Word16 tmp16, scale = 0; + move16(); if ( hCPE != NULL && hCPE->hStereoDft != NULL ) { tmp16 = BASOP_Util_Divide3216_Scale( input_Fs, hCPE->hStereoDft->NFFT, &scale ); tmp16 = shr( tmp16, negate( add( 1, scale ) ) ); Word16 gb = find_guarded_bits_fx( tmp16 ); - Q_new -= gb; + Q_new = sub( Q_new, gb ); } #endif Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 - 1 ), st->q_Bin_E_old ) ); @@ -1601,11 +1598,20 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL( PS_fx, PS, Q_new + QSCALE - 2, 128 ); Etot = fixedToFloat( Etot_fx, Q8 ); // fixedToFloat_arr( fft_buff_fx, fft_buff, Q_new + QSCALE + Scale_fac[0] - 14 -1, 512 ); - for ( int i_sbfr = 0; i_sbfr < 2; i_sbfr++ ) +#endif + Word16 min_q = MAX_16, fft_q[2]; + FOR( int i_sbfr = 0; i_sbfr < 2; i_sbfr++ ) { - fixedToFloat_arr( fft_buff_fx + i_sbfr * L_FFT, fft_buff + i_sbfr * L_FFT, Q_new + Scale_fac[i_sbfr], L_FFT ); + fft_q[i_sbfr] = add( Q_new, Scale_fac[i_sbfr] ); + move16(); + min_q = s_min( min_q, fft_q[i_sbfr] ); + // fixedToFloat_arr( fft_buff_fx + i_sbfr * L_FFT, fft_buff + i_sbfr * L_FFT, Q_new + Scale_fac[i_sbfr], L_FFT ); } -#endif + FOR( int i_sbfr = 0; i_sbfr < 2; i_sbfr++ ) + { + Scale_sig( fft_buff_fx + i_sbfr * L_FFT, L_FFT, sub( min_q, fft_q[i_sbfr] ) ); + } + *fft_buff_fx_q = min_q; #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -1713,7 +1719,7 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { - sf_energySum[i] = enerBuffer_exp; + sf_energySum[i] = *enerBuffer_fx_exp; move16(); } @@ -1808,23 +1814,11 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 band_energies_LR_fx[2 * NB_BANDS] = { 0 }; /* energy in critical bands without minimum noise floor E_MIN */ Word16 band_energies_LR_fx_exp; /* energy in critical bands without minimum noise floor E_MIN */ - Word32 enerBuffer_fx_loc[CLDFB_NO_CHANNELS_MAX] = { 0 }; - Word16 enerBuffer_fx_exp; Word16 q_band_energies_LR = Q_factor_arrL( band_energies_LR, 2 * NB_BANDS ); band_energies_LR_fx_exp = 31 - q_band_energies_LR; floatToFixed_arrL( band_energies_LR, band_energies_LR_fx, ( 31 - band_energies_LR_fx_exp ), 2 * NB_BANDS ); -#ifdef MSAN_FIX - Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, st->cldfbAnaEnc->no_channels ); -#else - Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, CLDFB_NO_CHANNELS_MAX ); -#endif - enerBuffer_fx_exp = 31 - q_enerBuffer; -#ifdef MSAN_FIX - floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); -#else - floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); -#endif + Word16 normmsPeriodog_fx = Q31, zero_flag = 0; move16(); move16(); @@ -1852,29 +1846,16 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->msNoiseEst_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); move16(); #endif - perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); + perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } else { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 band_energies_fx_exp; /* energy in critical bands without minimum noise floor E_MIN */ - Word32 enerBuffer_fx_loc[CLDFB_NO_CHANNELS_MAX] = { 0 }; - Word16 enerBuffer_fx_exp; Word16 q_band_energies = Q_factor_arrL( band_energies, 2 * NB_BANDS ); band_energies_fx_exp = 31 - q_band_energies; floatToFixed_arrL( band_energies, band_energies_fx, ( 31 - band_energies_fx_exp ), 2 * NB_BANDS ); -#ifdef MSAN_FIX - Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, st->cldfbAnaEnc->no_channels ); -#else - Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, CLDFB_NO_CHANNELS_MAX ); -#endif - enerBuffer_fx_exp = 31 - q_enerBuffer; -#ifdef MSAN_FIX - floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); -#else - floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); -#endif #endif Word16 normmsPeriodog_fx = Q31, zero_flag = 0; move16(); @@ -1912,7 +1893,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); move16(); - perform_noise_estimation_enc_ivas_fx( band_energies_fx, band_energies_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); + perform_noise_estimation_enc_ivas_fx( band_energies_fx, band_energies_fx_exp, enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } } } @@ -2037,7 +2018,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_r[2] = { 0 }; Word16 epsP_l_loc[M + 1]; Word16 epsP_h_loc[M + 1]; - Word32 ener_fx; Q_new_loc = ( Q_factor_arr( old_inp_12k8, L_INP_12k8 ) - 1 ); // 1 is the guard bit // Q_new_loc = 0; /* Dynamic Q_new used above causes overflow issues */ for ( int k = 0; k < L_INP_12k8; k++ ) @@ -2079,7 +2059,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - 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, + 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_fx, lsf_new_fx, M, INT_FS_12k8 ); @@ -2097,8 +2077,6 @@ ivas_error pre_proc_front_ivas_fx( check_float = (float) check / power_2; epsP[idx] = check_float; } - check_float = (float) ener_fx / power_2; - *ener = check_float; free( old_inp_12k8_loc_fx ); @@ -2521,13 +2499,13 @@ ivas_error pre_proc_front_ivas_fx( if ( st->hBWE_FD != NULL ) { - floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); st->Q_old_wtda = -1; // This reset needs to be looked into } #endif /* Compute core-coder buffers at internal sampling rate */ - error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, &ener_fx, + error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, NULL ); @@ -2542,11 +2520,6 @@ ivas_error pre_proc_front_ivas_fx( st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) - { - *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); - } - fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); 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 ); @@ -2556,10 +2529,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - if ( st->hBWE_FD != NULL ) - { - fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); - } if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) { @@ -2569,9 +2538,9 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 q_speech_enc; - 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 ) ); + q_speech_enc = 0; 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 ); + // floatToFixed_arr( st->wspeech_enc_flt - 560, st->wspeech_enc - 560, q_speech_enc, 2 * 560 ); #endif smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, q_speech_enc, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -2710,7 +2679,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 - free( enerBuffer_fx ); free( old_inp_16k_fx ); free( mem_decim_dummy_fx ); free( temp1F_icatdmResampBuf_fx ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index d158ac537..291d412d8 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -92,9 +92,10 @@ ivas_error ivas_cpe_enc_fx( Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ Word32 old_inp_16k_fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ - Word16 fft_exp; + Word16 fft_buff_fx_q[CPE_CHANNELS]; /* FFT buffer */ + Word16 fft_buff_fx_final_q = MAX_16; #endif - float ener[CPE_CHANNELS]; /* residual energy from Levinson-Durbin */ + Word32 ener_fx[CPE_CHANNELS]; /* residual energy from Levinson-Durbin Q6 */ Word16 relE_fx[CPE_CHANNELS]; /* frame relative energy Q8 */ Word16 A_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes Q12 */ Word16 Aw_fx[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes Q12 */ @@ -103,25 +104,24 @@ ivas_error ivas_cpe_enc_fx( 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; + Word16 q_re_im_buf[CPE_CHANNELS]; + Word16 q_re_im_min = Q15; move16(); - float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ - 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 */ - 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 */ + float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ + 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 */ + 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 */ + Word32 enerBuffer_fx[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + Word16 enerBuffer_fx_exp[CPE_CHANNELS]; /* energy buffer */ #ifdef IVAS_FLOAT_FIXED Word16 currFlatness_fx[CPE_CHANNELS]; /* flatness parameter Q7 */ #endif - float fft_buff[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ - Word16 tdm_ratio_idx, tdm_ratio_idx_SM; /* temp. TD stereo parameters */ - Word16 tdm_SM_or_LRTD_Pri; /* temp. TD stereo parameters */ + Word16 tdm_ratio_idx, tdm_ratio_idx_SM; /* temp. TD stereo parameters */ + Word16 tdm_SM_or_LRTD_Pri; /* temp. TD stereo parameters */ Word16 nb_bits; /* number of DFT stereo side bits */ float fr_bands[CPE_CHANNELS][2 * NB_BANDS]; /* energy in frequency bands */ @@ -165,6 +165,8 @@ ivas_error ivas_cpe_enc_fx( * Initialization - general *-----------------------------------------------------------------*/ + set16_fx( q_re_im_buf, 0, CPE_CHANNELS ); + tdm_SM_or_LRTD_Pri = 0; tdm_ratio_idx = -1; tdm_ratio_idx_SM = -1; @@ -181,7 +183,7 @@ ivas_error ivas_cpe_enc_fx( #ifdef MSAN_FIX FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) { - set_zero( fft_buff[i], 2 * L_FFT ); + set16_zero_fx( fft_buff_fx[i], 2 * L_FFT ); } #endif /*------------------------------------------------------------------* @@ -375,6 +377,7 @@ ivas_error ivas_cpe_enc_fx( { floatToFixed_arr( sts[n]->input_buff, sts[n]->input_buff_fx, q_inp, 1965 ); } + floatToFixed_arr( sts[0]->buf_speech_enc_flt, sts[0]->buf_speech_enc, q_inp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); #endif stereo_switching_enc_fx( hCPE, sts[0]->old_input_signal_fx, input_frame, q_inp ); @@ -600,9 +603,6 @@ ivas_error ivas_cpe_enc_fx( { floatToFixed_arr( sts[1]->old_inp_12k8, sts[1]->old_inp_12k8_fx, 0, L_INP_MEM ); } - floatToFixed_arrL( hCPE->hStereoDft->output_mem_res_8k, hCPE->hStereoDft->output_mem_res_8k_fx, 16, STEREO_DFT_OVL_8k ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_fx, 16, STEREO_DFT_OVL_MAX ); - floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_12k8, hCPE->hStereoDft->output_mem_dmx_12k8_fx, 16, STEREO_DFT_OVL_12k8 ); /*flt2fix end*/ #endif #ifdef IVAS_FLOAT_FIXED @@ -614,13 +614,15 @@ ivas_error ivas_cpe_enc_fx( scale_sig32( hCPE->hStereoDft->Spd_R_smooth_fx, STEREO_DFT_N_32k_ENC / 2, temp ); hCPE->hStereoDft->Spd_R_smooth_fx_e = sub( hCPE->hStereoDft->Spd_R_smooth_fx_e, temp ); - stereo_dft_hybrid_ITD_flag( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max ); + stereo_dft_hybrid_ITD_flag_fx( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max ); /* Time Domain ITD compensation using extrapolation */ stereo_td_itd_fx( hCPE->hStereoDft->hItd, hCPE->hStereoDft->input_mem_itd_fx, hCPE->hStereoDft->q_input_mem_itd, hCPE->hStereoDft->hConfig->hybrid_itd_flag, hCPE->hStereoDft->dft_ovl, sts, input_frame, hCPE->input_mem_fx, hCPE->q_input_mem ); stereo_dft_enc_analyze_fx( sts, CPE_CHANNELS, input_frame, hCPE->hStereoDft, NULL, hCPE->hStereoDft->DFT_fx, hCPE->hStereoDft->DFT_fx_e, hCPE->input_mem_fx, hCPE->q_input_mem ); #else + stereo_dft_hybrid_ITD_flag( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max ); + /* Time Domain ITD compensation using extrapolation */ stereo_td_itd( hCPE->hStereoDft->hItd, hCPE->hStereoDft->input_mem_itd, hCPE->hStereoDft->hConfig->hybrid_itd_flag, hCPE->hStereoDft->dft_ovl, sts, input_frame, hCPE->input_mem ); @@ -796,9 +798,6 @@ ivas_error ivas_cpe_enc_fx( fixedToFloat_arr( sts[1]->old_inp_12k8_fx, sts[1]->old_inp_12k8, 0, L_INP_MEM ); fixedToFloat_arrL( old_inp_12k8_fx[1] + L_INP_MEM + out_12k8_start_ind[1], old_inp_12k8[1] + L_INP_MEM + out_12k8_start_ind[1], 16, out_12k8_end_ind[1] - out_12k8_start_ind[1] ); } - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); - fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); /*fix2flt end*/ #endif #else @@ -847,20 +846,10 @@ ivas_error ivas_cpe_enc_fx( Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_12k8[n], old_inp_16k[n], - &ener[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], - realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf, old_wsp[n], pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer[n], - fft_buff[n], fft_buff_fx[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - 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 + &ener_fx[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[n], old_wsp[n], pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], + fft_buff_fx[n], &fft_buff_fx_q[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 ); + q_re_im_min = s_min( q_re_im_buf[n], q_re_im_min ); #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], @@ -873,6 +862,17 @@ ivas_error ivas_cpe_enc_fx( } } + /*making Q common*/ + FOR( n = 0; n < n_CoreChannels; n++ ) + { + fft_buff_fx_final_q = s_min( fft_buff_fx_final_q, fft_buff_fx_q[n] ); + } + fft_buff_fx_final_q = sub( fft_buff_fx_final_q, 2 ); // headroom + FOR( n = 0; n < n_CoreChannels; n++ ) + { + Scale_sig( fft_buff_fx[n], 2 * L_FFT, sub( fft_buff_fx_final_q, fft_buff_fx_q[n] ) ); + } + /* sanity check -> DTX not supported for more than one SCEs/CPEs */ if ( st_ivas->nSCE + st_ivas->nCPE > 1 ) { @@ -899,28 +899,7 @@ ivas_error ivas_cpe_enc_fx( if ( hCPE->element_mode == IVAS_CPE_MDCT && hEncoderConfig->Opt_DTX_ON ) { #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 max_e = -16, tmp_e, tmp_e2; - Word16 i; - - for ( i = 0; i < 2 * L_FFT; i++ ) - { - f2me_16( fft_buff[0][i], &fft_buff_fx[0][i], &tmp_e ); - f2me_16( fft_buff[1][i], &fft_buff_fx[1][i], &tmp_e2 ); - tmp_e = max( tmp_e, tmp_e2 ); - max_e = ( max_e > tmp_e ) ? max_e : tmp_e; - } - max_e += 2; - for ( i = 0; i < 2 * L_FFT; i++ ) - { - f2me_16( fft_buff[0][i], &fft_buff_fx[0][i], &tmp_e ); - f2me_16( fft_buff[1][i], &fft_buff_fx[1][i], &tmp_e2 ); - fft_buff_fx[0][i] = shr( fft_buff_fx[0][i], max_e - tmp_e ); - fft_buff_fx[1][i] = shr( fft_buff_fx[1][i], max_e - tmp_e2 ); - } - fft_exp = max_e; -#endif - stereoFdCngCoherence_fx( sts, hCPE->last_element_mode, fft_buff_fx, fft_exp ); + stereoFdCngCoherence_fx( sts, hCPE->last_element_mode, fft_buff_fx, sub( 15, fft_buff_fx_final_q ) /*fft exp*/ ); #else stereoFdCngCoherence( sts, hCPE->last_element_mode, fft_buff ); #endif @@ -992,7 +971,11 @@ ivas_error ivas_cpe_enc_fx( if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED if ( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) +#else + IF( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1182,8 +1165,18 @@ ivas_error ivas_cpe_enc_fx( /*----------------------------------------------------------------* * Core Encoder *----------------------------------------------------------------*/ - - if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, ener, A_fx, Aw_fx, epsP, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) + FOR( n = 0; n < n_CoreChannels; n++ ) + { + IF( NE_16( q_re_im_buf[n], q_re_im_min ) ) + { + FOR( Word16 i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, sub( q_re_im_min, q_re_im_buf[n] ) ); + scale_sig32( imagBuffer_fx[n][i], CLDFB_NO_CHANNELS_MAX, sub( q_re_im_min, q_re_im_buf[n] ) ); + } + } + } + if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, ener_fx, A_fx, Aw_fx, epsP, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_min, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -2252,7 +2245,11 @@ ivas_error create_cpe_enc( if ( hCPE->element_mode == IVAS_CPE_DFT ) { +#ifndef IVAS_FLOAT_FIXED if ( ( error = stereo_dft_enc_create( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ) != IVAS_ERR_OK ) +#else + if ( ( error = stereo_dft_enc_create_fx( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2323,7 +2320,11 @@ ivas_error create_cpe_enc( if ( hCPE->element_mode == IVAS_CPE_MDCT && element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED if ( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) +#else + IF( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2607,7 +2608,7 @@ ivas_error create_cpe_enc_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { - IF( NE_32( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -2660,11 +2661,19 @@ FOR( n = 0; n < CPE_CHANNELS; n++ ) } } -IF( hCPE->hStereoDft != NULL ) +#ifndef IVAS_FLOAT_FIXED +if ( hCPE->hStereoDft != NULL ) { stereo_dft_enc_destroy( &hCPE->hStereoDft ); hCPE->hStereoDft = NULL; } +#else + IF( hCPE->hStereoDft != NULL ) + { + stereo_dft_enc_destroy_fx( &hCPE->hStereoDft ); + hCPE->hStereoDft = NULL; + } +#endif IF( hCPE->hStereoTD != NULL ) { @@ -2672,11 +2681,19 @@ IF( hCPE->hStereoTD != NULL ) hCPE->hStereoTD = NULL; } -IF( hCPE->hStereoMdct != NULL ) +#ifndef IVAS_FLOAT_FIXED +if ( hCPE->hStereoMdct != NULL ) { stereo_mdct_enc_destroy( &hCPE->hStereoMdct ); hCPE->hStereoMdct = NULL; } +#else + IF( hCPE->hStereoMdct != NULL ) + { + stereo_mdct_enc_destroy_fx( &hCPE->hStereoMdct ); + hCPE->hStereoMdct = NULL; + } +#endif IF( hCPE->hStereoTCA != NULL ) { diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 852948fd0..697f97de1 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -754,28 +754,6 @@ ivas_error front_vad_spar_fx( Word16 old_pitch; ivas_error error; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - float input[L_FRAME48k] = { 0 }; - float fr_bands[1][2 * NB_BANDS]; - float Etot[1]; - float lf_E[1][2 * VOIC_BINS]; - float band_energies[2 * NB_BANDS]; - float tmpN[NB_BANDS], tmpE[NB_BANDS]; - float corr_shift; - float A[NB_SUBFR16k * ( M + 1 )], Aw[NB_SUBFR16k * ( M + 1 )]; - float epsP[M + 1]; - float lsp_new[M]; - float lsp_mid[M]; - float cor_map_sum; - float non_staX; - float S_map[L_FFT / 2]; - // float *inp_12k8; - float old_wsp[L_WSP]; - float *wsp; - float relE; - float PS[L_FRAME / 2]; -#endif - push_wmops( "front_vad_SPAR" ); error = IVAS_ERR_OK; move32(); @@ -788,23 +766,28 @@ ivas_error front_vad_spar_fx( /*------------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ - // inp_12k8 = hFrontVad->buffer_12k8; - Word16 Q_bands = Q31, tmp1; - Word16 Q_inp_12k8 = hFrontVad->q_buffer_12k8; + + Word16 Q_add = 0; + move16(); + Word16 front_create_flag = 0; + move16(); + Word16 Qband = -1; + move16(); + Word16 Q_bands = Q9; + move16(); + + Scale_sig32( hFrontVad->hNoiseEst->ave_enr_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); + Scale_sig32( hFrontVad->hNoiseEst->ave_enr2_fx, NB_BANDS, ( Q_bands + QSCALE ) - hFrontVad->hNoiseEst->ave_enr_q ); + hFrontVad->hNoiseEst->ave_enr_q = ( Q_bands + QSCALE ); move16(); + Word16 tmp1; + Word16 Q_inp_12k8 = hFrontVad->q_buffer_12k8; move16(); inp_12k8_fx = hFrontVad->buffer_12k8_fx; - mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q9, L_WSP_MEM ); - floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q9, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q9, 3 ); -#endif MVR2R_WORD16( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); - wsp = old_wsp + L_WSP_MEM; wsp_fx = old_wsp_fx + L_WSP_MEM; st->core_brate = -1; /* updated in dtx() */ @@ -815,9 +798,7 @@ ivas_error front_vad_spar_fx( /*------------------------------------------------------------------* * compensate for SPAR filterbank delay *-----------------------------------------------------------------*/ - Q_bands = Q9; - move16(); - st->input = input; + st->input_fx = input_fx; Copy_Scale_sig32_16( omni_in, st->input_fx, input_frame, Q16 - Q11 ); @@ -848,35 +829,20 @@ ivas_error front_vad_spar_fx( } Q_inp = s; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->input_fx, st->input, Q_inp, input_frame ); -#endif - Word16 Q_add = 0; - move16(); + + /*------------------------------------------------------------------* * Front-VAD *-----------------------------------------------------------------*/ -#if 0 - if ( ( error = front_vad( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands, Etot, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies, &PS[0], &st->Bin_E[0] ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - // Word16 n_chan = 1; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 front_create_flag = 0; - move16(); - Word16 Qband = -1; - move16(); + Word16 scale; + Word16 Q_new_old = add( sub( Q_inp, Qband ), Q_add ); - Word16 band_ener_guardbits = find_guarded_bits_fx( 2 * NB_BANDS ); - floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_new_old + QSCALE + 2, 20 ); - floatToFixed_arrL( hFrontVad->hNoiseEst->enrO, hFrontVad->hNoiseEst->enrO_fx, Q_new_old + QSCALE + 2, 20 ); + + Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_bckr ) ); // Q_new_old +QSCALE +2 + Scale_sig32( hFrontVad->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_enr ) ); + hFrontVad->hNoiseEst->q_enr = add( Q_new_old, QSCALE + 2 ); + move16(); st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; -#ifndef MSAN_FIX - floatToFixed_arrL( &band_energies[0], &band_energies_fx[0], Q_new_old + QSCALE + 2, 40 ); -#endif -#endif Word16 Q_buffer = hFrontVad->q_buffer_12k8; move16(); Scale_sig( hFrontVad->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp, hFrontVad->q_mem_decim ) ); @@ -896,37 +862,16 @@ ivas_error front_vad_spar_fx( { Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( fr_bands_fx[0], fr_bands[0], Q_buffer + QSCALE + 2, 40 ); - fixedToFloat_arrL( lf_E_fx[0], lf_E[0], Q_buffer + QSCALE, 148 ); - fixedToFloat_arrL( PS_fx, PS, Q_buffer + QSCALE, 128 ); - Etot[0] = fixedToFloat( Etot_fx[0], Q8 ); - fixedToFloat_arrL( &band_energies_fx[0], &band_energies[0], Q_buffer + QSCALE + 2 - band_ener_guardbits, 40 ); -#endif -#endif + Scale_sig32( fr_bands_fx[0], 40, sub( ( Q_bands + QSCALE ), add( Q_buffer, QSCALE + 2 ) ) ); Word32 e_min_scaled; e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands, QSCALE ) ) ), 1 ), 1 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arrL( fr_bands[0], fr_bands_fx[0], Q_bands + QSCALE, 2 * NB_BANDS ); - floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_bands + QSCALE, NB_BANDS ); -#ifndef MSAN_FIX - floatToFixed_arrL( tmpE, tmpE_fx, Q_bands + QSCALE, NB_BANDS ); -#endif - Etot_fx[0] = (Word16) ( Etot[0] * ONE_IN_Q8 ); -#endif + Scale_sig32( hFrontVad->hNoiseEst->bckr_fx, 20, sub( Q_bands + QSCALE, add( Q_new_old, QSCALE + 2 ) ) ); + hFrontVad->hNoiseEst->q_bckr = Q_bands + QSCALE; + move16(); noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( hFrontVad->hNoiseEst->bckr_fx, hFrontVad->hNoiseEst->bckr, Q_bands + Q7, NB_BANDS ); - fixedToFloat_arrL( tmpN_fx, tmpN, Q_bands + QSCALE, 20 ); - fixedToFloat_arrL( tmpE_fx, tmpE, Q_bands + QSCALE, 20 ); -#endif corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - corr_shift = fixedToFloat( corr_shift_fx, Q15 ); -#endif dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); /* linear prediction analysis */ @@ -934,9 +879,13 @@ ivas_error front_vad_spar_fx( alw_pitch_lag_12k8[1] = st->old_pitch_la; alw_voicing_fx[0] = st->voicing_fx[2]; alw_voicing_fx[1] = st->voicing_fx[2]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + move16(); + move16(); + move16(); + move16(); Word16 Q_r[2] = { 0 }; -#endif + move16(); + move16(); Scale_sig( inp_12k8_fx - 2 * L_FILT_MAX, 2 * L_FILT_MAX, sub( s_min( Q_inp_12k8, hFrontVad->q_mem_decim ), hFrontVad->q_mem_decim ) ); Scale_sig( inp_12k8_fx, 3 * L_FRAME / 2, sub( s_min( Q_inp_12k8, hFrontVad->q_mem_decim ), Q_inp_12k8 ) ); Q_inp_12k8 = s_min( hFrontVad->q_mem_decim, hFrontVad->q_buffer_12k8 ); @@ -946,43 +895,20 @@ ivas_error front_vad_spar_fx( move16(); analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( Word16 i = 0; i <= M; i++ ) + FOR( Word16 i = 0; i <= M; i++ ) { - epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); + epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); // Q_r[0] + move32(); } - fixedToFloat_arrL( epsP_fx, epsP, Q_r[0], M + 1 ); - fixedToFloat_arr( A_fx, A, Q14, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); - fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q9, 3 ); -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Etot_fx[0] = float_to_fix16( Etot[0], Q8 ); -#endif relE_fx = sub( Etot_fx[0], st->lp_speech_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - relE = fixedToFloat( relE_fx, Q8 ); -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#ifdef MSAN_FIX - floatToFixed_arr( A, A_fx, Q12, ( L_FRAME / L_SUBFR ) * ( M + 1 ) ); -#else - floatToFixed_arr( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); -#endif // MSAN_FIX - st->mem_wsp_fx = (Word16) floatToFixed( st->mem_wsp, Q_inp_12k8 ); -#endif + Scale_sig( A_fx, ( L_FRAME / L_SUBFR ) * ( M + 1 ), -2 ); // Q12 + st->mem_wsp_fx = (Word16) shl_sat( st->mem_wsp_fx, Q_inp_12k8 - st->mem_wsp_q ); + st->mem_wsp_q = Q_inp_12k8; + move16(); ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( wsp_fx, wsp, Q_inp_12k8, 368 ); - fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); -#endif - IF( st->vad_flag == 0 ) { /* reset the OL pitch tracker memories during inactive frames */ @@ -990,133 +916,75 @@ ivas_error front_vad_spar_fx( } old_pitch = st->pitch[1]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( wsp, wsp_fx, Q8, 368 ); - floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q8, 115 ); - floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q8, 3 ); - corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); - // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); - relE_fx = (Word16) floatToFixed( relE, Q8 ); -#endif + move16(); + Scale_sig( wsp_fx, 368, sub( Q8, Q_inp_12k8 ) ); 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 ); - - // pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q8, 115 ); - fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q8, 3 ); -#endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; -#if 0 - /* 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 ); -#else - // StableHighPitchDetect( &flag_spitch, st->pitch, st->voicing, st->Bin_E, wsp, st->localVAD, &st->voicing_sm, &st->voicing0_sm, &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); - floatToFixed_arr( wsp, wsp_fx, Q9, 368 ); - - Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); - + move16(); + Scale_sig( wsp_fx, 368, Q9 - Q8 ); StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q12, st->lgBin_E_fx ); - - Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); -#endif - if ( st->hSpMusClas != NULL ) + IF( st->hSpMusClas != NULL ) { - int16_t dummy_int; + Word16 dummy_int; dummy_int = 0; -#if 0 - loc_harm = multi_harm( st->Bin_E, hFrontVad->hNoiseEst->old_S, hFrontVad->hNoiseEst->cor_map, &hFrontVad->hNoiseEst->multi_harm_limit, st->total_brate, st->bwidth, ( st->hGSCEnc != NULL ) ? &st->hGSCEnc->cor_strong_limit : &dummy_int, &st->hSpMusClas->mean_avr_dyn, &st->hSpMusClas->last_sw_dyn, &cor_map_sum, &dummy, S_map ); -#else + move16(); loc_harm = multi_harm_ivas_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, ( st->hGSCEnc != NULL ) ? &st->hGSCEnc->cor_strong_limit : &dummy_int, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); - - cor_map_sum = fixedToFloat( cor_map_sum_fx, Q8 ); -#endif } -#if 0 - noise_est( st, old_pitch, tmpN, epsP, Etot[0], Etot[0] - hFrontVad->lp_speech, corr_shift, tmpE, fr_bands[0], &cor_map_sum, &ncharX, &sp_div, &non_staX, &loc_harm, lf_E[0], &hFrontVad->hNoiseEst->harm_cor_cnt, hFrontVad->hNoiseEst->Etot_l_lp, &dummy, S_map, NULL, hFrontVad, hFrontVad->ini_frame ); -#else - // noise_est( st, old_pitch, tmpN, epsP, Etot[0], Etot[0] - hFrontVad->lp_speech, corr_shift, tmpE, fr_bands[0], &cor_map_sum, &ncharX, &sp_div, &non_staX, &loc_harm, lf_E[0], &hFrontVad->hNoiseEst->harm_cor_cnt, hFrontVad->hNoiseEst->Etot_l_lp, &dummy, S_map, NULL, hFrontVad, hFrontVad->ini_frame ); - Q_esp = Q_factor_arrL( epsP, M + 1 ); - floatToFixed_arrL( epsP, epsP_fx, Q_esp, M + 1 ); + scale = getScaleFactor32( epsP_fx, M + 1 ); + Q_esp = add( Q_r[0], scale ); + Scale_sig32( epsP_fx, M + 1, scale ); FOR( Word16 i = 0; i <= M; i++ ) { L_Extract( epsP_fx[i], &epsP_h[i], &epsP_l[i] ); } Q_bands = Q9; - - floatToFixed_arrL( lf_E[0], lf_E_fx[0], Q_bands + QSCALE - 2, 148 ); - floatToFixed_arrL( hFrontVad->hNoiseEst->fr_bands1, hFrontVad->hNoiseEst->fr_bands1_fx, Q_bands + QSCALE, NB_BANDS ); - floatToFixed_arrL( hFrontVad->hNoiseEst->fr_bands2, hFrontVad->hNoiseEst->fr_bands2_fx, Q_bands + QSCALE, NB_BANDS ); - floatToFixed_arrL( hFrontVad->hNoiseEst->ave_enr, hFrontVad->hNoiseEst->ave_enr_fx, Q_bands + QSCALE, NB_BANDS ); - floatToFixed_arrL( hFrontVad->hNoiseEst->ave_enr2, hFrontVad->hNoiseEst->ave_enr2_fx, Q_bands + QSCALE, NB_BANDS ); - - corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); - floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_bands + QSCALE, NB_BANDS ); + move16(); + Scale_sig32( lf_E_fx[0], 148, ( Q_bands + QSCALE - 2 ) - ( Q_buffer + QSCALE ) ); noise_est_ivas_fx( st, old_pitch, tmpN_fx, epsP_h, epsP_l, Etot_fx[0], Etot_fx[0] - hFrontVad->lp_speech_fx, corr_shift_fx, tmpE_fx, fr_bands_fx[0], &cor_map_sum_fx, NULL, &sp_div_fx, &Q_sp_div, &non_staX_fx, &loc_harm, lf_E_fx[0], &hFrontVad->hNoiseEst->harm_cor_cnt, hFrontVad->hNoiseEst->Etot_l_lp_fx, hFrontVad->hNoiseEst->Etot_v_h2_fx, &hFrontVad->hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_bands, e_min_scaled, &sp_floor, S_map_fx, NULL, hFrontVad, hFrontVad->ini_frame ); - fixedToFloat_arrL( hFrontVad->hNoiseEst->fr_bands1_fx, hFrontVad->hNoiseEst->fr_bands1, Q_bands + QSCALE, NB_BANDS ); - fixedToFloat_arrL( hFrontVad->hNoiseEst->fr_bands2_fx, hFrontVad->hNoiseEst->fr_bands2, Q_bands + QSCALE, NB_BANDS ); - fixedToFloat_arrL( hFrontVad->hNoiseEst->ave_enr_fx, hFrontVad->hNoiseEst->ave_enr, Q_bands + QSCALE, NB_BANDS ); - fixedToFloat_arrL( hFrontVad->hNoiseEst->ave_enr2_fx, hFrontVad->hNoiseEst->ave_enr2, Q_bands + QSCALE, NB_BANDS ); - fixedToFloat_arrL( hFrontVad->hNoiseEst->bckr_fx, hFrontVad->hNoiseEst->bckr, Q_bands + Q7, NB_BANDS ); - cor_map_sum = fixedToFloat( cor_map_sum_fx, Q8 ); - non_staX = fixedToFloat( non_staX_fx, Q8 ); - fixedToFloat_arr( S_map_fx, S_map, Q7, 128 ); -#endif -#if 0 - vad_param_updt( st, corr_shift, corr_shift, A, st->pitch[1], &hFrontVad, 1 ); -#else MVR2R_WORD16( st->pitch, st->pitch, 3 ); - corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); -#ifdef MSAN_FIX - floatToFixed_arr( A, A_fx, Q12, ( L_FRAME / L_SUBFR ) * ( M + 1 ) ); -#else - floatToFixed_arr( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); -#endif // MSAN_FIX vad_param_updt_fx( st, st->pitch[1], corr_shift_fx, corr_shift_fx, A_fx, &hFrontVad, 1 ); -#endif /* 1st stage speech/music classification (GMM model) */ /* run only to get 'high_lpn_flag' parameter */ -#if 0 - ivas_smc_gmm( st, NULL, localVAD_HE_SAD[0], Etot[0], lsp_new, cor_map_sum, epsP, PS, non_staX, relE, &high_lpn_flag, flag_spitch ); -#else SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; -#if 1 - cor_map_sum_fx = float_to_fix16( cor_map_sum, Q8 ); - Word16 non_sta_fx = float_to_fix16( non_staX, Q6 ); - Word16 Etot_fx_0 = float_to_fix16( Etot[0], Q8 ); - floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - relE_fx = float_to_fix16( relE, 8 ); - 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 ); -#endif + Word16 non_sta_fx = shr( non_staX_fx, Q2 ); // Q8->Q6 + Word16 Etot_fx_0 = Etot_fx[0]; + move16(); + scale = getScaleFactor32( PS_fx, 128 ); + Word16 Qfact_PS = add( add( Q_buffer, QSCALE ), scale ); + Scale_sig32( PS_fx, 128, scale ); 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 */ ivas_long_enr_fx( st, -1, localVAD_HE_SAD[0], high_lpn_flag, &hFrontVad, 1, localVAD_HE_SAD, Etot_fx ); /* increase ini_frame counter */ - hFrontVad->ini_frame = min( hFrontVad->ini_frame + 1, MAX_FRAME_COUNTER ); + hFrontVad->ini_frame = min( add( hFrontVad->ini_frame, 1 ), MAX_FRAME_COUNTER ); st->ini_frame = hFrontVad->ini_frame; - + move16(); hSpar->front_vad_flag = st->vad_flag; + move16(); hSpar->front_vad_dtx_flag = 1; + move16(); if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) { hSpar->front_vad_dtx_flag = 0; + move16(); } hSpar->force_front_vad = 1; + move16(); st->last_core = 0; + move16(); } - else + ELSE { hSpar->front_vad_flag = 1; + move16(); hSpar->front_vad_dtx_flag = 0; + move16(); hSpar->force_front_vad = 0; + move16(); } pop_wmops(); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 4087e6786..0d67347fd 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -440,36 +440,34 @@ ivas_error ivas_ism_enc_fx( float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 16kHz */ #endif Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */ - float ener[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin */ + Word32 ener_fx[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin Q6 */ Word16 relE_fx[MAX_NUM_OBJECTS][1]; /* frame relative energy, Q8 */ - 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 */ - 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(); + 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 */ + 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) */ 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 */ - 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 */ - 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 q_re_im_buf[MAX_NUM_OBJECTS]; + float old_wsp[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */ + 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 */ + 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 */ + Word32 enerBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + Word16 enerBuffer_fx_exp[MAX_NUM_OBJECTS][1]; /* energy buffer */ + Word16 currFlatness_fx[1]; /* flatness parameter */ + Word16 fft_buff_fx[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ + Word16 fft_buff_fx_q[MAX_NUM_OBJECTS][1]; /* 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; @@ -487,6 +485,8 @@ ivas_error ivas_ism_enc_fx( error = IVAS_ERR_OK; move32(); + set16_fx( q_re_im_buf, 0, MAX_NUM_OBJECTS ); + dtx_flag = 0; sid_flag = 0; flag_noisy_speech = 0; @@ -586,20 +586,9 @@ ivas_error ivas_ism_enc_fx( Scale_sig( &A_fx[sce_id][0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[sce_id][0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], - &ener[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], - realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf, old_wsp[sce_id][0], pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], - fft_buff[sce_id][0], fft_buff_fx[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands, Etot_LR_fx, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - 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 + &ener_fx[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[sce_id], 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_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], + fft_buff_fx[sce_id][0], &fft_buff_fx_q[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 ); IF( NE_32( error, IVAS_ERR_OK ) ) { @@ -786,7 +775,7 @@ ivas_error ivas_ism_enc_fx( test(); IF( !dtx_flag || ( dtx_flag && EQ_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) ) { - IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], ener[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], q_re_im_buf[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 560fac4b9..f82d245ef 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -68,19 +68,17 @@ ivas_error ivas_sce_enc_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ - float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ - float ener[1]; /* residual energy from Levinson-Durbin */ - float epsP[1][M + 1]; /* LP prediction errors */ - float realBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ - float imagBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ - float old_wsp[1][L_WSP]; /* old weighted input signal */ - float enerBuffer[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ - float fft_buff[1][2 * L_FFT]; /* FFT buffer */ - float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ - float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion + float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ + float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ + float epsP[1][M + 1]; /* LP prediction errors */ + float old_wsp[1][L_WSP]; /* old weighted input signal */ + float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ + float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ #endif + Word32 ener_fx[1]; /* residual energy from Levinson-Durbin Q6 */ + Word32 enerBuffer_fx[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + Word16 enerBuffer_fx_exp[1]; /* energy buffer */ 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 */ @@ -102,6 +100,7 @@ ivas_error ivas_sce_enc_fx( Word16 loc_harm[1]; /* harmonicity flag */ Word16 vad_flag_dtx[1]; /* HE-SAD flag with additional DTX HO */ Word16 fft_buff_fx[1][2 * L_FFT]; /* FFT buffer */ + Word16 fft_buff_fx_q[1]; /* FFT buffer */ Word16 localVAD_HE_SAD[1]; /* local HE SAD */ SCE_ENC_HANDLE hSCE; Encoder_State *st; @@ -244,21 +243,11 @@ ivas_error ivas_sce_enc_fx( Scale_sig( &A_fx[0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_12k8[0], old_inp_16k[0], - &ener[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], - realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp[0], pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer[0], - 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, + &ener_fx[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_fx[0], &enerBuffer_fx_exp[0], + fft_buff_fx[0], &fft_buff_fx_q[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 - 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], @@ -353,7 +342,7 @@ ivas_error ivas_sce_enc_fx( * Encoder *----------------------------------------------------------------*/ - IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, ener, A_fx, Aw_fx, epsP, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer, fft_buff, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, ener_fx, A_fx, Aw_fx, epsP, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6339bc639..3f668f8df 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -670,14 +670,12 @@ static ivas_error ivas_spar_cov_md_process_fx( Word16 i, j, i_ts, b, table_idx; Word16 active_w_vlbr; /* note: the actual dimensions of matrixes correspond to num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); */ -#ifdef IVAS_FLOAT_FIXED Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; Word32 cov_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 cov_dtx_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; -#endif ivas_error error; error = IVAS_ERR_OK; @@ -757,7 +755,6 @@ static ivas_error ivas_spar_cov_md_process_fx( ivas_enc_cov_handler_process_fx( hSpar->hCovEnc, ppIn_FR_real_fx, ppIn_FR_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( i = 0; i < nchan_inp; i++ ) { free( q_cov_real[i] ); @@ -765,7 +762,6 @@ static ivas_error ivas_spar_cov_md_process_fx( free( q_cov_dtx_real[i] ); q_cov_dtx_real[i] = NULL; } -#endif test(); IF( GT_16( nchan_transport, 1 ) && LE_16( nchan_transport, ( FOA_CHANNELS - 1 ) ) ) { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 8ca0113c3..11e585cf5 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -149,6 +149,7 @@ static void ivas_quant_pred_coeffs_per_band_fx( ivas_band_coeffs_t *pband_coeffs * Allocate and initialize SPAR MD encoder handle *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_open( ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -225,7 +226,7 @@ ivas_error ivas_spar_md_enc_open( return error; } -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_spar_md_enc_open_fx( ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -268,6 +269,7 @@ ivas_error ivas_spar_md_enc_open_fx( } } } + hMdEnc->q_mixer_mat_fx = 0; IF( ( error = ivas_spar_md_enc_init_fx( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 74a6bc8eb..7a178771f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -203,12 +203,12 @@ typedef struct stereo_dft_enc_data_struct const float *dft_trigo_32k; #endif Word16 dft_trigo_step; +#ifndef IVAS_FLOAT_FIXED float output_mem_res_8k[STEREO_DFT_OVL_8k]; /*I/O channel buffers */ float output_mem_dmx[STEREO_DFT_OVL_MAX]; float output_mem_dmx_12k8[STEREO_DFT_OVL_12k8]; -#ifndef IVAS_FLOAT_FIXED float output_mem_dmx_16k_shb[STEREO_DFT_OVL_16k]; float output_mem_dmx_32k[STEREO_DFT_OVL_32k]; /*can hold 16, 12.8 or 32kHz signals*/ float output_mem_dmx_16k[STEREO_DFT_OVL_16k]; /*can hold 16, 12.8 or 32kHz signals*/ @@ -250,19 +250,28 @@ typedef struct stereo_dft_enc_data_struct /* Stereo CNG */ #ifndef IVAS_FLOAT_FIXED float sidSideGain[STEREO_DFT_ERB4_BANDS]; -#endif float win_ana_energy; - Word32 sidSideGain_fx[STEREO_DFT_ERB4_BANDS]; // Q31? - Word16 win_ana_energy_fx; // Q15 -#ifndef IVAS_FLOAT_FIXED float xspec_smooth[STEREO_DFT_N_32k_ENC]; - float sid_gipd; - float prev_sid_gipd; float Spd_L_smooth[STEREO_DFT_N_32k_ENC / 2]; float Spd_R_smooth[STEREO_DFT_N_32k_ENC / 2]; + float sid_gipd; +#else + Word32 sidSideGain_fx[STEREO_DFT_ERB4_BANDS]; // Q31? + Word16 win_ana_energy_fx; // Q15 + Word32 xspec_smooth_fx[STEREO_DFT_N_32k_ENC]; // Q(31 - xspec_smooth_fx_e) + Word16 xspec_smooth_fx_e[STEREO_DFT_N_32k_ENC]; + Word32 Spd_L_smooth_fx[STEREO_DFT_N_32k_ENC / 2]; // Q(31 - Spd_L_smooth_fx_e) + Word16 Spd_L_smooth_fx_e; + Word32 Spd_R_smooth_fx[STEREO_DFT_N_32k_ENC / 2]; // Q(31 - Spd_R_smooth_fx_e) + Word16 Spd_R_smooth_fx_e; + Word32 sid_gipd_fx; // Q13 #endif Word16 coh_fade_counter; - Word32 prev_sid_gipd_fx; // Q13 +#ifndef IVAS_FLOAT_FIXED + float prev_sid_gipd; +#else + Word32 prev_sid_gipd_fx; // Q13 +#endif Word16 prev_sid_no_ipd_flag; /*IPD*/ @@ -395,18 +404,11 @@ typedef struct stereo_dft_enc_data_struct Word16 dot_prod_img_smooth_fx_e[STEREO_DFT_BAND_MAX]; Word32 ipd_buf_fx[STEREO_DFT_BAND_MAX][STEREO_DFT_IPD_BUF_LEN]; // Q13 Word32 prev_gipd_fx; // Q13 - Word32 xspec_smooth_fx[STEREO_DFT_N_32k_ENC]; // Q(31 - xspec_smooth_fx_e) - Word16 xspec_smooth_fx_e[STEREO_DFT_N_32k_ENC]; - Word32 Spd_L_smooth_fx[STEREO_DFT_N_32k_ENC / 2]; // Q(31 - Spd_L_smooth_fx_e) - Word16 Spd_L_smooth_fx_e; - Word32 Spd_R_smooth_fx[STEREO_DFT_N_32k_ENC / 2]; // Q(31 - Spd_R_smooth_fx_e) - Word16 Spd_R_smooth_fx_e; - Word32 sid_gipd_fx; // Q13 - const Word32 *win_fx; /* DFT window */ - const Word32 *win_8k_fx; /* DFT window */ - const Word32 *win_12k8_fx; /* DFT window */ - const Word32 *win_16k_fx; /* DFT window */ - const Word32 *win_32k_fx; /* DFT window */ + const Word32 *win_fx; /* DFT window */ + const Word32 *win_8k_fx; /* DFT window */ + const Word32 *win_12k8_fx; /* DFT window */ + const Word32 *win_16k_fx; /* DFT window */ + const Word32 *win_32k_fx; /* DFT window */ const Word16 *win_ana_fx; /* DFT analysis window */ const Word16 *win_ana_8k_fx; /* DFT analysis window */ diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index a6ad046c3..9314e80ba 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -63,8 +63,9 @@ * Local function prototypes *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void stereo_dft_enc_open( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, const int32_t input_Fs, const int16_t max_bwidth ); -#ifdef IVAS_FLOAT_FIXED +#else static void stereo_dft_enc_open_fx( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, const Word32 input_Fs, const Word16 max_bwidth ); #endif // IVAS_FLOAT_FIXED @@ -549,6 +550,7 @@ static void stereo_dft_quantize_ipd( * Create DFT stereo handle *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error stereo_dft_enc_create( STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* i/o: encoder DFT stereo handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -580,11 +582,7 @@ ivas_error stereo_dft_enc_create( hStereoDft_loc->hConfig->force_mono_transmission = 0; -#ifndef IVAS_FLOAT_FIXED stereo_dft_config( hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS ); -#else - stereo_dft_config_fx( hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS ); -#endif stereo_dft_enc_open( hStereoDft_loc, input_Fs, max_bwidth ); @@ -595,7 +593,7 @@ ivas_error stereo_dft_enc_create( return IVAS_ERR_OK; } -#ifdef IVAS_FLOAT_FIXED +#else ivas_error stereo_dft_enc_create_fx( STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* i/o: encoder DFT stereo handle */ const Word32 input_Fs, /* i : input sampling rate */ @@ -632,20 +630,23 @@ ivas_error stereo_dft_enc_create_fx( stereo_dft_enc_open_fx( hStereoDft_loc, input_Fs, max_bwidth ); - stereo_dft_hybrid_ITD_flag( hStereoDft_loc->hConfig, input_Fs, - hStereoDft_loc->hItd->hybrid_itd_max ); + stereo_dft_hybrid_ITD_flag_fx( hStereoDft_loc->hConfig, input_Fs, + hStereoDft_loc->hItd->hybrid_itd_max ); *hStereoDft = hStereoDft_loc; return IVAS_ERR_OK; } #endif + + /*------------------------------------------------------------------------- * stereo_dft_enc_open() * * Initialize DFT stereo handle *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void stereo_dft_enc_open( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -667,12 +668,8 @@ static void stereo_dft_enc_open( hStereoDft->win_ana_energy = (float) hStereoDft->N - hStereoDft->dft_ovl; hStereoDft->win_ana_energy += 2 * sum_f( win, hStereoDft->dft_ovl ); hStereoDft->win_ana_energy = hStereoDft->win_ana_energy / hStereoDft->NFFT; -#ifdef IVAS_FLOAT_FIXED - hStereoDft->win_ana_energy_fx = (Word16) ( hStereoDft->win_ana_energy * ( 1 << 15 ) ); -#endif hStereoDft->dft_zp = (int16_t) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); -#ifndef IVAS_FLOAT_FIXED set_f( hStereoDft->output_mem_dmx_32k, 0, STEREO_DFT_OVL_32k ); hStereoDft->dft_trigo_8k = dft_trigo_32k; hStereoDft->dft_trigo_12k8 = dft_trigo_12k8; @@ -688,144 +685,43 @@ static void stereo_dft_enc_open( hStereoDft->win_12k8 = win_syn_12k8; hStereoDft->win_16k = win_syn_16k; hStereoDft->win_32k = win_syn_32k; -#else - set32_fx( hStereoDft->output_mem_dmx_32k_fx, 0, STEREO_DFT_OVL_32k ); -#endif -// need to remove this once fixed function is called // -#ifdef IVAS_FLOAT_FIXED - hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; - hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_32k_fx = dft_trigo_32k_fx; - - hStereoDft->win_ana_8k_fx = win_ana_8k_fx; - hStereoDft->win_ana_12k8_fx = win_ana_12k8_fx; - hStereoDft->win_ana_16k_fx = win_ana_16k_fx; - hStereoDft->win_ana_32k_fx = win_ana_32k_fx; - - hStereoDft->win_8k_fx = win_syn_8k_fx; - hStereoDft->win_12k8_fx = win_syn_12k8_fx; - hStereoDft->win_16k_fx = win_syn_16k_fx; - hStereoDft->win_32k_fx = win_syn_32k_fx; -#endif if ( input_Fs == 16000 ) { hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; -#ifdef IVAS_FLOAT_FIXED - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->win_ana_fx = win_ana_16k_fx; - hStereoDft->win_fx = win_syn_16k_fx; -#else hStereoDft->dft_trigo = dft_trigo_32k; hStereoDft->win_ana = win_ana_16k; hStereoDft->win = win_syn_16k; - -#endif } else if ( input_Fs == 32000 ) { hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; -#ifdef IVAS_FLOAT_FIXED - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->win_ana_fx = win_ana_32k_fx; - hStereoDft->win_fx = win_syn_32k_fx; -#else hStereoDft->dft_trigo = dft_trigo_32k; hStereoDft->win_ana = win_ana_32k; hStereoDft->win = win_syn_32k; -#endif } else { assert( input_Fs == 48000 ); hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; -#ifdef IVAS_FLOAT_FIXED - hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; - hStereoDft->win_ana_fx = win_ana_48k_fx; - hStereoDft->win_fx = win_syn_48k_fx; -#else hStereoDft->dft_trigo = dft_trigo_48k; hStereoDft->win_ana = win_ana_48k; hStereoDft->win = win_syn_48k; - -#endif } -#ifdef IVAS_FLOAT_FIXED - hStereoDft->win_mdct_8k_fx = win_mdct_8k_fx; -#else hStereoDft->win_mdct_8k = win_mdct_8k; -#endif -#ifdef IVAS_FLOAT_FIXED + /*I/O Buffers*/ set_zero( hStereoDft->output_mem_dmx, STEREO_DFT_OVL_MAX ); set_zero( hStereoDft->output_mem_dmx_12k8, STEREO_DFT_OVL_12k8 ); - set_zero( hStereoDft->output_mem_res_8k, STEREO_DFT_OVL_8k ); - set32_fx( hStereoDft->output_mem_dmx_16k_shb_fx, 0, STEREO_DFT_OVL_16k ); - set32_fx( hStereoDft->output_mem_dmx_16k_fx, 0, STEREO_DFT_OVL_16k ); -#else - set_zero( hStereoDft->output_mem_dmx_16k_shb, STEREO_DFT_OVL_16k ); set_zero( hStereoDft->output_mem_dmx_16k, STEREO_DFT_OVL_16k ); -#endif -#ifdef IVAS_FLOAT_FIXED - hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; - hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_32k_fx = dft_trigo_32k_fx; - - hStereoDft->win_ana_8k_fx = win_ana_8k_fx; - hStereoDft->win_ana_12k8_fx = win_ana_12k8_fx; - hStereoDft->win_ana_16k_fx = win_ana_16k_fx; - hStereoDft->win_ana_32k_fx = win_ana_32k_fx; - - hStereoDft->win_8k_fx = win_syn_8k_fx; - hStereoDft->win_12k8_fx = win_syn_12k8_fx; - hStereoDft->win_16k_fx = win_syn_16k_fx; - hStereoDft->win_32k_fx = win_syn_32k_fx; - - IF( EQ_32( input_Fs, 16000 ) ) - { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; - hStereoDft->win_ana_fx = win_ana_16k_fx; - hStereoDft->win_fx = win_syn_16k_fx; - } - ELSE IF( EQ_32( input_Fs, 32000 ) ) - { - hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; - hStereoDft->win_ana_fx = win_ana_32k_fx; - hStereoDft->win_fx = win_syn_32k_fx; - } - ELSE - { - assert( EQ_32( input_Fs, 48000 ) ); - hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; - hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; - hStereoDft->win_ana_fx = win_ana_48k_fx; - hStereoDft->win_fx = win_syn_48k_fx; - } - - hStereoDft->win_mdct_8k_fx = win_mdct_8k_fx; - - /*I/O Buffers*/ - set_zero_fx( hStereoDft->output_mem_dmx_fx, STEREO_DFT_OVL_MAX ); - set_zero_fx( hStereoDft->output_mem_dmx_12k8_fx, STEREO_DFT_OVL_12k8 ); - set_zero_fx( hStereoDft->output_mem_dmx_16k_fx, STEREO_DFT_OVL_16k ); - set_zero_fx( hStereoDft->output_mem_dmx_16k_shb_fx, STEREO_DFT_OVL_16k ); - set_zero_fx( hStereoDft->output_mem_res_8k_fx, STEREO_DFT_OVL_8k ); -#endif + set_zero( hStereoDft->output_mem_dmx_16k_shb, STEREO_DFT_OVL_16k ); + set_zero( hStereoDft->output_mem_res_8k, STEREO_DFT_OVL_8k ); /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ NFFT_inner = STEREO_DFT_N_MAX_ENC * inner_frame_tbl[max_bwidth] / L_FRAME48k; -#ifndef IVAS_FLOAT_FIXED hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); hStereoDft->nbands_dmx = stereo_dft_band_config( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); -#else - hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); - hStereoDft->nbands_dmx = stereo_dft_band_config_fx( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); -#endif /*Set configuration*/ set_s( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_ENC_DFT_NB ); @@ -842,13 +738,10 @@ static void stereo_dft_enc_open( /* reset DFT stereo memories */ stereo_dft_enc_reset( hStereoDft ); -#ifdef IVAS_FLOAT_FIXED - stereo_dft_enc_reset_fx( hStereoDft ); -#endif return; } -#ifdef IVAS_FLOAT_FIXED +#else static void stereo_dft_enc_open_fx( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ const Word32 input_Fs, /* i : input sampling rate */ @@ -858,43 +751,39 @@ static void stereo_dft_enc_open_fx( Word16 NFFT_inner; PWord16 win_p[STEREO_DFT_OVL_MAX]; Word16 win[STEREO_DFT_OVL_MAX]; + Word32 L_tmp; + Word16 tmp, tmp_e; /*Sizes*/ - hStereoDft->N = extract_l( Mpy_32_32( input_Fs, 42949673 /* STEREO_DFT_HOP_MAX_ENC / 48000 in Q31 */ ) ); // e = div_e + hStereoDft->N = extract_l( Mpy_32_32( input_Fs, 42949673 /* STEREO_DFT_HOP_MAX_ENC / 48000 in Q31 */ ) ); move16(); assert( ( ( input_Fs / FRAMES_PER_SEC ) / hStereoDft->N ) == 1 ); /*Init. DFT sizes*/ - // hStereoDft->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, input_Fs_48k ); // e = div_e - hStereoDft->NFFT = extract_l( Mpy_32_32( input_Fs, 85899346 /* STEREO_DFT_N_MAX_ENC / 48000 in Q31 */ ) ); // e = div_e - // hStereoDft->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, input_Fs ); // e = div_e - hStereoDft->dft_ovl = extract_l( Mpy_32_32( input_Fs, 18790482 /* STEREO_DFT_OVL_MAX / 48000 in Q31 */ ) ); // e = div_e + hStereoDft->NFFT = extract_l( Mpy_32_32( input_Fs, 85899346 /* STEREO_DFT_N_MAX_ENC / 48000 in Q31 */ ) ); move16(); + hStereoDft->dft_ovl = extract_l( Mpy_32_32( input_Fs, 18790482 /* STEREO_DFT_OVL_MAX / 48000 in Q31 */ ) ); move16(); mdct_window_sine_IVAS_updated( win_p, input_Fs, hStereoDft->dft_ovl, FULL_OVERLAP, IVAS_CPE_DFT ); // win_e = 15 - FOR( Word16 i = 0; i < ( STEREO_DFT_OVL_MAX / 2 ); i++ ) + FOR( Word16 i = 0; i < ( hStereoDft->dft_ovl / 2 ); i++ ) { - win[STEREO_DFT_OVL_MAX - 1 - i] = win_p[i].v.re; - win[i] = win_p[i].v.im; + win[hStereoDft->dft_ovl - 1 - i] = win_p[i].v.re; move16(); + win[i] = win_p[i].v.im; move16(); } - hStereoDft->win_ana_energy_fx = sub( hStereoDft->N, hStereoDft->dft_ovl ); // e = div_e - hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); // Q = 15 - hStereoDft->win_ana_energy_fx = add( hStereoDft->win_ana_energy_fx, shl( sum_s( win, hStereoDft->dft_ovl ), 1 ) ); // Q = 15 - hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); - hStereoDft->win_ana_energy_fx = div_s( hStereoDft->win_ana_energy_fx, hStereoDft->NFFT ); // Q = 15 - move16(); - move16(); - move16(); - move16(); + L_tmp = L_shl( L_sub( hStereoDft->N, hStereoDft->dft_ovl ), Q15 ); /* Q15 */ + L_tmp = L_add( L_tmp, L_shl( sum16_32_fx( win, hStereoDft->dft_ovl ), 1 ) ); /* Q15 */ + tmp = BASOP_Util_Divide3232_Scale( L_tmp, hStereoDft->NFFT, &tmp_e ); + tmp_e = sub( tmp_e, 15 ); + hStereoDft->win_ana_energy_fx = shl( tmp, tmp_e ); /* Q15 */ move16(); set32_fx( hStereoDft->output_mem_dmx_32k_fx, 0, STEREO_DFT_OVL_32k ); - hStereoDft->dft_zp = (Word16) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); + hStereoDft->dft_zp = extract_l( Mpy_32_32( input_Fs, 12079596 /* STEREO_DFT_ZP_MAX_ENC / 48000 in Q31 */ ) ); move16(); hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; @@ -975,94 +864,67 @@ static void stereo_dft_enc_open_fx( return; } #endif + + /*------------------------------------------------------------------------- * stereo_dft_enc_reset() * * Reset DFT stereo memories *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_dft_enc_reset( STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ) { /*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 ); set_s( hStereoDft->side_gain_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); set_s( hStereoDft->side_gain_index_ECprevious, 15, STEREO_DFT_BAND_MAX ); hStereoDft->side_gain_counter = 0; -#ifdef IVAS_FLOAT_FIXED - hStereoDft->side_gain_bitdiff_lp_fx = STEREO_DFT_BITDIFF_INIT_FX; - hStereoDft->q_side_gain_bitdiff_lp = Q10; -#else hStereoDft->side_gain_bitdiff_lp = STEREO_DFT_BITDIFF_INIT; -#endif -#ifndef IVAS_FLOAT_FIXED set_zero( hStereoDft->gipd, STEREO_DFT_ENC_DFT_NB ); set_zero( hStereoDft->dot_prod_real_smooth, STEREO_DFT_BAND_MAX ); set_zero( hStereoDft->dot_prod_img_smooth, STEREO_DFT_BAND_MAX ); -#endif -#ifdef IVAS_FLOAT_FIXED - set_zero_fx( hStereoDft->dot_prod_real_smooth_fx, STEREO_DFT_BAND_MAX ); - set16_zero_fx( hStereoDft->dot_prod_real_smooth_fx_e, STEREO_DFT_BAND_MAX ); - set_zero_fx( hStereoDft->dot_prod_img_smooth_fx, STEREO_DFT_BAND_MAX ); - set16_zero_fx( hStereoDft->dot_prod_img_smooth_fx_e, STEREO_DFT_BAND_MAX ); -#endif -#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { set_zero( hStereoDft->ipd_buf[i], STEREO_DFT_IPD_BUF_LEN ); } hStereoDft->prev_gipd = 0.f; set_zero( hStereoDft->res_pred_gain, STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX ); -#endif hStereoDft->gipd_index = 0; set_s( hStereoDft->res_pred_index_EC, 0, STEREO_DFT_BAND_MAX ); set_s( hStereoDft->res_pred_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); set_s( hStereoDft->res_pred_index_ECprevious, 0, STEREO_DFT_BAND_MAX ); hStereoDft->res_pred_counter = 0; -#ifndef IVAS_FLOAT_FIXED set_zero( hStereoDft->past_nrgL, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); set_zero( hStereoDft->past_nrgR, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); set_zero( hStereoDft->past_dot_prod_real, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); set_zero( hStereoDft->past_dot_prod_imag, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); -#endif hStereoDft->nrg_past_pos = 0; -#ifndef IVAS_FLOAT_FIXED hStereoDft->res_dmx_ratio_lt = 1.0f; -#endif hStereoDft->hangover_cnt0 = 0; hStereoDft->hangover_cnt1 = 0; -#ifndef IVAS_FLOAT_FIXED hStereoDft->dmx_res_all_prev = EPSILON; -#endif hStereoDft->last_res_cod_mode_modify_flag = 0; hStereoDft->res_cod_sw_flag = 0; -#ifndef IVAS_FLOAT_FIXED 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; } hStereoDft->old_snr = 0.f; -#endif - hStereoDft->reverb_flag = 0; -#ifndef IVAS_FLOAT_FIXED set_zero( hStereoDft->pre_sub_nrg_DMX, STEREO_DFT_BAND_MAX ); hStereoDft->diff_l_h_sm = 0.0f; hStereoDft->diff_r_h_sm = 0.0f; hStereoDft->prev_fac2 = 1.0f; set_zero( hStereoDft->res_pred_gain_f, STEREO_DFT_BAND_MAX ); -#endif /*misc*/ hStereoDft->no_ipd_flag = 1; /* Initialization of the no IPD variables */ @@ -1071,26 +933,19 @@ void stereo_dft_enc_reset( hStereoDft->no_ipd_cnt1 = 0; hStereoDft->attackPresent = 0; hStereoDft->wasTransient = 0; -#ifndef IVAS_FLOAT_FIXED hStereoDft->gainIPD_sm = 1.f; hStereoDft->voicing_lt = 0; -#endif - hStereoDft->flip_sign = 1; -#ifndef IVAS_FLOAT_FIXED hStereoDft->sfm = 0.f; hStereoDft->sum_dot_prod_real = 0.f; hStereoDft->sum_dot_prod_img = 0.f; -#endif /*Coherence*/ -#ifndef IVAS_FLOAT_FIXED set_f( hStereoDft->xspec_smooth, 1.0f, STEREO_DFT_N_32k_ENC ); hStereoDft->sid_gipd = 0; hStereoDft->prev_sid_gipd = 0; set_f( hStereoDft->Spd_L_smooth, 1.0f, STEREO_DFT_N_32k_ENC / 2 ); set_f( hStereoDft->Spd_R_smooth, 1.0f, STEREO_DFT_N_32k_ENC / 2 ); -#endif hStereoDft->currentNumUpdates = 0; hStereoDft->expectedNumUpdates = FIXED_SID_RATE; hStereoDft->resetFrames = 0; @@ -1099,10 +954,8 @@ void stereo_dft_enc_reset( hStereoDft->coh_fade_counter = 0; /* Xtalk classifier */ -#ifndef IVAS_FLOAT_FIXED hStereoDft->hItd->prev_m1 = 0; hStereoDft->hItd->prev_m2 = 0; -#endif hStereoDft->hItd->prev_itd1 = 0; hStereoDft->hItd->prev_itd2 = 0; @@ -1112,14 +965,14 @@ void stereo_dft_enc_reset( return; } -#ifdef IVAS_FLOAT_FIXED +#else void stereo_dft_enc_reset_fx( STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ) { Word16 i; /*reset parameters*/ - set_zero_fx( hStereoDft->side_gain_fx, i_mult( STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX ) ); + set_zero_fx( hStereoDft->side_gain_fx, STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX ); set16_fx( hStereoDft->side_gain_index_EC, 15, STEREO_DFT_BAND_MAX ); set16_fx( hStereoDft->side_gain_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); set16_fx( hStereoDft->side_gain_index_ECprevious, 15, STEREO_DFT_BAND_MAX ); @@ -1127,9 +980,13 @@ void stereo_dft_enc_reset_fx( move16(); hStereoDft->side_gain_bitdiff_lp_fx = STEREO_DFT_BITDIFF_INIT_FX; move16(); + hStereoDft->q_side_gain_bitdiff_lp = Q10; + move16(); set_zero_fx( hStereoDft->gipd_fx, STEREO_DFT_ENC_DFT_NB ); set_zero_fx( hStereoDft->dot_prod_real_smooth_fx, STEREO_DFT_BAND_MAX ); + set16_zero_fx( hStereoDft->dot_prod_real_smooth_fx_e, STEREO_DFT_BAND_MAX ); set_zero_fx( hStereoDft->dot_prod_img_smooth_fx, STEREO_DFT_BAND_MAX ); + set16_zero_fx( hStereoDft->dot_prod_img_smooth_fx_e, STEREO_DFT_BAND_MAX ); FOR( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { set_zero_fx( hStereoDft->ipd_buf_fx[i], STEREO_DFT_IPD_BUF_LEN ); @@ -1138,20 +995,20 @@ void stereo_dft_enc_reset_fx( move32(); hStereoDft->gipd_index = 0; move16(); - set_zero_fx( hStereoDft->res_pred_gain_fx, i_mult( STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX ) ); + set_zero_fx( hStereoDft->res_pred_gain_fx, STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX ); set16_fx( hStereoDft->res_pred_index_EC, 0, STEREO_DFT_BAND_MAX ); set16_fx( hStereoDft->res_pred_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); set16_fx( hStereoDft->res_pred_index_ECprevious, 0, STEREO_DFT_BAND_MAX ); hStereoDft->res_pred_counter = 0; move16(); - set_zero_fx( hStereoDft->past_nrgL_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); - set16_zero_fx( hStereoDft->past_nrgL_fx_e, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); - set_zero_fx( hStereoDft->past_nrgR_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); - set16_zero_fx( hStereoDft->past_nrgR_fx_e, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); - set_zero_fx( hStereoDft->past_dot_prod_real_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); - set16_zero_fx( hStereoDft->past_dot_prod_real_fx_e, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); - set_zero_fx( hStereoDft->past_dot_prod_imag_fx, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); - set16_zero_fx( hStereoDft->past_dot_prod_imag_fx_e, i_mult( STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX ) ); + set_zero_fx( hStereoDft->past_nrgL_fx, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); + set16_zero_fx( hStereoDft->past_nrgL_fx_e, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); + set_zero_fx( hStereoDft->past_nrgR_fx, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); + set16_zero_fx( hStereoDft->past_nrgR_fx_e, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); + set_zero_fx( hStereoDft->past_dot_prod_real_fx, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); + set16_zero_fx( hStereoDft->past_dot_prod_real_fx_e, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); + set_zero_fx( hStereoDft->past_dot_prod_imag_fx, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); + set16_zero_fx( hStereoDft->past_dot_prod_imag_fx_e, STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX ); hStereoDft->nrg_past_pos = 0; move16(); @@ -1175,6 +1032,7 @@ void stereo_dft_enc_reset_fx( hStereoDft->switch_fade_factor_fx = ONE_IN_Q14; // Q15/2 move16(); hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1] = STEREO_DFT_RES_COD_1kHz; + move16(); FOR( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { hStereoDft->res_cod_NRG_M_fx[i] = 0; @@ -1244,10 +1102,10 @@ void stereo_dft_enc_reset_fx( /*Coherence*/ set32_fx( hStereoDft->xspec_smooth_fx, MAX_32, STEREO_DFT_N_32k_ENC ); set16_fx( hStereoDft->xspec_smooth_fx_e, 0, STEREO_DFT_N_32k_ENC ); - set32_fx( hStereoDft->Spd_L_smooth_fx, MAX_32, shr( STEREO_DFT_N_32k_ENC, 1 ) ); + set32_fx( hStereoDft->Spd_L_smooth_fx, MAX_32, STEREO_DFT_N_32k_ENC / 2 ); hStereoDft->Spd_L_smooth_fx_e = 0; move16(); - set32_fx( hStereoDft->Spd_R_smooth_fx, MAX_32, shr( STEREO_DFT_N_32k_ENC, 1 ) ); + set32_fx( hStereoDft->Spd_R_smooth_fx, MAX_32, STEREO_DFT_N_32k_ENC / 2 ); hStereoDft->Spd_R_smooth_fx_e = 0; move16(); @@ -1286,64 +1144,57 @@ void stereo_dft_enc_reset_fx( return; } #endif + + /*------------------------------------------------------------------------- * stereo_enc_itd_init() * * initialize ITD struct *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_enc_itd_init( ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ ) { hItd->prev_itd = 0; -#ifndef IVAS_FLOAT_FIXED set_zero( hItd->itd, STEREO_DFT_ENC_DFT_NB ); set_zero( hItd->deltaItd, STEREO_DFT_ENC_DFT_NB ); -#endif set_s( hItd->td_itd, 0, STEREO_DFT_ENC_DFT_NB ); set_s( hItd->td_itd_32k, 0, STEREO_DFT_ENC_DFT_NB ); set_s( hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB ); -#ifndef IVAS_FLOAT_FIXED set_zero( hItd->xcorr_smooth, STEREO_DFT_N_32k_ENC ); hItd->lp_phat_peak = 0.f; -#endif hItd->itd_hangover = 0; hItd->itd_cnt = 0; -#ifndef IVAS_FLOAT_FIXED hItd->prev_sum_nrg_L_lb = 0.f; set_zero( hItd->prev_xcorr_lb, STEREO_DFT_XCORR_LB_MAX ); set_f( hItd->E_band_n, (float) ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM ); -#endif hItd->vad_frm_cnt = 0; hItd->pre_vad = 0; hItd->itd_nonzero_cnt = 0; -#ifndef IVAS_FLOAT_FIXED set_zero( hItd->acorr_L, STEREO_DFT_BAND_MAX ); set_zero( hItd->acorr_R, STEREO_DFT_BAND_MAX ); hItd->cohSNR = 15.f; hItd->itd_thres = 0.f; -#endif hItd->valid_itd_cnt = 0; hItd->detected_itd_flag = 0; hItd->itd_tracking = 0; hItd->prev_index = 0; -#ifndef IVAS_FLOAT_FIXED hItd->prev_max = 0.f; hItd->prev_avg_max = 0.f; hItd->currFlatness = 0.f; /* Xtalk classifier */ hItd->prev_m1 = 0; hItd->prev_m2 = 0; -#endif hItd->prev_itd1 = 0; hItd->prev_itd2 = 0; hItd->hybrid_itd_max = 0; return; } - +#else void stereo_enc_itd_init_fx( ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ ) @@ -1417,6 +1268,8 @@ void stereo_enc_itd_init_fx( move16(); return; } +#endif + /*-------------------------------------------------------------------------- * stereo_dft_enc_update() @@ -1593,9 +1446,32 @@ void stereo_dft_enc_update( * destroy DFT stereo handle *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_dft_enc_destroy( STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle */ ) +{ + if ( ( *hStereoDft )->hConfig != NULL ) + { + free( ( *hStereoDft )->hConfig ); + ( *hStereoDft )->hConfig = NULL; + } + + if ( ( *hStereoDft )->hItd != NULL ) + { + free( ( *hStereoDft )->hItd ); + ( *hStereoDft )->hItd = NULL; + } + + free( *hStereoDft ); + *hStereoDft = NULL; + + return; +} +#else +void stereo_dft_enc_destroy_fx( + STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle */ +) { IF( ( *hStereoDft )->hConfig != NULL ) { @@ -1614,6 +1490,7 @@ void stereo_dft_enc_destroy( return; } +#endif /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index d558a4c34..a048b0141 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -147,7 +147,33 @@ static void set_band_limits( * Get the hybrid ITD flag *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_dft_hybrid_ITD_flag( + STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ + const int32_t input_Fs, /* i : CPE element sampling rate */ + const int16_t hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ +) +{ + if ( hConfig != NULL ) + { + if ( hConfig->res_cod_mode || ( hConfig->ada_wb_res_cod_mode && input_Fs == 16000 ) || ( hybrid_itd_max == 1 ) ) + { + hConfig->hybrid_itd_flag = 1; + } + else + { + hConfig->hybrid_itd_flag = 0; + } + } + else + { + assert( 0 && "Stereo Dft Config Data Handle is uninitialized" ); + } + + return; +} +#else +void stereo_dft_hybrid_ITD_flag_fx( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ const Word32 input_Fs, /* i : CPE element sampling rate */ const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ @@ -176,7 +202,7 @@ void stereo_dft_hybrid_ITD_flag( return; } - +#endif /*------------------------------------------------------------------------- * stereo_dft_quantize_itd() diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index b1e7097e1..0d380f37b 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -218,7 +218,7 @@ static int16_t ic_bwe_enc_specMapping( return idx; } #endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifdef IVAS_FLOAT_FIXED static Word16 ic_bwe_enc_specMapping_ivas_fx( const Word32 *shb_frame_target_fx, /* i : target shb */ Word16 shb_frame_target_e, diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 40adc73a1..8ee9b6051 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -127,18 +127,18 @@ static void dft_ana_init( return; } #else -static void dft_ana_init( +static void dft_ana_init_fx( DFT_ANA_HANDLE hDft_ana, /*i : DFT analysis handle */ const Word32 input_Fs /*i : Input sampling frequency */ ) { - hDft_ana->N = extract_l( Mpy_32_16_1( input_Fs, 656 ) ); + hDft_ana->N = extract_l( Mpy_32_16_1( input_Fs, 656 /* STEREO_DFT_HOP_MAX_ENC / 48000 in Q15 */ ) ); move16(); - hDft_ana->NFFT = extract_l( Mpy_32_16_1( input_Fs, 1311 ) ); + hDft_ana->NFFT = extract_l( Mpy_32_16_1( input_Fs, 1311 /* STEREO_DFT_N_MAX_ENC / 48000 in Q15 */ ) ); move16(); - hDft_ana->dft_ovl = extract_l( Mpy_32_16_1( input_Fs, 287 ) ); + hDft_ana->dft_ovl = extract_l( Mpy_32_16_1( input_Fs, 287 /* STEREO_DFT_OVL_MAX / 48000 in Q15 */ ) ); move16(); - hDft_ana->dft_zp = extract_l( Mpy_32_16_1( input_Fs, 185 ) ); + hDft_ana->dft_zp = extract_l( Mpy_32_16_1( input_Fs, 185 /* STEREO_DFT_ZP_MAX_ENC / 48000 in Q15 */ ) ); move16(); hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; @@ -170,6 +170,7 @@ static void dft_ana_init( } #endif + /*-------------------------------------------------------------------* * write_itd_data() * @@ -2274,7 +2275,7 @@ ivas_error initMdctItdHandling( return IVAS_ERR_OK; } #else -ivas_error initMdctItdHandling( +ivas_error initMdctItdHandling_fx( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const Word32 input_Fs /* i : input sampling rate */ ) @@ -2299,11 +2300,12 @@ ivas_error initMdctItdHandling( stereo_enc_itd_init_fx( hStereoMdct->hItd ); /*Initialize DFT analysis parameters*/ - dft_ana_init( hStereoMdct->hDft_ana, input_Fs ); + dft_ana_init_fx( hStereoMdct->hDft_ana, input_Fs ); return IVAS_ERR_OK; } #endif + /*------------------------------------------------------------------------- * stereo_mdct_enc_destroy() * @@ -2333,7 +2335,7 @@ void stereo_mdct_enc_destroy( return; } #else -void stereo_mdct_enc_destroy( +void stereo_mdct_enc_destroy_fx( STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */ ) { diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 5e86db216..f8f460ff3 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -48,13 +48,13 @@ #include "ivas_prot_fx.h" #endif -#ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function allocate_CoreCoder_enc() * * Allocate CoreCoder modules *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED static ivas_error allocate_CoreCoder_enc_fx( ENC_CORE_HANDLE st /* i/o: Core encoder state structure */ ) @@ -65,10 +65,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - LPDmem_enc_init_fx( st->hLPDmem ); -#endif - LPDmem_enc_init( st->hLPDmem ); + LPDmem_enc_init_ivas_fx( st->hLPDmem ); } IF( st->hGSCEnc == NULL && st->element_mode != IVAS_CPE_MDCT ) @@ -86,9 +83,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ) ); } -#ifdef IVAS_FLOAT_FIXED noise_est_init_ivas_fx( st->hNoiseEst ); -#endif } IF( st->hVAD == NULL ) @@ -97,9 +92,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); } -#ifdef IVAS_FLOAT_FIXED wb_vad_init_ivas_fx( st->hVAD ); -#endif } IF( st->hSpMusClas == NULL ) @@ -108,21 +101,12 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } -#ifdef IVAS_FLOAT_FIXED speech_music_clas_init_ivas_fx( st->hSpMusClas ); -#endif - speech_music_clas_init( st->hSpMusClas ); } return IVAS_ERR_OK; } -#endif -/*-------------------------------------------------------------------* - * Function allocate_CoreCoder_enc() - * - * Allocate CoreCoder modules - *-------------------------------------------------------------------*/ - +#else static ivas_error allocate_CoreCoder_enc( ENC_CORE_HANDLE st /* i/o: Core encoder state structure */ ) @@ -142,11 +126,7 @@ static ivas_error allocate_CoreCoder_enc( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } -#ifndef IVAS_FLOAT_FIXED GSC_enc_init( st->hGSCEnc ); -#else - GSC_enc_init_fx( st->hGSCEnc ); -#endif } if ( st->hNoiseEst == NULL ) @@ -155,11 +135,7 @@ static ivas_error allocate_CoreCoder_enc( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ) ); } -#ifndef IVAS_FLOAT_FIXED noise_est_init( st->hNoiseEst ); -#else - noise_est_init_ivas_fx( st->hNoiseEst ); -#endif } if ( st->hVAD == NULL ) @@ -168,15 +144,7 @@ static ivas_error allocate_CoreCoder_enc( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); } -#ifndef IVAS_FLOAT_FIXED wb_vad_init( st->hVAD ); -#else -#ifndef MSAN_FIX - wb_vad_init_fx( st->hVAD ); -#else - wb_vad_init_ivas_fx( st->hVAD ); -#endif -#endif } if ( st->hSpMusClas == NULL ) @@ -186,13 +154,11 @@ static ivas_error allocate_CoreCoder_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } speech_music_clas_init( st->hSpMusClas ); -#if 1 - speech_music_clas_init_ivas_fx( st->hSpMusClas ); -#endif } return IVAS_ERR_OK; } +#endif /*-------------------------------------------------------------------* * Function deallocate_CoreCoder_TCX_enc() @@ -200,9 +166,41 @@ static ivas_error allocate_CoreCoder_enc( * Deallocate CoreCoder TCX modules *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void deallocate_CoreCoder_TCX_enc( ENC_CORE_HANDLE st /* i/o: Core encoder state structure */ ) +{ + if ( st->hTcxEnc != NULL ) + { + free( st->hTcxEnc ); + st->hTcxEnc = NULL; + } + + if ( st->hTcxCfg != NULL ) + { + free( st->hTcxCfg ); + st->hTcxCfg = NULL; + } + + if ( st->hIGFEnc != NULL ) + { + free( st->hIGFEnc ); + st->hIGFEnc = NULL; + } + + if ( st->hHQ_core != NULL ) + { + free( st->hHQ_core ); + st->hHQ_core = NULL; + } + + return; +} +#else +static void deallocate_CoreCoder_TCX_enc_fx( + ENC_CORE_HANDLE st /* i/o: Core encoder state structure */ +) { IF( st->hTcxEnc != NULL ) { @@ -230,6 +228,7 @@ static void deallocate_CoreCoder_TCX_enc( return; } +#endif /*-------------------------------------------------------------------* @@ -238,9 +237,74 @@ static void deallocate_CoreCoder_TCX_enc( * Deallocate CoreCoder modules *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void deallocate_CoreCoder_enc( ENC_CORE_HANDLE st /* i/o: Core encoder state structure */ ) +{ + if ( st->hLPDmem != NULL ) + { + free( st->hLPDmem ); + st->hLPDmem = NULL; + } + + if ( st->hGSCEnc != NULL ) + { + free( st->hGSCEnc ); + st->hGSCEnc = NULL; + } + + if ( st->hNoiseEst != NULL && st->element_mode != IVAS_CPE_MDCT ) + { + free( st->hNoiseEst ); + st->hNoiseEst = NULL; + } + + if ( st->hVAD != NULL && st->element_mode != IVAS_CPE_MDCT ) + { + free( st->hVAD ); + st->hVAD = NULL; + } + + if ( st->hSpMusClas != NULL && st->element_mode != IVAS_CPE_MDCT ) + { + free( st->hSpMusClas ); + st->hSpMusClas = NULL; + } + + if ( st->cldfbAnaEnc != NULL ) + { + deleteCldfb( &st->cldfbAnaEnc ); + } + + if ( st->hBWE_TD != NULL ) + { + free( st->hBWE_TD ); + st->hBWE_TD = NULL; + } + + if ( st->cldfbSynTd != NULL ) + { + deleteCldfb( &st->cldfbSynTd ); + } + + if ( st->hBWE_FD != NULL ) + { + free( st->hBWE_FD ); + st->hBWE_FD = NULL; + } + + if ( st->element_mode != IVAS_CPE_MDCT ) + { + deallocate_CoreCoder_TCX_enc( st ); + } + + return; +} +#else +static void deallocate_CoreCoder_enc_fx( + ENC_CORE_HANDLE st /* i/o: Core encoder state structure */ +) { IF( st->hLPDmem != NULL ) { @@ -254,18 +318,21 @@ static void deallocate_CoreCoder_enc( st->hGSCEnc = NULL; } + test(); IF( st->hNoiseEst != NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { free( st->hNoiseEst ); st->hNoiseEst = NULL; } + test(); IF( st->hVAD != NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { free( st->hVAD ); st->hVAD = NULL; } + test(); IF( st->hSpMusClas != NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { free( st->hSpMusClas ); @@ -274,7 +341,7 @@ static void deallocate_CoreCoder_enc( IF( st->cldfbAnaEnc != NULL ) { - deleteCldfb_ivas( &st->cldfbAnaEnc ); + deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); } IF( st->hBWE_TD != NULL ) @@ -285,7 +352,7 @@ static void deallocate_CoreCoder_enc( IF( st->cldfbSynTd != NULL ) { - deleteCldfb_ivas( &st->cldfbSynTd ); + deleteCldfb_ivas_fx( &st->cldfbSynTd ); } IF( st->hBWE_FD != NULL ) @@ -296,11 +363,12 @@ static void deallocate_CoreCoder_enc( IF( st->element_mode != IVAS_CPE_MDCT ) { - deallocate_CoreCoder_TCX_enc( st ); + deallocate_CoreCoder_TCX_enc_fx( st ); } return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -364,15 +432,15 @@ ivas_error stereo_memory_enc_fx( IF( hCPE->hStereoMdct != NULL ) { - stereo_mdct_enc_destroy( &( hCPE->hStereoMdct ) ); + stereo_mdct_enc_destroy_fx( &( hCPE->hStereoMdct ) ); hCPE->hStereoMdct = NULL; } /* deallocate CoreCoder secondary channel */ - deallocate_CoreCoder_enc( hCPE->hCoreCoder[1] ); + deallocate_CoreCoder_enc_fx( hCPE->hCoreCoder[1] ); /* allocate DFT stereo data structure */ - IF( NE_32( ( error = stereo_dft_enc_create( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = stereo_dft_enc_create_fx( &( hCPE->hStereoDft ), input_Fs, max_bwidth ) ), IVAS_ERR_OK ) ) { return error; } @@ -409,18 +477,18 @@ ivas_error stereo_memory_enc_fx( /* deallocate data structure of the previous CPE mode */ IF( hCPE->hStereoDft != NULL ) { - stereo_dft_enc_destroy( &( hCPE->hStereoDft ) ); + stereo_dft_enc_destroy_fx( &( hCPE->hStereoDft ) ); hCPE->hStereoDft = NULL; } IF( hCPE->hStereoMdct != NULL ) { - stereo_mdct_enc_destroy( &( hCPE->hStereoMdct ) ); + stereo_mdct_enc_destroy_fx( &( hCPE->hStereoMdct ) ); hCPE->hStereoMdct = NULL; } /* deallocated TCX/IGF structures for second channel */ - deallocate_CoreCoder_TCX_enc( hCPE->hCoreCoder[1] ); + deallocate_CoreCoder_TCX_enc_fx( hCPE->hCoreCoder[1] ); /* allocate TD stereo data structure */ IF( hCPE->hStereoTD != NULL ) @@ -435,16 +503,10 @@ ivas_error stereo_memory_enc_fx( stereo_td_init_enc_fx( hCPE->hStereoTD, hCPE->last_element_mode ); /* allocate secondary channel */ -#ifdef IVAS_FLOAT_FIXED IF( NE_32( ( error = allocate_CoreCoder_enc_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) { return error; } -#endif - IF( ( error = allocate_CoreCoder_enc( hCPE->hCoreCoder[1] ) ) != IVAS_ERR_OK ) - { - return error; - } } /*--------------------------------------------------------------* @@ -479,7 +541,7 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_enc_init( hCPE->hCoreCoder[0]->hTdCngEnc, hCPE->hCoreCoder[0]->Opt_DTX_ON, hCPE->hCoreCoder[0]->max_bwidth ); + td_cng_enc_init_ivas_fx( hCPE->hCoreCoder[0]->hTdCngEnc, hCPE->hCoreCoder[0]->Opt_DTX_ON, hCPE->hCoreCoder[0]->max_bwidth ); } /* allocate TCA data structure */ @@ -498,7 +560,7 @@ ivas_error stereo_memory_enc_fx( st = hCPE->hCoreCoder[0]; /* allocate primary channel substructures */ - IF( NE_32( ( error = allocate_CoreCoder_enc( st ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = allocate_CoreCoder_enc_fx( st ) ), IVAS_ERR_OK ) ) { return error; } @@ -528,7 +590,6 @@ ivas_error stereo_memory_enc_fx( } } - InitSWBencBuffer( st->hBWE_TD ); InitSWBencBuffer_ivas_fx( st ); ResetSHBbuffer_Enc_fx( st ); @@ -537,7 +598,7 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } - fd_bwe_enc_init( st->hBWE_FD ); + fd_bwe_enc_init_fx( st->hBWE_FD ); } /* allocate stereo CNG structure */ @@ -563,7 +624,7 @@ ivas_error stereo_memory_enc_fx( /* deallocate data structure of the previous CPE mode */ IF( hCPE->hStereoDft != NULL ) { - stereo_dft_enc_destroy( &( hCPE->hStereoDft ) ); + stereo_dft_enc_destroy_fx( &( hCPE->hStereoDft ) ); hCPE->hStereoDft = NULL; } @@ -588,13 +649,13 @@ ivas_error stereo_memory_enc_fx( FOR( i = 0; i < CPE_CHANNELS; i++ ) { /* deallocate core-coder substructures */ - deallocate_CoreCoder_enc( hCPE->hCoreCoder[i] ); + deallocate_CoreCoder_enc_fx( hCPE->hCoreCoder[i] ); } IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { /* allocate secondary channel */ - IF( NE_32( ( error = allocate_CoreCoder_enc( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = allocate_CoreCoder_enc_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -665,7 +726,7 @@ ivas_error stereo_memory_enc_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { - IF( NE_32( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -719,7 +780,7 @@ ivas_error stereo_memory_enc_fx( IF( EQ_16( ivas_format, STEREO_FORMAT ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) && GT_32( hCPE->last_element_brate, MAX_MDCT_ITD_BRATE ) ) { /* allocate MDCT stereo ITD handling structure */ - IF( NE_32( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -955,9 +1016,6 @@ ivas_error stereo_memory_enc( } InitSWBencBuffer( st->hBWE_TD ); -#ifdef IVAS_FLOAT_FIXED - InitSWBencBuffer_fx( st ); -#endif ResetSHBbuffer_Enc( st->hBWE_TD ); if ( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) @@ -1207,7 +1265,7 @@ void stereo_switching_enc_fx( /* window DFT synthesis overlap memory @input_Fs, primary channel */ FOR( i = 0; i < dft_ovl; i++ ) { - hCPE->hStereoDft->output_mem_dmx_fx[i] = Mpy_32_16_r( hCPE->hStereoDft->win_fx[dft_ovl - 1 - i], old_input_signal_pri[input_frame - dft_ovl + i] ); + hCPE->hStereoDft->output_mem_dmx_fx[i] = L_shr( Mpy_32_16_r( hCPE->hStereoDft->win_fx[dft_ovl - 1 - i], old_input_signal_pri[input_frame - dft_ovl + i] ), q_inp ); // ( ( Q31 + q_inp ) - Q15 ) - Q16 ) -> Q16 move32(); } /* reset 48kHz BWE overlap memory */ @@ -1250,7 +1308,13 @@ void stereo_switching_enc_fx( L_lerp_fx( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx_16k_fx, STEREO_DFT_OVL_16k, dft_ovl, &q_dmx ); FOR( i = 0; i < STEREO_DFT_OVL_16k; i++ ) { - hCPE->hStereoDft->output_mem_dmx_16k_fx[i] = L_shl( hCPE->hStereoDft->output_mem_dmx_16k_fx[i], q_dmx - Q16 ); + hCPE->hStereoDft->output_mem_dmx_16k_fx[i] = L_shl( hCPE->hStereoDft->output_mem_dmx_16k_fx[i], sub( Q16, q_dmx ) ); // Q16 + move32(); + } + + FOR( i = 0; i < STEREO_DFT_OVL_MAX; i++ ) + { + hCPE->hStereoDft->output_mem_dmx_fx[i] = L_shl( hCPE->hStereoDft->output_mem_dmx_fx[i], sub( Q16, q_dmx ) ); // Q16 move32(); } diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 3c14a53c7..a17403e3f 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -416,10 +416,7 @@ ivas_error stereo_set_tdm_fx( return error; } - InitSWBencBuffer( st->hBWE_TD ); -#ifdef IVAS_FLOAT_FIXED InitSWBencBuffer_ivas_fx( st ); -#endif ResetSHBbuffer_Enc_fx( st ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) @@ -427,10 +424,7 @@ ivas_error stereo_set_tdm_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } -#ifdef IVAS_FLOAT_FIXED fd_bwe_enc_init_fx( st->hBWE_FD ); -#endif - fd_bwe_enc_init( st->hBWE_FD ); } } @@ -589,9 +583,6 @@ ivas_error stereo_set_tdm( } InitSWBencBuffer( st->hBWE_TD ); -#ifdef IVAS_FLOAT_FIXED - InitSWBencBuffer_fx( st ); -#endif ResetSHBbuffer_Enc( st->hBWE_TD ); if ( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 3bbb04ecd..fcaca81e1 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -304,9 +304,7 @@ void stereo_tcx_core_enc( hTcxEnc = st->hTcxEnc; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 /*Q_new, */ Q_exc, q_comm_Bin; -#endif + Word16 Q_exc; /*--------------------------------------------------------------* * Configuration of TCX @@ -449,7 +447,6 @@ void stereo_tcx_core_enc( *---------------------------------------------------------------*/ /* TODO: integrate this. */ -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->input_buff, st->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); st->prev_Q_new = 0; @@ -461,9 +458,6 @@ void stereo_tcx_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->input_buff_fx, st->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); #endif -#else - core_signal_analysis_high_bitrate( p_new_samples, T_op, lsp_new, lsp_mid, st, NULL, tnsSize, tnsBits, param_core, <pBits, NULL, st->L_frame, hTcxEnc->L_frameTCX, last_element_mode, vad_hover_flag ); -#endif bitsAvailable = sub( st->bits_frame_core, nbits_header ); IF( st->igf ) @@ -471,58 +465,15 @@ void stereo_tcx_core_enc( bitsAvailable = sub( bitsAvailable, st->hIGFEnc->infoTotalBitsWritten ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_comm_Bin = Q_new + Q_SCALE - 2; const Word16 Q_ener = Q_new + Q_SCALE - 2; // Q_new + Q_SCALE -2 -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS_ - st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 ); - floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, q_comm_Bin, 128 ); - floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, q_comm_Bin, 256 ); - - floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); - - st->hTcxEnc->spectrum_e[0] = 31 - ( Q_factor_arrL( st->hTcxEnc->spectrum[0], N_MAX ) - 4 ); - floatToFixed_arrL( st->hTcxEnc->spectrum[0], st->hTcxEnc->spectrum_fx[0], 31 - st->hTcxEnc->spectrum_e[0], N_MAX ); - st->hTcxEnc->spectrum_e[1] = st->hTcxEnc->spectrum_e[0]; - - Word16 L_frame = st->L_frame; - Word16 L_frameTCX = hTcxEnc->L_frameTCX; - Word16 L_spec = st->hTcxCfg->tcx_coded_lines; - Word16 tcx_offset = st->hTcxCfg->tcx_offset; - - IF( EQ_16( st->core, TCX_10_CORE ) ) - { - L_frame = shr( L_frame, 1 ); - L_frameTCX = shr( L_frameTCX, 1 ); - L_spec = shr( L_spec, 1 ); - } - ELSE IF( st->last_core == ACELP_CORE ) - { - L_frame = add( L_frame, tcx_offset ); - L_frameTCX = add( L_frameTCX, st->hTcxCfg->tcx_offsetFB ); - L_spec = add( L_spec, shr( st->hTcxCfg->tcx_coded_lines, 2 ) ); - - IF( st->hTcxCfg->lfacNext < 0 ) - { - L_frame = sub( L_frame, st->hTcxCfg->lfacNext ); - L_frameTCX = sub( L_frameTCX, st->hTcxCfg->lfacNextFB ); - } - } -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Q_exc = Q_new; st->prev_Q_new = Q_exc; -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->synth_flt, st->synth, st->Q_syn, st->L_frame ); - if ( st->tcxonly == 0 ) + + Scale_sig( st->synth, st->L_frame, st->Q_syn ); + IF( st->tcxonly == 0 ) { - st->wspeech_enc[st->L_frame - 1] = (Word16) floatToFixed( st->wspeech_enc_flt[st->L_frame - 1], st->Q_syn ); + st->wspeech_enc[st->L_frame - 1] = shl( st->wspeech_enc[st->L_frame - 1], st->Q_syn ); } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS IF( st->hTdCngEnc ) { FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) @@ -845,15 +796,15 @@ void stereo_tcx_core_enc( move16(); } } - st->q_Bin_E = q_comm_Bin; + st->q_Bin_E = Q_new + Q_SCALE - 2; move16(); - st->q_Bin_E_old = q_comm_Bin; + st->q_Bin_E_old = Q_new + Q_SCALE - 2; move16(); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Fixed to float - fixedToFloat_arr( st->synth, st->synth_flt, Q_new, st->L_frame ); -#endif + Scale_sig( st->synth, st->L_frame, -Q_new ); + IF( st->tcxonly == 0 ) + { + st->wspeech_enc[st->L_frame - 1] = shl( st->wspeech_enc[st->L_frame - 1], -st->Q_syn ); + } pop_wmops(); return; diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index ccf16510d..a4278601b 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -178,10 +178,16 @@ void noise_est_init_fx( move32(); /*Q7//E_MIN; */ hNoiseEst->enrO_fx[i] = E_MIN_FX; move32(); + hNoiseEst->q_enr = Q7; + move16(); hNoiseEst->bckr_fx[i] = E_MIN_FX; move32(); + hNoiseEst->q_bckr = Q7; + move16(); hNoiseEst->ave_enr_fx[i] = E_MIN_FX; move32(); + hNoiseEst->ave_enr_q = Q7; + move16(); } move16(); hNoiseEst->totalNoise_fx = 0; @@ -289,14 +295,20 @@ void noise_est_init_ivas_fx( move32(); /*1e-5f; */ hNoiseEst->fr_bands2_fx[i] = 1; move32(); /*1e-5f; */ - hNoiseEst->ave_enr2_fx[i] = E_MIN_FX; + hNoiseEst->ave_enr2_fx[i] = E_MIN_Q11_FX; move32(); /*Q7//E_MIN; */ hNoiseEst->enrO_fx[i] = E_MIN_Q11_FX; move32(); + hNoiseEst->q_enr = Q11; + move16(); hNoiseEst->bckr_fx[i] = E_MIN_Q11_FX; move32(); - hNoiseEst->ave_enr_fx[i] = E_MIN_FX; + hNoiseEst->q_bckr = Q11; + move16(); + hNoiseEst->ave_enr_fx[i] = E_MIN_Q11_FX; move32(); + hNoiseEst->ave_enr_q = Q11; + move16(); } move16(); hNoiseEst->totalNoise_fx = 0; @@ -2583,6 +2595,7 @@ void noise_est_ivas_fx( /* else */ /* non_sta2 = non_sta2 * ((st_ave_enr2[i]+1) / (enr[i]+1)) */ Lden = L_min( L_tmp_enr, L_tmp_ave_enr ); + if ( Lden == 0 ) { Lden = L_add( Lden, EPSILON_FX ); @@ -2604,7 +2617,7 @@ void noise_est_ivas_fx( /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */ Ltmp = Mult_32_16( hNoiseEst->ave_enr_fx[i], alpha ); - Ltmp = L_add( Ltmp, Mult_32_16( enr[i], alpham1 ) ); + Ltmp = L_add_sat( Ltmp, Mult_32_16( enr[i], alpham1 ) ); hNoiseEst->ave_enr_fx[i] = L_max( Le_min_scaled, Ltmp ); move32(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d530cbe1d..862712edf 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -883,6 +883,10 @@ void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); +void LPDmem_enc_init_ivas_fx( + LPD_state_HANDLE hLPDmem /* i/o: LP memories */ +); + void lsf_end_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ @@ -1159,6 +1163,12 @@ void td_cng_enc_init_fx( const Word16 max_bwidth /* i : maximum encoded bandwidth */ ); +void td_cng_enc_init_ivas_fx( + TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +); + void dtx_enc_init_fx( Encoder_State *st, /* i : Encoder state handle */ const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 6d358119c..db163997d 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -44,9 +44,6 @@ #include "rom_enc.h" #include "rom_com.h" /* Common static table prototypes */ #include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx.h" -#endif #ifndef IVAS_FLOAT_FIXED @@ -99,7 +96,6 @@ static int16_t sp_mus_classif_1st( Encoder_State *st, const int16_t localVAD_HE_ static void sp_mus_classif_2nd( Encoder_State *st, const float Etot, int16_t *attack_flag, const float *inp ); static void music_mixed_classif_improv( Encoder_State *st, const float *new_inp, const float *epsP, const float etot, const float old_cor, const float cor_map_sum ); -#endif /*---------------------------------------------------------------------* @@ -112,24 +108,17 @@ void speech_music_clas_init( SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ) { -#ifndef IVAS_FLOAT_FIXED int16_t i; -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->FV_st, 0.0f, N_SMC_FEATURES ); -#endif hSpMusClas->inact_cnt = 0; set_s( hSpMusClas->past_dec, 0, HANG_LEN - 1 ); -#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->past_dlp, 0, HANG_LEN - 1 ); set_f( hSpMusClas->past_dlp_mean_ST, 0, HANG_LEN - 1 ); hSpMusClas->dlp_mean_ST = 0.0f; hSpMusClas->dlp_mean_LT = 0.0f; hSpMusClas->dlp_var_LT = 0.0f; -#endif -#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < N_SMC_FEATURES; i++ ) { hSpMusClas->prev_FV[i] = 0.5f * hout_intervals[2 * i] + 0.5f * hout_intervals[2 * i + 1]; @@ -139,12 +128,8 @@ void speech_music_clas_init( { hSpMusClas->past_log_enr[i] = logf( E_MIN ); } -#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; hSpMusClas->wdlp_0_95_sp = 0.0f; @@ -156,39 +141,29 @@ void speech_music_clas_init( hSpMusClas->past_ps_diff = 0; hSpMusClas->past_epsP2 = 01; hSpMusClas->past_epsP = 0; -#endif hSpMusClas->flag_spitch_cnt = 0; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->gsc_thres[0] = TH_0_MIN; hSpMusClas->gsc_thres[1] = TH_1_MIN; hSpMusClas->gsc_thres[2] = TH_2_MIN; hSpMusClas->gsc_thres[3] = TH_3_MIN; set_f( hSpMusClas->gsc_lt_diff_etot, 0.0f, MAX_LT ); hSpMusClas->gsc_mem_etot = 0.0f; -#endif hSpMusClas->gsc_last_music_flag = 0; hSpMusClas->gsc_nb_thr_1 = 0; hSpMusClas->gsc_nb_thr_3 = 0; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->mold_corr = 0.9f; hSpMusClas->mean_avr_dyn = 0.5f; hSpMusClas->last_sw_dyn = 10.0f; -#endif hSpMusClas->relE_attack_cnt = 0; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->prev_relE = 0.0f; hSpMusClas->prev_Etot = 0.0f; -#endif hSpMusClas->prev_vad = 0; hSpMusClas->vad_0_1_cnt = 0; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->relE_attack_sum = 0; -#endif /* speech/music classifier improvement */ -#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < BUF_LEN; i++ ) { hSpMusClas->buf_flux[i] = -100; @@ -199,34 +174,24 @@ void speech_music_clas_init( hSpMusClas->buf_Ntonal2[i] = 0; hSpMusClas->buf_Ntonal_lf[i] = 0; } -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->lpe_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->voicing_buf, 0, HANG_LEN_INIT ); -#endif hSpMusClas->gsc_hangover = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->sparse_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->hf_spar_buf, 0, HANG_LEN_INIT ); hSpMusClas->LT_sparse = 0.0f; -#endif hSpMusClas->gsc_cnt = 0; hSpMusClas->last_vad_spa = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->old_Bin_E, 0.0f, 3 * N_OLD_BIN_E ); set_f( hSpMusClas->buf_etot, 0, 4 ); set_f( hSpMusClas->buf_dlp, 0, 10 ); -#endif hSpMusClas->UV_cnt1 = 300; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->LT_UV_cnt1 = 250.0f; -#endif hSpMusClas->onset_cnt = 0; hSpMusClas->attack_hangover = 0; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->dec_mov = 0.0f; hSpMusClas->dec_mov1 = 0.0f; hSpMusClas->mov_log_max_spl = 200.0f; @@ -234,68 +199,47 @@ void speech_music_clas_init( hSpMusClas->old_lt_diff[1] = 0.0f; 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 ); - hSpMusClas->Q_tod_lt_Bin_E = Q31; - move16(); -#else hSpMusClas->tdm_lt_Etot = 0.01f; 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; hSpMusClas->tod_weight = 0.0f; hSpMusClas->tod_S_mass_prev = 0.0f; hSpMusClas->tod_S_mass_lt = 0.0f; -#endif /* speech/music classification */ set_s( hSpMusClas->lt_old_mode, 1, 3 ); -#ifndef IVAS_FLOAT_FIXED hSpMusClas->lt_voicing_flt = 0.5f; hSpMusClas->lt_corr_flt = 0.5f; hSpMusClas->lt_tonality_flt = 0; -#endif set_s( hSpMusClas->lt_corr_pitch, 0, 3 ); hSpMusClas->lt_hangover = 0; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->lowrate_pitchGain_flt = 0; -#endif hSpMusClas->lt_music_hangover = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->tonality2_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->tonality3_buf, 0, HANG_LEN_INIT ); set_f( hSpMusClas->LPCErr_buf, 0, HANG_LEN_INIT ); -#endif hSpMusClas->lt_music_state = 0; hSpMusClas->lt_speech_state = 0; hSpMusClas->lt_speech_hangover = 0; -#ifndef IVAS_FLOAT_FIXED hSpMusClas->lt_dec_thres = 10.0f; hSpMusClas->ener_RAT = 0.0f; -#endif hSpMusClas->high_stable_cor = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hSpMusClas->var_cor_t, 0.0f, VAR_COR_LEN ); hSpMusClas->lps = 0.0f; hSpMusClas->lpm = 0.0f; hSpMusClas->lpn = 0.0f; -#endif return; } -#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * speech_music_classif() * diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 74be752ff..7e0de47b1 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -336,6 +336,8 @@ void speech_music_clas_init_ivas_fx( hSpMusClas->last_non_sta_fx = 0; move16(); set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); + hSpMusClas->past_PS_Q = Q31; + move16(); hSpMusClas->past_ps_diff_fx = 0; move16(); hSpMusClas->past_epsP2_fx = 1024; /* 1.0f in Q10 */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index ea6c413af..dddf78e3d 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -427,7 +427,7 @@ typedef struct td_cng_enc_structure 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 */ + Word32 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 */ @@ -720,7 +720,8 @@ typedef struct noise_estimation_structure float act_pred; /* Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ float multi_harm_limit; /* Tonal detector - adaptive threshold */ #endif - float ave_enr2[NB_BANDS]; /* Tonal detector - LT average E per crit. band (for non_sta2) */ + float ave_enr2[NB_BANDS]; /* Tonal detector - LT average E per crit. band (for non_sta2) */ + Word16 ave_enr_q; float enrO[NB_BANDS]; /* Noise estimator - previous energy per critical band */ float bckr[NB_BANDS]; /* Noise estimator - background noise estimation per critical band */ float ave_enr[NB_BANDS]; /* Noise estimator - long-term average energy per critical band */ @@ -731,8 +732,10 @@ typedef struct noise_estimation_structure Word16 act_pred_fx; /* Q15 Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ Word16 multi_harm_limit_fx; /* Q9 Tonal detector - adaptive threshold */ Word32 enrO_fx[NB_BANDS]; /* Noise estimator - previous energy per critical band */ - Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ - Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ + Word16 q_enr; + Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ + Word16 q_bckr; + Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ Word16 aEn; /* Noise estimator - noise estimator adaptation flag */ #ifndef IVAS_FLOAT_FIXED @@ -808,20 +811,17 @@ typedef struct sp_mus_clas_structure { #ifndef IVAS_FLOAT_FIXED float FV_st[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector */ -#else - Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ -#endif - 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; float past_epsP2; #else - Word16 past_ps_diff_fx; /* Q10 */ - Word32 prev_FV_fx[N_SMC_FEATURES]; /* Q20 */ + Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ + Word32 past_PS_fx[HIGHEST_FBIN - LOWEST_FBIN]; /* Q(past_PS_Q) */ + Word16 past_PS_Q; + Word16 past_ps_diff_fx; /* Q10 */ + Word32 prev_FV_fx[N_SMC_FEATURES]; /* Q20 */ Word16 past_epsP_fx; Word16 past_epsP2_fx; /* Q10 */ #endif @@ -871,7 +871,6 @@ typedef struct sp_mus_clas_structure Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation Q8 */ Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory Q8 */ #endif - 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 */ @@ -927,7 +926,6 @@ typedef struct sp_mus_clas_structure Word16 buf_Ntonal_lf_fx[BUF_LEN]; /* Q0 */ Word16 buf_dlp_fx[10]; /* Q9 */ #endif - Word16 onset_cnt; #ifndef IVAS_FLOAT_FIXED float buf_etot[4]; @@ -956,12 +954,11 @@ typedef struct sp_mus_clas_structure #ifndef IVAS_FLOAT_FIXED float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ float lt_finc; /* strong attack detection - long-term finc energy */ +#else + 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) */ #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 */ - Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_tod_lt_Bin_E */ - Word16 Q_tod_lt_Bin_E; + Word16 last_strong_attack; /* strong attack detection - last strong attack flag */ #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 */ @@ -970,11 +967,13 @@ typedef struct sp_mus_clas_structure float tod_S_mass_prev; float tod_S_mass_lt; #else - Word32 tod_S_map_lt_fx[TOD_NSPEC]; /* tonal detector - long-term correlation map, Q22 */ - Word32 tod_thr_lt_fx; /* tonal detector - adaptive threshold, Q22 */ - Word16 tod_weight_fx; /* tonal detector - adaptive weight, Q15 */ - Word32 tod_S_mass_prev_fx; /* Q22 */ - Word32 tod_S_mass_lt_fx; /* Q22 */ + Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_tod_lt_Bin_E */ + Word16 Q_tod_lt_Bin_E; + Word32 tod_S_map_lt_fx[TOD_NSPEC]; /* tonal detector - long-term correlation map, Q22 */ + Word32 tod_thr_lt_fx; /* tonal detector - adaptive threshold, Q22 */ + Word16 tod_weight_fx; /* tonal detector - adaptive weight, Q15 */ + Word32 tod_S_mass_prev_fx; /* Q22 */ + Word32 tod_S_mass_lt_fx; /* Q22 */ #endif Word16 lt_music_hangover; @@ -983,9 +982,9 @@ typedef struct sp_mus_clas_structure float tonality3_buf[HANG_LEN_INIT]; float LPCErr_buf[HANG_LEN_INIT]; #else - Word16 tonality2_buf_fx[HANG_LEN_INIT]; /* Q14 */ - Word16 tonality3_buf_fx[HANG_LEN_INIT]; /* Q14 */ - Word16 LPCErr_buf_fx[HANG_LEN_INIT]; /* Q10 */ + Word16 tonality2_buf_fx[HANG_LEN_INIT]; /* Q14 */ + Word16 tonality3_buf_fx[HANG_LEN_INIT]; /* Q14 */ + Word16 LPCErr_buf_fx[HANG_LEN_INIT]; /* Q10 */ #endif Word16 lt_music_state; Word16 lt_speech_state; @@ -994,8 +993,8 @@ typedef struct sp_mus_clas_structure float lpe_buf[HANG_LEN_INIT]; float voicing_buf[HANG_LEN_INIT]; #else - Word16 lpe_buf_fx[HANG_LEN_INIT]; /* Q10 */ - Word16 voicing_buf_fx[HANG_LEN_INIT]; /* Q13 */ + Word16 lpe_buf_fx[HANG_LEN_INIT]; /* Q10 */ + Word16 voicing_buf_fx[HANG_LEN_INIT]; /* Q13 */ #endif Word16 gsc_hangover; #ifndef IVAS_FLOAT_FIXED @@ -1025,10 +1024,14 @@ typedef struct sp_mus_clas_structure Word16 lt_hangover; #ifndef IVAS_FLOAT_FIXED float lowrate_pitchGain_flt; +#else + Word16 lowrate_pitchGain; /* Q14 */ +#endif + +#ifndef IVAS_FLOAT_FIXED float tdm_lt_Etot; float var_cor_t[VAR_COR_LEN]; #else - Word16 lowrate_pitchGain; /* Q14 */ Word16 tdm_lt_Etot_fx; /* Q8 */ Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ #endif @@ -1578,37 +1581,41 @@ typedef struct td_bwe_enc_structure typedef struct fd_bwe_enc_structure { +#ifndef IVAS_FLOAT_FIXED float new_input_hp[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS )]; float old_input[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS )]; - Word16 new_input_hp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS )]; - Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS )]; +#endif + Word16 new_input_hp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS )]; // q0 + Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS )]; // q0 #ifndef IVAS_FLOAT_FIXED float old_input_wb[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; #else Word16 old_input_wb_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; /* Q(-1) */ #endif - float old_input_lp[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; #ifndef IVAS_FLOAT_FIXED + float old_input_lp[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; float old_fdbwe_speech[L_FRAME48k]; float mem_deemph_old_syn; #endif - Word16 old_input_lp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; - Word16 old_syn_12k8_16k_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; + Word16 old_input_lp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; // st->hBWE_FD->prev_Q_input_lp + Word16 old_syn_12k8_16k_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; // st->Q_syn Word16 old_fdbwe_speech_fx[L_FRAME48k]; Word16 mem_deemph_old_syn_fx; Word16 q_mem_deemph_old_syn; - int16_t prev_mode; + Word16 prev_mode; +#ifndef IVAS_FLOAT_FIXED float old_wtda_swb[L_FRAME48k]; +#endif Word16 L_old_wtda_swb_fx[L_FRAME48k]; /* Q(Q_old_wtda) */ Word16 prev_Q_input_lp; - int16_t prev_L_swb_norm1; + Word16 prev_L_swb_norm1; #ifndef IVAS_FLOAT_FIXED float prev_global_gain; #else Word32 prev_global_gain_fx; /* Q(2 * prev_Q_shb) */ #endif - int16_t modeCount; + Word16 modeCount; #ifndef IVAS_FLOAT_FIXED float EnergyLF; float mem_old_wtda_swb; @@ -2088,11 +2095,12 @@ typedef struct enc_core_structure /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ Word16 mem_wsp_fx; /* weighted signal vector memory */ - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 mem_wsp_q; + Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ + Word16 mem_deemph_fx; /* deemphasis filter memory */ + Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ int16_t GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; diff --git a/lib_enc/swb_bwe_enc.c b/lib_enc/swb_bwe_enc.c index 5a716d6f0..e3abfa4a1 100644 --- a/lib_enc/swb_bwe_enc.c +++ b/lib_enc/swb_bwe_enc.c @@ -1849,6 +1849,7 @@ void hq_generic_hf_encoding( * Initialize FD BWE state structure at the encoder *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void fd_bwe_enc_init( FD_BWE_ENC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ) @@ -1899,3 +1900,4 @@ void fd_bwe_enc_init( return; } +#endif diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 3c673d138..de3f5b3e1 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -4310,6 +4310,8 @@ void fd_bwe_enc_init_fx( hBWE_FD->modeCount = 0; move16(); hBWE_FD->EnergyLF_fx = 0; + hBWE_FD->mem_old_wtda_swb_fx = 0; + move32(); move32(); hBWE_FD->prev_Q_input_lp = 0; @@ -4318,6 +4320,8 @@ void fd_bwe_enc_init_fx( hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); + hBWE_FD->q_mem_deemph_old_syn = 0; + move16(); // hBWE_FD->mem_old_wtda_swb = 0.0f; return; diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 29461ffb2..bb18bb23c 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -44,10 +44,8 @@ #include "rom_enc.h" #include "wmc_auto.h" #include "ivas_prot.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx_enc.h" -#endif +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ @@ -60,7 +58,6 @@ * Local function prototypes *-----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void return_M_Least( const float *inp, const int16_t n_cols, const float *codebook, const int16_t num_grp, const float *weight, const int16_t interNum, int16_t *least ); static void singlevectortest_gain( const float *inp, const int16_t dimen, const int16_t cb_size, int16_t *index, const float *weight, float *recon, const float *codebook ); static void determine_gain_weights( const float *gain, float *weights, const int16_t dims ); @@ -79,7 +76,6 @@ static void Quant_BWE_LSF( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, con static void Quant_shb_ener_sf( Encoder_State *st, float *shb_ener_sf ); static void Quant_shb_res_gshape( Encoder_State *st, float *shb_res_gshape ); static void LVQQuant_BWE_LSF( BSTR_ENC_HANDLE hBstr, const float lsf_shb[], float Q_lsfs[], int16_t nbits ); -#endif /*-------------------------------------------------------------------* * InitSWBencBuffer() @@ -95,7 +91,6 @@ void InitSWBencBuffer( hBWE_TD->bwe_seed[0] = 23; hBWE_TD->bwe_seed[1] = 59; -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) ); set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale = 0; @@ -107,41 +102,13 @@ void InitSWBencBuffer( set_f( hBWE_TD->elliptic_bpf_2_48k_mem[2], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); hBWE_TD->prev_fb_energy = 0.0f; -#else - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - - set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); - set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); - hBWE_TD->prev_fb_energy_fx = 0; - move16(); - hBWE_TD->prev_fb_energy_fx_Q = 0; - move16(); -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); -#else - set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); - set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); -#endif -#ifdef IVAS_FLOAT_FIXED - InitSWBencBufferStates_fx( hBWE_TD, NULL ); -#else InitSWBencBufferStates( hBWE_TD, NULL ); -#endif -#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->prev_lsp_shb[i] = i / 20.0f; @@ -151,55 +118,21 @@ void InitSWBencBuffer( hBWE_TD->prev_gainFr_SHB = 0; set_f( hBWE_TD->lsp_shb_slow_interpl, 0, LPC_SHB_ORDER ); set_f( hBWE_TD->lsp_shb_fast_interpl, 0, LPC_SHB_ORDER ); -#else - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_fx[i]; - } - - hBWE_TD->cldfbHBLT = 8192; - hBWE_TD->prev_gainFr_SHB_fx = 0; - set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->shb_inv_filt_mem, 0, LPC_SHB_ORDER ); set_f( hBWE_TD->lsp_shb_spacing, 0.1f, 3 ); hBWE_TD->prev_swb_GainShape = 0; -#else - set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277, 3 ); - hBWE_TD->prev_swb_GainShape_fx = 0; -#endif hBWE_TD->prev_frGainAtten = 0; -#ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_wb_GainShape_flt = 0; set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0.0f; hBWE_TD->tilt_mem = 0.0f; -#else - hBWE_TD->prev_wb_GainShape = 0; - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - hBWE_TD->tilt_mem_fx = 0; - move16(); -#endif hBWE_TD->prev_coder_type = GENERIC; -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para = 0.0f; set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 ); -#else - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = 0; - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); - move16(); -#endif /* TD BWE post-processing */ -#ifndef IVAS_FLOAT_FIXED hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); @@ -207,29 +140,14 @@ void InitSWBencBuffer( { hBWE_TD->swb_lsp_prev_interp[i] = (float) cos( (float) i * EVS_PI / (float) 10.0f ); } -#else - hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; - } -#endif - -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->dec_2_over_3_mem, 0.0f, L_FILT_2OVER3 ); set_f( hBWE_TD->dec_2_over_3_mem_lp, 0.0f, L_FILT_2OVER3_LP ); -#else - set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); - set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); -#endif return; } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * InitSWBencBufferStates() * @@ -2931,7 +2849,6 @@ void tbe_write_bitstream( return; } -#endif /*---------------------------------------------------------------------* * TBEreset_enc() @@ -2947,66 +2864,34 @@ void TBEreset_enc( { if ( last_core != ACELP_CORE ) { -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale = 0.f; -#else - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif } if ( bwidth == WB ) { -#ifndef IVAS_FLOAT_FIXED wb_tbe_extras_reset( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3 ); set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, 7 ); set_f( hBWE_TD->state_lpc_syn, 0, 10 ); set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); -#else - wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); - set16_fx( hBWE_TD->state_lpc_syn_fx, 0, 10 ); - set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->mem_csfilt, 0, 2 ); -#else - set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); -#endif } else if ( bwidth == SWB || bwidth == FB ) { -#ifdef IVAS_FLOAT_FIXED - set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#else set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#endif -#ifdef IVAS_FLOAT_FIXED - swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); -#else swb_tbe_reset( hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, hBWE_TD->syn_overlap, hBWE_TD->state_syn_shbexc, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), hBWE_TD->mem_stp_swb, &( hBWE_TD->gain_prec_swb ) ); -#endif - if ( bwidth == FB ) { -#ifdef IVAS_FLOAT_FIXED - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; - fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); -#else set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; fb_tbe_reset_enc( hBWE_TD->elliptic_bpf_2_48k_mem, &hBWE_TD->prev_fb_energy ); -#endif } } return; } +#endif diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 722e7c6e7..676b16ea2 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -528,16 +528,13 @@ void InitSWBencBuffer_ivas_fx( hBWE_TD->old_input_fhb_fx_Q = 0; move16(); - // IVAS_CODE - // set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); - // set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); - // hBWE_TD->old_mean_EnvSHBres = 0.0f; - // hBWE_TD->prev_enr_EnvSHBres = 1.0f; - // hBWE_TD->prev_shb_env_tilt = 0.0f; - // hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; - // hBWE_TD->prev_mix_factor = 1.0f; - // hBWE_TD->prev_Env_error = 0.0f; - set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, 10 ); + InitSWBencBufferStates_fx( hBWE_TD, NULL ); + + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_fx[i]; + move16(); + } hBWE_TD->cldfbHBLT = 8192; /* 1.0f Q13 */ move16(); @@ -3642,13 +3639,13 @@ void swb_tbe_enc_ivas_fx( move16(); // Replace with IVAS equivalent - GenShapedSHBExcitation_ivas_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, - hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, - shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st_fx->extl_brate, MSFlag, - EnvSHBres_4k_norm_fx, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); + GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, + shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st_fx->extl_brate, MSFlag, + EnvSHBres_4k_norm_fx, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); *Q_white_exc = Q_bwe_exc_fb; move16(); @@ -3707,8 +3704,8 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { - PostShortTerm_ivas_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); + PostShortTerm_ivas_enc_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); /* i: shaped_shb_excitation_fx in Q_bwe_exc */ /* i: lpc_shb_fx in Q12 */ } -- GitLab