diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 4e380b17cb53c5d82323615496cef9aa501059c0..b4d09d5eca50e2d76f6236c0345d5a3ef18fa5ec 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1601,6 +1601,7 @@ void ivas_hq_core_dec_fx( Word16 *Q_output ); +#ifndef HARMONIZE_TBE void ivas_HQ_FEC_Mem_update_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 *t_audio_q_fx, /*Q12*/ @@ -1616,6 +1617,7 @@ void ivas_HQ_FEC_Mem_update_fx( Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ Word16 output_frame ); +#endif /* o : Consumed bits Q0 */ Word16 ivas_hq_classifier_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -1865,6 +1867,7 @@ void stereoFdCngCoherence_fx( Word16 fft_exp ); +#ifndef HARMONIZE_TBE void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -1893,7 +1896,7 @@ void GenShapedWBExcitation_ivas_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); - +#endif /* o : Q_syn_hb*/ Word16 ivas_wb_bwe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ diff --git a/lib_com/options.h b/lib_com/options.h index b584b6931635ad178abfed1de4261fbdae27545a..6c867c693d5e7b3f385fedf9aaac780ed2e06a79 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -107,6 +107,7 @@ #define FIX_2383_INIT_Q_A_ITF /* FhG: Initialize Q_A_itf, to avoid reading of uninitialized memory in case ITF is not triggered */ #define FIX_2382_COPY_AQ_IN_MCT /* FhG: basop issue 2382: 2nd instance of prevent copying uninitialized values from Aq_fx[][] to Aq_fx_32[][] in TCX */ #define FIX_2391_INIT_HQ_GENERIC_OFFSET /* FhG/Eri: basop issue 2391: make sure hq_generic_offset is initialized inside hq_hr_dec_fx() */ +#define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3b93fda3b80ef0349421a8b29b784c656d3022be..c45c2a7490d98886919391ee55e3dcb80560eff0 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2856,11 +2856,12 @@ void Calc_rc0_h( Word16 *rc0 /* o : 1st parcor */ ); +#ifndef HARMONIZE_TBE void Calc_rc0_h_ivas_enc_fx( Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ); - +#endif void PostShortTerm_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -2895,11 +2896,11 @@ void PostShortTerm_ivas_dec_fx( ); void flip_spectrum_and_decimby4_fx( - const Word16 i[], /* i : i spectrum */ + const Word16 i[], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory */ - Word16 mem2[], /* i/o : memory */ + Word16 mem1[], /* i/o: memory */ + Word16 mem2[], /* i/o: memory */ const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core */ ); @@ -2913,69 +2914,90 @@ void GenShapedWBExcitation_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */ Word16 *state_lpc_syn, /* i/o : memory */ const Word16 coder_type, /* i : coding type */ - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor */ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o : random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor */ const Word16 signal_type, const Word16 igf_flag ); +#ifdef HARMONIZE_TBE +void GenShapedWBExcitation_ivas_fx( + Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32 *mem_csfilt, /* i/o: memory Q_bwe_exc+16*/ + Word16 *mem_genSHBexc_filt_down1, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down2, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down3, /* i/o: memory Q_bwe_exc*/ + Word16 *state_lpc_syn, /* i/o: memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag /* i : IGF flag */ +); + +#endif void GenWBSynth_fx( - const Word16 *input_synspeech, /* i : i synthesized speech */ + const Word16 *input_synspeech, /* i : i synthesized speech */ Word16 *shb_syn_speech_16k, /* o : output highband compnent */ Word16 *state_lsyn_filt_shb1, /* i/o: memory */ Word16 *state_lsyn_filt_shb2 /* i/o: memory */ ); void GenShapedSHBExcitation_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 */ + 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 element_mode, /* i : element mode */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ + 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: i shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: i res gain shape, Q14 */ + Word16 *lpc_shb_sf, /* i : LP coefficients */ + const Word32 shb_ener_sf_32, /* i : i shb ener, Q31 */ + Word16 *shb_res_gshape, /* i : i res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + 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 */ + 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 ); 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_fb */ + 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_fb */ 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 */ + 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 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 *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] */ @@ -3087,19 +3109,19 @@ void ScaleShapedSHB_fx32( Word16 *Q_new ); void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o : synthesized shb signal */ - Word16 *overlap, /* i/o : buffer for overlap-add */ - const Word16 *subgain, /* i : subframe gain */ - const Word32 frame_gain, /* i : frame gain */ - const Word16 *win, /* i : window */ - const Word16 *subwin, /* i : subframes window */ - const Word16 Q_bwe_exc, - Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ - Word16 *Qx, /* o : newly computed Q factor for synSHB */ - Word16 prev_Qx, /* i : prev_Qx for memory scaling */ - Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o: synthesized shb signal */ + Word16 *overlap, /* i/o: buffer for overlap-add */ + const Word16 *subgain, /* i : subframe gain */ + const Word32 frame_gain, /* i : frame gain */ + const Word16 *win, /* i : window */ + const Word16 *subwin, /* i : subframes window */ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ + Word16 *Qx, /* o : newly computed Q factor for synSHB */ + Word16 prev_Qx, /* i : prev_Qx for memory scaling */ + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ); void non_linearity_fx( @@ -5775,6 +5797,7 @@ void swb_tbe_dec_fx( Word16 *Q_synth, Word16 *pitch_buf ); +#ifndef HARMONIZE_TBE void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ @@ -5787,8 +5810,9 @@ void ivas_dequantizeSHBparams_fx_9_1( Word16 *Q_shb_res_gshape, /* o : Q14 */ Word16 *Q_mixFactors, /* o : Q15 */ Word16 *MSFlag ); - +#endif void fb_tbe_dec_fx( +#ifndef HARMONIZE_TBE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, @@ -5796,9 +5820,13 @@ void fb_tbe_dec_fx( Word16 hb_synth_exp ); void fb_tbe_dec_ivas_fx( +#endif Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, +#ifdef HARMONIZE_TBE + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ +#endif Word32 *hb_synth, /* o : high-band synthesis */ Word16 hb_synth_exp, Word16 *fb_synth_ref, diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index e06c8c4f6dad19a1a405f68ca90234158f2ee838..8f5f19d13763f2c67f45eaaf9cc77ad6a61e3147 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -8,30 +8,29 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" #include "basop_util.h" -#include "ivas_prot_fx.h" /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -#define POW_EXC16k_WHTND 1.14e11f /* power of random excitation, length 320 samples, uniform distribution */ -#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 // Q31 +#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 // 1.14e11f in Q31 power of random excitation, length 320 samples, uniform distribution #define POW_EXC16k_WHTND_FX_INV_SQRT_IN_Q49 1667313793 // Q49 #define POW_EXC16k_WHTND_FX 178125000 // Q-6 -#define THR_ENV_ERROR_PLOSIVE 200.0f /* threshold for envelope error used in plosive detection */ #define THR_ENV_ERROR_PLOSIVE_FX 200 /* threshold for envelope error used in plosive detection Q0 */ + /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[], Word16 element_mode ); static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); -static void Calc_st_filt_tbe( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); +static void Calc_st_filt_tbe_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); -void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); +static void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); + /*-------------------------------------------------------------------* * swb_tbe_reset() @@ -720,9 +719,15 @@ void Calc_rc0_h( *rc0 = negate( *rc0 ); move16(); } + + return; } +#ifdef HARMONIZE_TBE +static void Calc_rc0_h_ivas_enc_fx( +#else void Calc_rc0_h_ivas_enc_fx( +#endif Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ) @@ -781,7 +786,7 @@ void Calc_rc0_h_ivas_enc_fx( } } -static void Calc_st_filt_tbe( +static void Calc_st_filt_tbe_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ @@ -819,6 +824,8 @@ static void Calc_st_filt_tbe( move16(); } } + + return; } static void Calc_st_filt_tbe_ivas_enc_fx( @@ -859,8 +866,11 @@ static void Calc_st_filt_tbe_ivas_enc_fx( move16(); } } + + return; } +#ifndef HARMONIZE_TBE static void Calc_st_filt_tbe_ivas_dec_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ @@ -899,8 +909,10 @@ static void Calc_st_filt_tbe_ivas_dec_fx( move16(); } } -} + return; +} +#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : output signal */ @@ -1103,7 +1115,7 @@ void PostShortTerm_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); + Calc_st_filt_tbe_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 */ @@ -1223,7 +1235,11 @@ void PostShortTerm_ivas_dec_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ +#ifdef HARMONIZE_TBE + Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); +#else Calc_st_filt_tbe_ivas_dec_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); +#endif /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ @@ -1240,6 +1256,13 @@ void PostShortTerm_ivas_dec_fx( return; } + +/*-------------------------------------------------------------------* + * flip_spectrum_and_decimby4() + * + * + *-------------------------------------------------------------------*/ + void flip_spectrum_and_decimby4_fx( const Word16 input[], /* i : input spectrum Q_inp */ Word16 output[], /* o : output spectrum Q_inp */ @@ -1319,22 +1342,23 @@ void flip_spectrum_and_decimby4_fx( /*==========================================================================*/ void GenShapedWBExcitation_ivas_fx( - Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ - Word32 *mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ - Word16 *mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ - Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ - const Word16 coder_type, /* i : coding type */ - const Word16 element_mode, /* i : element mode */ - const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor Q15*/ - const Word16 uv_flag, /* i : unvoiced flag */ - const Word16 igf_flag ) + Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32 *mem_csfilt, /* i/o: memory Q_bwe_exc+16*/ + Word16 *mem_genSHBexc_filt_down1, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down2, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down3, /* i/o: memory Q_bwe_exc*/ + Word16 *state_lpc_syn, /* i/o: memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag /* i : IGF flag */ +) { Word16 i, j, k; Word16 wht_fil_mem[LPC_WHTN_ORDER_WB]; @@ -4868,7 +4892,6 @@ void ScaleShapedSHB_fx( } } - Q_gFr_norm = norm_l( frame_gain ); if ( frame_gain == 0 ) { @@ -5106,19 +5129,19 @@ void ScaleShapedSHB_fx32( *-------------------------------------------------------------------*/ void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ - Word16 *overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ - const Word16 *subgain, /* i : subframe gain Q15*/ - const Word32 frame_gain, /* i : frame gain Q18 */ - const Word16 *win, /* i : window Q15*/ - const Word16 *subwin, /* i : subframes window Q15*/ - const Word16 Q_bwe_exc, - Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ - Word16 *Qx, /* o : newly computed Q factor for synSHB */ - Word16 prev_Qx, /* i : prev_Qx for memory scaling */ - Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o: synthesized shb signal Q_bwe_exc/Qx*/ + Word16 *overlap, /* i/o: buffer for overlap-add Q_bwe_exc/Qx*/ + const Word16 *subgain, /* i : subframe gain Q15*/ + const Word32 frame_gain, /* i : frame gain Q18*/ + const Word16 *win, /* i : window Q15*/ + const Word16 *subwin, /* i : subframes window Q15*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ + Word16 *Qx, /* o : newly computed Q factor for synSHB */ + Word16 prev_Qx, /* i : prev_Qx for memory scaling */ + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ) { const Word16 *skip; @@ -5128,6 +5151,7 @@ void ScaleShapedWB_fx( Word16 sum_gain; Word32 L_tmp; Word16 max_val, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2; + /* Init */ set32_fx( mod_syn, 0, L_FRAME16k + L_SHB_LAHEAD ); @@ -5225,7 +5249,6 @@ void ScaleShapedWB_fx( } } - max_val = 0; move16(); FOR( i = 0; i < l_frame + l_shb_lahead; i++ ) @@ -5997,6 +6020,7 @@ void interp_code_5over2_fx( Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] ); /*Q(16+x) */ interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ move16(); + return; } @@ -6224,7 +6248,6 @@ void elliptic_bpf_48k_generic_fx( } /*IsUpsampled3*/ - memory_fx2[0][0] = input_fx[L_FRAME48k - 4]; memory_fx2[0][1] = input_fx[L_FRAME48k - 3]; memory_fx2[0][2] = input_fx[L_FRAME48k - 2]; @@ -6272,7 +6295,6 @@ void elliptic_bpf_48k_generic_fx( } } - Q_temp = norm_l( L_tmpMax ); Q_temp = sub( Q_temp, 4 ); Scale_sig32( L_tmp2, 960, Q_temp ); @@ -6334,7 +6356,6 @@ void elliptic_bpf_48k_generic_fx( } } - memory_fx2[2][0] = L_tmp2[L_FRAME48k - 4]; memory_fx2[2][1] = L_tmp2[L_FRAME48k - 3]; memory_fx2[2][2] = L_tmp2[L_FRAME48k - 2]; @@ -6372,6 +6393,8 @@ void elliptic_bpf_48k_generic_fx( return; } + + /*-------------------------------------------------------------------* * synthesise_fb_high_band() * @@ -6428,20 +6451,12 @@ void synthesise_fb_high_band_fx( IF( EQ_16( L_frame, L_FRAME16k ) ) { /* for 16kHz ACELP core */ - elliptic_bpf_48k_generic_fx( - element_mode, - 1, // IsUpsampled3 - excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_3_fx - - ); + elliptic_bpf_48k_generic_fx( element_mode, 1, /* IsUpsampled3 */ excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_3_fx ); } ELSE { /* for 12.8kHz ACELP core */ - elliptic_bpf_48k_generic_fx( - element_mode, - 1, // IsUpsampled3 - excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_1_fx ); + elliptic_bpf_48k_generic_fx( element_mode, 1, /* IsUpsampled3 */ excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_1_fx ); } /* temp1 = sum2_f( tmp, L_FRAME48k ) + 0.001f */ temp1 = sum2_fx_mod( tmp, L_FRAME48k ); @@ -6524,15 +6539,18 @@ void synthesise_fb_high_band_fx( move16(); } } + return; } + /*-------------------------------------------------------------------* * Estimate_mix_factors_fx() * * * * Estimate mix factors for SHB excitation generation * *-------------------------------------------------------------------*/ -void Estimate_mix_factors_fx( + +static void Estimate_mix_factors_fx( const Word16 *shb_res, /* i : SHB LP residual in Q = Q_shb */ const Word16 Q_shb, const Word16 *exc16kWhtnd, /* i : SHB transformed low band excitation Q_bwe_exc */ @@ -6596,7 +6614,6 @@ void Estimate_mix_factors_fx( /* (Q_bwe_exc) */ } - length = L_FRAME16k; move16(); temp_p1_p2 = Dot_product( temp_numer1, temp_numer2, length ); /* 2*(Q_bwe_exc)+1 */ @@ -6672,6 +6689,7 @@ void Estimate_mix_factors_fx( return; } + /*======================================================================================*/ /* FUNCTION : prep_tbe_exc_fx() */ /*--------------------------------------------------------------------------------------*/ @@ -6721,7 +6739,6 @@ void prep_tbe_exc_fx( const Word16 idchan, /* i : channel ID */ const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ - ) { Word16 i; diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index f320e323fed3788b9c9c5dfd24bc90cc3223c263..07b2deddc3d6b0309a992cb26e82a6784253f8e7 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -408,7 +408,11 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { +#ifdef HARMONIZE_TBE + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); +#else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); +#endif } } ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) || @@ -843,7 +847,11 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { +#ifdef HARMONIZE_TBE + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); +#else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); +#endif } } Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index a412ff27d789fbdf3e0967d8916e51e8769e424c..a7eebafb52ad074c4d463f449fb59273acbc515a 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1015,7 +1015,11 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ +#ifdef HARMONIZE_TBE + wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); +#else ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); +#endif } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) { @@ -1079,7 +1083,11 @@ ivas_error ivas_core_dec_fx( /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { +#ifdef HARMONIZE_TBE + fb_tbe_dec_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, NULL, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); +#else fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); +#endif } } ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || flag_bwe_bws ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index b9fb6f1b7ca9a1813ed22210d1e3ba9fa8effe95..2d99d9a4a27d6d849bd47e1bc6719296bf2a35d5 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -2,22 +2,22 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ - #include #include "options.h" #include "rom_com.h" #include "prot_fx.h" #include "rom_dec.h" -#include "stl.h" - #include "ivas_prot_fx.h" /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ +#ifdef HARMONIZE_TBE +static void dequantizeSHBparams_fx( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors, Word16 *MSFlag ); +#else static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors ); - +#endif static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2, Word16 *n_mem3 ); static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ); static void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ); @@ -27,15 +27,15 @@ static void Map_higher_LSF_fx( Word16 lsf_q[], const Word16 m, const Word16 grid static void Dequant_mirror_point_fx( const Word16 lsf_q[], const Word16 m_idx, Word16 *m ); static Word16 dotp_loc( const Word16 x[], const Word32 y[], const Word16 n ); static void find_max_mem_dec_m3( Decoder_State *st, Word16 *n_mem3 ); - -/* gain shape concealment code */ static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, Word32 *GainFrame ); + /*-------------------------------------------------------------------* * find_max_mem_dec() * * Find norm and max in TBE memories and past buffers *-------------------------------------------------------------------*/ + static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, @@ -219,14 +219,17 @@ static void find_max_mem_dec( because of the Hilber transform and Q14 coeffs */ *n_mem3 = s_max( tempQ15, 0 ); move16(); - /* --------------------------------------------------------------*/ + + return; } + /*-------------------------------------------------------------------* * rescale_genSHB_mem_dec() * * Rescale genSHB memories *-------------------------------------------------------------------*/ + static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ) @@ -255,20 +258,25 @@ static void rescale_genSHB_mem_dec( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { +#ifdef HARMONIZE_TBE + hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf ); +#else hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); +#endif move16(); } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { +#ifdef HARMONIZE_TBE + hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf ); +#else hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); +#endif move16(); } } - if ( EQ_16( st_fx->extl, FB_TBE ) ) - { - } hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); move32(); @@ -276,9 +284,14 @@ static void rescale_genSHB_mem_dec( move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); + + return; } -void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) + +static void find_max_mem_wb( + Decoder_State *st_fx, + Word16 *n_mem ) { Word16 i; Word16 max = 0; @@ -311,21 +324,18 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) FOR( i = 0; i < 7; i++ ) { - if ( GT_16( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ), max ) ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } FOR( i = 0; i < 10; i++ ) { - if ( GT_16( abs_s( hBWE_TD->state_lpc_syn_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); } FOR( i = 0; i < 5; i++ ) { - if ( GT_16( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); } @@ -341,10 +351,8 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) move16(); } - FOR( i = 0; i < 2; i++ ) { - if ( GT_32( L_abs( hBWE_TD->mem_csfilt_fx[i] ), Lmax ) ) Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } @@ -363,9 +371,14 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) move16(); *n_mem = s_max( *n_mem, 0 ); move16(); + + return; } -void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ) + +static void rescale_genWB_mem( + Decoder_State *st_fx, + Word16 sf ) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -466,6 +479,12 @@ static void InitSWBdecBuffer_fx( } +/*-------------------------------------------------------------------* + * ResetSHBbuffer_Dec() + * + * + *-------------------------------------------------------------------*/ + void ResetSHBbuffer_Dec_fx( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 extl /* i : BWE extension layer */ @@ -587,20 +606,25 @@ void ResetSHBbuffer_Dec_fx( /* _Word16 *synth o : WB synthesis/final synthesis Q_synth */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx, i/o: decoder state structure */ +/* Decoder_State *st_fx, i/o: decoder state structure */ /*--------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ /* CALLED FROM : */ /*==========================================================================*/ + +#ifdef HARMONIZE_TBE +void wb_tbe_dec_fx( +#else void ivas_wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type Q0 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors Q15 */ - Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ +#endif + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type Q0 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc */ + const Word16 Q_exc, /* i : Q_exc factor */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -635,8 +659,10 @@ void ivas_wb_tbe_dec_fx( Word16 f, inc; Word64 W_tmp; TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; set32_fx( &dummy2[0], 0, HILBERT_MEM_SIZE ); + IF( st_fx->bws_cnt == 0 ) { /* Initialization */ @@ -750,9 +776,14 @@ void ivas_wb_tbe_dec_fx( } ELSE { +#ifdef HARMONIZE_TBE + /* de-quantization */ + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &j /*temp*/ ); +#else /* de-quantization */ Word16 ignore; ivas_dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &ignore ); +#endif } } ELSE @@ -835,9 +866,21 @@ void ivas_wb_tbe_dec_fx( /* From low band excitation, generate highband excitation */ Lmax = 0; move32(); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + } + } + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + } } IF( Lmax == 0 ) { @@ -848,7 +891,16 @@ void ivas_wb_tbe_dec_fx( { Q_bwe_exc = norm_l( Lmax ); } - Q_bwe_exc = sub( Q_bwe_exc, 3 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Q_bwe_exc = sub( Q_bwe_exc, 1 ); + } + ELSE +#endif + { + Q_bwe_exc = sub( Q_bwe_exc, 3 ); + } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); find_max_mem_wb( st_fx, &n_mem ); @@ -865,38 +917,82 @@ void ivas_wb_tbe_dec_fx( move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } - W_tmp = 0; - move64(); - IF( st_fx->element_mode > EVS_MONO ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - W_tmp = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + prev_pow = 0; + move32(); + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0_sat( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + } } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + ELSE +#endif { - W_tmp = W_mac_16_16( W_tmp, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16 + 1))*/ + W_tmp = 0; + move64(); + tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); + W_tmp = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + W_tmp = W_mac_16_16( W_tmp, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16 + 1))*/ + } + exp = W_norm( W_tmp ); + prev_pow = W_extract_h( W_shl( W_tmp, exp ) ); + exp = sub( add( add( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 1 ), exp ), 32 ); } - exp = W_norm( W_tmp ); - prev_pow = W_extract_h( W_shl( W_tmp, exp ) ); - exp = sub( add( add( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 1 ), exp ), 32 ); rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } +#endif + sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - bwe_exc_extended_16[cnt] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); - move16(); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } + + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + bwe_exc_extended_16[cnt] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); + move16(); + } } Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, - bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); + } + ELSE +#endif + { + GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); + } curr_pow = 0; move32(); @@ -915,8 +1011,16 @@ void ivas_wb_tbe_dec_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, - exp, &exp ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + } + ELSE +#endif + { + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, exp, &exp ); + } FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) { @@ -932,7 +1036,6 @@ void ivas_wb_tbe_dec_fx( /* Update SHB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - /* Adjust the subframe and frame gain of the synthesized shb signal */ /* Scale the shaped excitation */ ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, @@ -941,9 +1044,21 @@ void ivas_wb_tbe_dec_fx( max = 0; move16(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + max = s_max( max, shaped_wb_excitation[i] ); /*Q0*/ + } + } + ELSE +#endif { - max = s_max( max, abs_s( shaped_wb_excitation[i] ) ); + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + max = s_max( max, abs_s( shaped_wb_excitation[i] ) ); + } } IF( max == 0 ) @@ -985,8 +1100,12 @@ void ivas_wb_tbe_dec_fx( } test(); +#ifdef HARMONIZE_TBE + IF( !st_fx->bfi && st_fx->prev_bfi ) +#else test(); IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) +#endif { IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) { @@ -1063,13 +1182,17 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); + } } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); + } } IF( EQ_32( st_fx->output_Fs, 32000 ) ) @@ -1178,10 +1301,21 @@ void ivas_wb_tbe_dec_fx( } ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - Copy_Scale_sig_16_32_no_sat( synth, tmp_synL, L_FRAME48k, sub( Q11, Qx ) ); - interpolate_3_over_1_allpass_fx32( tmp_synL, L_FRAME16k, upsampled_synth_32fx, hBWE_TD->mem_resamp_HB_fx_32 ); - Copy_Scale_sig_32_16( hBWE_TD->mem_resamp_HB_fx_32, hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, Q11 ) ); - Copy_Scale_sig_32_16( upsampled_synth_32fx, synth, L_FRAME48k, sub( Qx, Q11 ) ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); + interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); + Copy( upsampled_synth, synth, L_FRAME48k ); + } + ELSE +#endif + { + Copy_Scale_sig_16_32_no_sat( synth, tmp_synL, L_FRAME48k, sub( Q11, Qx ) ); + interpolate_3_over_1_allpass_fx32( tmp_synL, L_FRAME16k, upsampled_synth_32fx, hBWE_TD->mem_resamp_HB_fx_32 ); + Copy_Scale_sig_32_16( hBWE_TD->mem_resamp_HB_fx_32, hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, Q11 ) ); + Copy_Scale_sig_32_16( upsampled_synth_32fx, synth, L_FRAME48k, sub( Qx, Q11 ) ); + } } } ELSE @@ -1238,7 +1372,7 @@ void ivas_wb_tbe_dec_fx( return; } - +#ifndef HARMONIZE_TBE void wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -1877,7 +2011,7 @@ void wb_tbe_dec_fx( return; } - +#endif /*======================================================================================*/ /* FUNCTION : void swb_tbe_dec_fx () */ @@ -1896,13 +2030,14 @@ void wb_tbe_dec_fx( /* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ /*--------------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State *st_fx: : Decoder state structure */ +/* _ Decoder_State *st_fx: : Decoder state structure */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*======================================================================================*/ + void swb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -2210,10 +2345,14 @@ void swb_tbe_dec_fx( } ELSE { - /* de-quantization */ +#ifdef HARMONIZE_TBE + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, + &shb_ener_sf_32, shb_res_gshape, &mixFactors, &j /*temp*/ ); +#else dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, &shb_ener_sf_32, shb_res_gshape, &mixFactors ); +#endif Q_shb = 0; move16(); /* o: shb_ener_sf_32 in (2*Q_shb) */ @@ -3867,6 +4006,7 @@ static Word16 dotp_loc( Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ FOR( i = 1; i < n; i++ ) @@ -3878,7 +4018,18 @@ static Word16 dotp_loc( return extract_h( suma ); /*Qx + Qy - 16*/ } + +/*-------------------------------------------------------------------* + * dequantizeSHBparams() + * + * Dequantize super highband spectral envolope, temporal gains and frame gain + *-------------------------------------------------------------------*/ + +#ifdef HARMONIZE_TBE +static void dequantizeSHBparams_fx( +#else void ivas_dequantizeSHBparams_fx_9_1( +#endif Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ Word32 extl_brate, /* i : extensiuon layer bitrate */ @@ -4310,7 +4461,7 @@ void ivas_dequantizeSHBparams_fx_9_1( return; } - +#ifndef HARMONIZE_TBE /*==========================================================================*/ /* FUNCTION : static void dequantizeSHBparams_fx_9_1 () */ /*--------------------------------------------------------------------------*/ @@ -4629,13 +4780,16 @@ static void dequantizeSHBparams_fx_9_1( return; } +#endif /*-------------------------------------------------------------------* * fb_tbe_dec() * * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ + void fb_tbe_dec_fx( +#ifndef HARMONIZE_TBE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, @@ -4690,9 +4844,13 @@ void fb_tbe_dec_fx( } void fb_tbe_dec_ivas_fx( +#endif Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, +#ifdef HARMONIZE_TBE + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ +#endif Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ @@ -4754,17 +4912,31 @@ void fb_tbe_dec_ivas_fx( { Copy_Scale_sig( fb_synth, fb_synth_ref, L_FRAME48k, sub( Q_fb_synth_ref, add( hb_synth_exp, 16 ) ) ); // scaling is required } + /* add the fb_synth component to the hb_synth component */ - /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ - FOR( i = 0; i < L_FRAME48k; i++ ) +#ifdef HARMONIZE_TBE + IF( st->element_mode == EVS_MONO ) { - // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp - move16(); + FOR( i = 0; i < L_FRAME48k; i++ ) + { + hb_synth16[i] = add_sat( hb_synth16[i], fb_synth[i] ); + move16(); + } } + ELSE +#endif + { + FOR( i = 0; i < L_FRAME48k; i++ ) + { + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp + move16(); + } + } + return; } + void tbe_read_bitstream_fx( Decoder_State *st_fx ) { @@ -5381,6 +5553,7 @@ static void calc_tilt_bwe_fx_loc( return; } +#ifndef HARMONIZE_TBE /*-------------------------------------------------------------------* * swb_tbe_dec() * @@ -5427,6 +5600,7 @@ static void rescale_genSHB_mem_dec_ivas( return; } +#endif static void find_max_mem_dec_m3( Decoder_State *st, @@ -5797,8 +5971,13 @@ void ivas_swb_tbe_dec_fx( ELSE { /* de-quantization */ +#ifdef HARMONIZE_TBE + dequantizeSHBparams_fx( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, + &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); +#else ivas_dequantizeSHBparams_fx_9_1( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); +#endif if ( hStereoICBWE != NULL ) { hStereoICBWE->MSFlag = MSFlag; @@ -6192,7 +6371,11 @@ void ivas_swb_tbe_dec_fx( sc = sub( Q_bwe_exc, st->prev_Q_bwe_exc ); IF( sc != 0 ) { +#ifdef HARMONIZE_TBE + rescale_genSHB_mem_dec( st, sc ); +#else rescale_genSHB_mem_dec_ivas( st, sc ); +#endif } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 5f696e8997b8eed9faa4766a5c6f106be59f2c74..45e58c5e8b622451cb208e309a3087eb75cdc9be 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -79,9 +79,6 @@ ivas_error evs_enc_fx( #endif ivas_error error; SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - // NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; - // VAD_HANDLE hVAD = st->hVAD; - // DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; LPD_state_HANDLE hLPDmem = st->hLPDmem; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; @@ -95,7 +92,6 @@ ivas_error evs_enc_fx( Q_shb_spch = 0; move16(); /* to avoid compiler warnings */ - /*------------------------------------------------------------------* * Initializiation *-----------------------------------------------------------------*/ @@ -176,19 +172,19 @@ ivas_error evs_enc_fx( /*---------------------------------------------------------------------* * Pre-processing *---------------------------------------------------------------------*/ + #ifdef FIX_I4_OL_PITCH - pre_proc( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &hq_core_type ); + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, + &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #else pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #endif - // st->sharpFlag = sharpFlag; IF( EQ_16( st->mdct_sw, MODE2 ) ) { - Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ st->bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ @@ -271,6 +267,7 @@ ivas_error evs_enc_fx( acelp_core_enc_fx( st, inp, ener, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, Q_new, shift ); } + /*---------------------------------------------------------------------* * HQ core encoding *---------------------------------------------------------------------*/ @@ -283,6 +280,7 @@ ivas_error evs_enc_fx( /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ + core_switching_post_enc_fx( st, old_inp_12k8, old_inp_16k, A, shift, Q_new, st->Q_syn2, &Q_synth ); #ifndef FIX_I4_OL_PITCH IF( EQ_16( st->core, HQ_CORE ) ) @@ -427,8 +425,11 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ +#ifdef HARMONIZE_TBE + wb_tbe_enc_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); +#else wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); - +#endif IF( EQ_16( st->codec_mode, MODE2 ) ) { tbe_write_bitstream_fx( st ); @@ -444,6 +445,7 @@ ivas_error evs_enc_fx( * SWB(FB) TBE encoding * SWB BWE encoding *---------------------------------------------------------------------*/ + test(); IF( !st->Opt_SC_VBR && GE_32( st->input_Fs, 32000 ) ) { @@ -473,7 +475,11 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ +#ifdef HARMONIZE_TBE + fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc, 0 ); +#else fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc ); +#endif } IF( EQ_16( st->codec_mode, MODE2 ) ) @@ -646,9 +652,11 @@ static void initFrameHeader_loc( Encoder_State *st ) * * Write MODE2 frame header *-------------------------------------------------------------------*/ -static void writeFrameHeader_loc( Encoder_State *st ) -{ +static void writeFrameHeader_loc( + Encoder_State *st /* i/o: encoder state structure */ +) +{ BSTR_ENC_HANDLE hBstr = st->hBstr; IF( NE_32( st->core_brate, FRAME_NO_DATA ) ) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 4a55101d51ac37ddcb9bacda903d6306a75266bf..b30b95806d16aa905b59b4d26b8aeafe91ba10da 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -842,8 +842,9 @@ ivas_error init_encoder_fx( { return error; } - +#ifndef HARMONIZE_TBE InitSWBencBuffer_fx( st->hBWE_TD ); +#endif } ELSE { @@ -851,9 +852,13 @@ ivas_error init_encoder_fx( { return error; } - +#ifndef HARMONIZE_TBE InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 14230d021674e65e1fa61dd5b6a8e52deb6601bc..2880c054a181ce3141b4ab48ef06ea9c36f7394b 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -666,7 +666,11 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ +#ifdef HARMONIZE_TBE + wb_tbe_enc_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); +#else wb_tbe_enc_ivas_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); +#endif } ELSE IF( EQ_16( st->extl, WB_BWE ) && n == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -755,7 +759,7 @@ ivas_error ivas_core_enc_fx( Copy_Scale_sig_16_32_no_sat( shb_speech_fx, shb_speech_fx32, L_FRAME16k, shift ); // Q_shb_spch Q_shb_spch = add( Q_shb_spch, shift ); #endif - IF( st->hBWE_FD ) // VE: to be moved to the end of swb_pre_proc_ivas_fx() + IF( st->hBWE_FD ) { shift = getScaleFactor16( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k ); st->Q_old_wtda = add( st->Q_old_wtda, shift ); @@ -786,7 +790,11 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ +#ifdef HARMONIZE_TBE + fb_tbe_enc_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); +#else fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); +#endif } } } diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index a87edb39f9434a1adbfb19d5f4288b52331546f9..a4a3080a7aaa36ca452b57667da919a5493033ee 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -434,7 +434,11 @@ ivas_error stereo_memory_enc_fx( } } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); +#else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index 92bd08afd262b7401089eb7b7d0bfd290287e6e2..4e3b5fdd1528b01b8ad3d7f45e1963da9559f6b1 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -325,7 +325,11 @@ ivas_error stereo_set_tdm_fx( return error; } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); +#else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 30aa1498bb144407acfe4bd83a371e21aa19831f..49c438515789aae8dc382a315f2a91474c67ab8c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -159,17 +159,19 @@ Word16 dtx_hangover_addition_fx( Word16 *rem_dtx_ho ); void fb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc ); + const Word16 Q_fb_exc ); void fb_tbe_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ - const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ - Word16 Q_fb_exc, - Word16 Q_new_input ); +#endif + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ + const Word16 Q_fb_exc, + const Word16 Q_new_input ); void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], @@ -698,6 +700,7 @@ void wb_pre_proc_ivas_fx( ); void wb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ @@ -709,6 +712,7 @@ void wb_tbe_enc_fx( ); void wb_tbe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ @@ -3967,13 +3971,17 @@ void noise_est_init_ivas_fx( ); void InitSWBencBuffer_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); +#ifndef HARMONIZE_TBE void InitSWBencBuffer_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); - +#endif void ResetSHBbuffer_Enc_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index c0af2d1e59f157c09c93edd25bcb643db1124152..d6fe953257eac236750b68945cad5c705ddada2e 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -8,7 +8,6 @@ #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#include "stl.h" #include "ivas_prot_fx.h" @@ -19,6 +18,7 @@ #define ENVSHBRES_ACORR_MIN 40 /* minimum lag for calculating autocorrelation function on SHB residual TD envelope */ #define ENVSHBRES_ACORR_MAX 80 /* maximum lag for calculating autocorrelation function on SHB residual TD envelope */ + /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ @@ -30,34 +30,43 @@ static void singlevectortest_gain_fx( const Word32 *inp, const Word16 dimen, con static void determine_gain_weights_fx( const Word32 *gain, Word16 *weights, const Word16 dims ); static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, Word16 *subgains, const Word16 extl ); - +#ifndef HARMONIZE_TBE static void QuantizeSHBsubgains_ivas_fx( Encoder_State *st_fx, Word16 subgains[], const Word16 extl ); +#endif +#ifdef HARMONIZE_TBE +static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); +#else static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind ); static void QuantizeSHBframegain_ivas_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); +#endif static Word16 closest_centroid_fx( const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length ); static Word16 closest_centroid_lc_fx( const Word16 *data, const Word16 *quantizer, const Word16 centroids ); +#ifdef HARMONIZE_TBE +static void EstimateSHBFrameGain_fx( const Word16 element_mode, const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); +#else static void EstimateSHBFrameGain_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); static void EstimateSHBFrameGain_ivas_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); +#endif static void EstimateSHBGainShape_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, const Word16 *subwin, Word16 *n_subfr_saturation, const Flag limit_min_gain ); -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ); +static Word32 pow_off_pk_fx( const Word16 a[], const Word16 len, const Word16 step ); -static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ); +static Word32 pow_off_pk_corrected_fx( const Word16 a[], const Word16 len, const Word16 step ); static void find_max_mem_enc( Encoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2 ); -static void rescale_genSHB_mem_enc( Encoder_State *st_fx, Word16 sf ); +static void rescale_genSHB_mem_enc( Encoder_State *st_fx, const Word16 sf ); static void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ); -static void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ); +static void rescale_genWB_mem_enc( Encoder_State *st_fx, const Word16 sf ); static void Quant_lower_LSF_fx( const Word16 lsf[], Word16 lsf_q[], Word16 lsf_idx[] ); @@ -65,6 +74,15 @@ static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], W static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], const Word16 m ); +#ifdef HARMONIZE_TBE +static void Quant_BWE_LSF_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); + +static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, const Word16 Q_ener ); + +static void Quant_shb_res_gshape_fx( Encoder_State *st, Word16 shb_res_gshape_fx[] ); + +static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); +#else static void Quant_BWE_LSF_fx( Encoder_State *st_fx, const Word16 lsp_shb[], Word16 Q_lsfs[] ); static void Quant_BWE_LSF_ivas_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); @@ -80,6 +98,7 @@ static void Quant_shb_res_gshape_ivas_fx( Encoder_State *st, Word16 shb_res_gsha static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, const Word16 *lsp_shb_fx, Word16 *MA_lsp_shb_spacing, Word16 *frGainAttenuate, Word16 *frGainSmoothEn ); static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); +#endif /*-------------------------------------------------------------------* @@ -204,9 +223,9 @@ void find_max_mem_enc( * Rescale genSHB memories *-------------------------------------------------------------------*/ -void rescale_genSHB_mem_enc( +static void rescale_genSHB_mem_enc( Encoder_State *st_fx, - Word16 sf ) + const Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -246,9 +265,14 @@ void rescale_genSHB_mem_enc( move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); + + return; } -void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ) + +static void find_max_mem_wb_enc( + Encoder_State *st_fx, + Word16 *n_mem ) { Word16 i; Word16 n_mem_32; @@ -323,9 +347,14 @@ void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ) move16(); *n_mem = s_max( *n_mem, 0 ); move16(); + + return; } -void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) + +static void rescale_genWB_mem_enc( + Encoder_State *st_fx, + const Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -371,6 +400,8 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) hBWE_TD->mem_csfilt_fx[i] = L_shl( hBWE_TD->mem_csfilt_fx[i], sf ); move32(); } + + return; } @@ -381,8 +412,12 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) *-------------------------------------------------------------------*/ void InitSWBencBuffer_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) +#ifndef HARMONIZE_TBE { Word16 i; @@ -480,6 +515,7 @@ void InitSWBencBuffer_fx( void InitSWBencBuffer_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) +#endif { Word16 i; @@ -561,10 +597,23 @@ void InitSWBencBuffer_ivas_fx( hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - hBWE_TD->prev_Q_bwe_exc = 15; - move16(); - hBWE_TD->prev_Q_bwe_syn = 15; - move16(); +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) + { + hBWE_TD->prev_Q_bwe_exc = 31; + move16(); + hBWE_TD->prev_Q_bwe_syn = 31; + move16(); + } + ELSE +#endif + { + hBWE_TD->prev_Q_bwe_exc = 15; + move16(); + hBWE_TD->prev_Q_bwe_syn = 15; + move16(); + } + set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); @@ -644,6 +693,7 @@ void ResetSHBbuffer_Enc_fx( #define WBTBE_LPCWIN_LENGTH ( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16 - 1 void wb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz at Q-1 */ @@ -1122,8 +1172,13 @@ void wb_tbe_enc_fx( p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#else EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#endif /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1196,7 +1251,11 @@ void wb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind ); +#endif /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ @@ -1235,6 +1294,7 @@ void wb_tbe_enc_fx( /*==========================================================================*/ void wb_tbe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ @@ -1264,10 +1324,7 @@ void wb_tbe_enc_ivas_fx( Word32 LepsP[LPC_SHB_ORDER_WB + 1]; Word32 prev_pow, curr_pow, Lscale; - /* Word16 scale; */ - /*Word16 ramp_flag;*/ Word32 p2m_in, p2m_out; - /*Word16 cnt, max =0;*/ Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out, Q_cur_pow, Q_prev_pow; /* Q_hb_frame; */ Word32 L_tmp, Lmax; Word16 tmp, exp, Q_out, sc; @@ -1287,7 +1344,6 @@ void wb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; move16(); - /*Word16 att = 32767;*/ set16_fx( bwe_exc_extended_16, 0, L_FRAME32k + NL_BUFF_OFFSET ); hb_new_speech = hb_old_speech + WBTBE_LOOK_LSUFBR_5_OVER_16; hb_frame = hb_old_speech + WBTBE_LSUBFR_5_OVER_16 + WBTBE_ANA_ALIGNDELAY; @@ -1312,34 +1368,73 @@ void wb_tbe_enc_ivas_fx( k = 0; move16(); - FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); - move16(); - i--; - k++; + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + } + } + ELSE +#endif + { + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + k++; + } } } - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); + } + ELSE +#endif + { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); - /* Ensure R[0] isn't zero when entering Levinson-Durbin */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); + /* Ensure R[0] isn't zero when entering Levinson-Durbin */ + R_l[0] = s_max( R_l[0], 1 ); + move16(); + } E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); // Since 0th index will be 1 in floating point buffer, in fixed point one has to take norm of 0th index to identify the Q-factor Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); // Q12 - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 - move32(); - } + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); + move32(); + } - lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } + ELSE +#endif + { + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 + move32(); + } + lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { @@ -1347,20 +1442,11 @@ void wb_tbe_enc_ivas_fx( move16(); } - /* lsp_spacing_fx = 16384; move16(); */ lsp_spacing_fx = lsp_wb_temp_fx[0]; move16(); FOR( i = 1; i < LPC_SHB_ORDER_WB; i++ ) { - /*if ( i == 0 ) - { - tmp = lsp_wb_temp_fx[0]; move16(); - } - else - {*/ tmp = sub( lsp_wb_temp_fx[i], lsp_wb_temp_fx[i - 1] ); - /*} */ - lsp_spacing_fx = s_min( lsp_spacing_fx, tmp ); } @@ -1465,7 +1551,17 @@ void wb_tbe_enc_ivas_fx( /* Quantization of LSFs */ i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ - push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); +#ifdef HARMONIZE_TBE + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + hBWE_TD->lsf_WB = i; + move16(); + } + ELSE +#endif + { + push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); + } Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); @@ -1543,43 +1639,63 @@ void wb_tbe_enc_ivas_fx( prev_pow = 0; move32(); - Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - /* Compare with the guard bits needed in the subsequent operations. - * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. - */ - IF( LT_16( Q_prev_pow, 3 ) ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); - move16(); + prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ } - Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); - move16(); + + Q_prev_pow = 0; + move32(); } ELSE +#endif { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_prev_pow, 3 ) ) + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); + move16(); + } + Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); + move16(); + } + ELSE { - shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; + move16(); + } + Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); move16(); } - Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); - move16(); - } - IF( st_fx->element_mode > EVS_MONO ) - { tmp = sub( Q_prev_pow, 31 + 16 ); prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ + + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ + } } rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } +#endif + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( i = 0; i < L_FRAME32k; i++ ) { @@ -1587,69 +1703,117 @@ void wb_tbe_enc_ivas_fx( move16(); } +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } +#endif Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, - vf_modified_fx, uv_flag, st_fx->igf ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); + } + ELSE +#endif + { + GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); + } curr_pow = 0; move32(); - Q_cur_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); - /* Compare with the guard bits needed in the subsequent operations. - * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. - */ - IF( LT_16( Q_cur_pow, 3 ) ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i + L_SHB_LAHEAD / 4], 3 ); + curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + } + + IF( GT_16( voice_factors[0], 24576 ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ + } + + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + + FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + { + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } - Q_cur_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); + + Lscale = root_a_fx( Lscale, 31 - exp, &exp ); + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } ELSE +#endif { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + Q_cur_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_cur_pow, 3 ) ) { - shaped_wb_exc_scale[i] = shaped_wb_excitation[i + L_SHB_LAHEAD / 4]; + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i + L_SHB_LAHEAD / 4], 3 ); + move16(); + } + Q_cur_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); move16(); } - Q_cur_pow = shl_r( Q_bwe_exc_ext, 1 ); - move16(); - } - IF( st_fx->element_mode > EVS_MONO ) - { + ELSE + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shaped_wb_excitation[i + L_SHB_LAHEAD / 4]; + move16(); + } + Q_cur_pow = shl_r( Q_bwe_exc_ext, 1 ); + move16(); + } + tmp = sub( Q_cur_pow, 31 + 16 ); curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(Q_cur_pow)*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_cur_pow) */ - } - IF( GT_16( voice_factors[0], 24576 ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ - } + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_cur_pow) */ + } + + IF( GT_16( voice_factors[0], 24576 ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ + } - Lscale = root_a_over_b_fx( curr_pow, Q_cur_pow, prev_pow, Q_prev_pow, &exp ); + Lscale = root_a_over_b_fx( curr_pow, Q_cur_pow, prev_pow, Q_prev_pow, &exp ); - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) - { - L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + { + L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + move16(); + } + + Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); + L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } - Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); - L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - move16(); - /* Update WB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); @@ -1675,6 +1839,7 @@ void wb_tbe_enc_ivas_fx( temp_wb_fac_fx = 0; move16(); } + L_feedback = L_mult0( temp_wb_fac_fx, temp_wb_fac_fx ); FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -1753,7 +1918,11 @@ void wb_tbe_enc_ivas_fx( push_indice( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); /* Quantization of the subframe gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl ); +#else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape, st_fx->extl ); +#endif } /* Compute the power of gains away from the peak gain after quantization */ @@ -1767,9 +1936,13 @@ void wb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#else EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); - +#endif /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1777,7 +1950,16 @@ void wb_tbe_enc_ivas_fx( IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) { L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); - GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } } pitBufAvg_fx = 0; @@ -1806,11 +1988,29 @@ void wb_tbe_enc_ivas_fx( } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ + } IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) { - GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ + } } /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ @@ -1826,33 +2026,70 @@ void wb_tbe_enc_ivas_fx( IF( st_fx->igf != 0 && EQ_16( st_fx->coder_type, VOICED ) ) { /*GainFrame *= 0.5f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 16384 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 16384 ); + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 16384 ); + } } ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ { /*GainFrame *= 0.75f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 24576 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 24576 ); + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 24576 ); + } } /* Quantization of the frame gain parameter */ IF( st_fx->rf_mode ) { +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); +#endif } ELSE { +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); +#else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); +#endif } /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ - scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); - scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); - Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode > EVS_MONO ) +#endif + { + scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); + scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); + Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); + } + ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); - Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode > EVS_MONO ) +#endif + { + Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); + } hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); @@ -1860,6 +2097,12 @@ void wb_tbe_enc_ivas_fx( } +/*-------------------------------------------------------------------* + * fb_tbe_reset_enc() + * + * Reset the extra parameters needed for FB TBE encoding + *-------------------------------------------------------------------*/ + void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], Word32 *prev_fb_energy_fx, @@ -2098,7 +2341,11 @@ void swb_tbe_enc_fx( ELSE { /* LSF quantization (21 bits) */ +#ifdef HARMONIZE_TBE + Quant_BWE_LSF_fx( st_fx->hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); +#else Quant_BWE_LSF_fx( st_fx, lsf_shb_fx, lsf_shb_fx ); +#endif } /* space the lsfs to assert a minimum distance */ @@ -2634,8 +2881,13 @@ void swb_tbe_enc_fx( p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, + GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#else EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -2744,7 +2996,11 @@ void swb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind ); +#endif /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation */ @@ -2933,7 +3189,9 @@ void swb_tbe_enc_ivas_fx( move16(); TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; +#ifndef HARMONIZE_TBE RF_ENC_HANDLE hRF = st_fx->hRF; +#endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; /* init and buffers set up */ @@ -3104,7 +3362,11 @@ void swb_tbe_enc_ivas_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ +#ifdef HARMONIZE_TBE + gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); +#else gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); +#endif test(); test(); @@ -3138,7 +3400,11 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ +#ifdef HARMONIZE_TBE + Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#else Quant_BWE_LSF_ivas_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#endif } /* space the lsfs to assert a minimum distance */ @@ -3312,7 +3578,11 @@ void swb_tbe_enc_ivas_fx( } shb_ener_sf_Q31 = Mult_32_16( shb_ener_sf_Q31, 102 /*0.003125f Q15*/ ); shb_ener_sf_Q31 = L_add( 1l /*1 Q0*/, shb_ener_sf_Q31 ); +#ifdef HARMONIZE_TBE + Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); +#else Quant_shb_ener_sf_ivas_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); +#endif /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ set16_fx( shb_res_fx, 0, L_FRAME16k ); @@ -3359,7 +3629,11 @@ void swb_tbe_enc_ivas_fx( move16(); } +#ifdef HARMONIZE_TBE + Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); +#else Quant_shb_res_gshape_ivas_fx( st_fx, shb_res_gshape_fx ); +#endif } ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { @@ -4067,7 +4341,11 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the gain shape parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); +#else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); +#endif /* Compute the power of gains away from the peak gain after quantization */ IF( st_fx->element_mode > EVS_MONO ) @@ -4113,8 +4391,13 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, + GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#else EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -4359,6 +4642,9 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); +#else IF( st_fx->rf_mode ) { QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); @@ -4367,6 +4653,7 @@ void swb_tbe_enc_ivas_fx( { QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); } +#endif IF( hStereoICBWE != NULL ) { @@ -4462,7 +4749,11 @@ void swb_tbe_enc_ivas_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ + static void EstimateSHBFrameGain_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif const Word16 length, /* i : SHB overlap length */ const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ const Word16 Q_oriSHB, /* i : Q of arget original SHB frame */ @@ -4474,6 +4765,7 @@ static void EstimateSHBFrameGain_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) +#ifndef HARMONIZE_TBE { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -4658,6 +4950,7 @@ static void EstimateSHBFrameGain_ivas_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) +#endif { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -4697,34 +4990,70 @@ static void EstimateSHBFrameGain_ivas_fx( move16(); j = skip[0]; move16(); - FOR( k = 0; k < length / 2; k++ ) - { - sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ - mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] ); - move32(); /* Q(16+Q_synSHB) */ - } - FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) { - j = skip[i]; - move16(); - FOR( k = 0; k < length; k++ ) + FOR( k = 0; k < length / 2; k++ ) { - L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ - mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] ); + sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ + mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + mod_syn[j + k + length / 2] = L_mult( synSHB[j + k + length / 2], subgain[0] ); + move32(); /* Q(16+Q_synSHB) */ + } + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + j = skip[i]; + move16(); + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ + mod_syn[j + k] = L_shl( L_mult( sum_gain, synSHB[j + k] ), 1 ); + move32(); /* Q(16+Q_synSHB) */ + } + } + FOR( k = 0; k < length / 2; k++ ) + { + j = skip[i]; + move16(); + sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ + mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); move32(); /* Q(16+Q_synSHB) */ } } - FOR( k = 0; k < length / 2; k++ ) + ELSE +#endif { - j = skip[i]; - move16(); - sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ - mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ + FOR( k = 0; k < length / 2; k++ ) + { + sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] ); + move32(); /* Q(16+Q_synSHB) */ + } + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + j = skip[i]; + move16(); + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ + mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] ); + move32(); /* Q(16+Q_synSHB) */ + } + } + FOR( k = 0; k < length / 2; k++ ) + { + j = skip[i]; + move16(); + sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + } } } ELSE @@ -4734,45 +5063,93 @@ static void EstimateSHBFrameGain_ivas_fx( join_length = i_mult2( num_join, length ); j = 0; move16(); - FOR( k = 0; k < length; k++ ) - { - sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ - mod_syn[j] = L_mult0( synSHB[j], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) { - FOR( k = 0; k < join_length - length; k++ ) + FOR( k = 0; k < length; k++ ) { - mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); + sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ + mod_syn[j] = L_mult( synSHB[j], sum_gain ); move32(); /* Q(16+Q_synSHB) */ j++; } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); + tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + mod_syn[j] = L_shl( L_mult( tmp, synSHB[j] ), 1 ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); + move32(); /* Q(16+Q_synSHB)*/ + j++; + } FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); - tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ mod_syn[j] = L_mult( tmp, synSHB[j] ); - move32(); /* Q(16+Q_synSHB) */ + move32(); /* Q(16+Q_synSHB ) */ j++; } } - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); - move32(); /* Q(16+Q_synSHB)*/ - j++; - } - FOR( k = 0; k < length; k++ ) + ELSE +#endif { - tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ - mod_syn[j] = L_mult0( tmp, synSHB[j] ); - move32(); /* Q(16+Q_synSHB ) */ - j++; + FOR( k = 0; k < length; k++ ) + { + sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ + mod_syn[j] = L_mult0( synSHB[j], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); + tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + mod_syn[j] = L_mult( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); + move32(); /* Q(16+Q_synSHB)*/ + j++; + } + FOR( k = 0; k < length; k++ ) + { + tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ + mod_syn[j] = L_mult0( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB ) */ + j++; + } } } + /* adjust frame energy */ oriNrg = L_deposit_l( 0 ); synNrg = L_deposit_l( 0 ); @@ -4782,14 +5159,14 @@ static void EstimateSHBFrameGain_ivas_fx( sig = mult_r_sat( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_orisHB*/ sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_synSHB - 2*/ } FOR( ; i < l_frame; i++ ) { oriNrg = L_mac0_sat( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ sig = round_fx_sat( mod_syn[i] ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_oriSHB - 2*/ } tmp = add( l_frame, l_shb_lahead ); @@ -4798,7 +5175,7 @@ static void EstimateSHBFrameGain_ivas_fx( sig = mult_r_sat( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB */ sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_oriSHB - 2*/ } IF( EQ_32( oriNrg, MAX_32 ) ) { @@ -4821,7 +5198,17 @@ static void EstimateSHBFrameGain_ivas_fx( oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ } } - L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); + +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) + { + L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &exp_out ); + } + ELSE +#endif + { + L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); + } exp_out = sub( exp_out, scaling ); frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ *GainFrame = frame_gain; @@ -4831,7 +5218,10 @@ static void EstimateSHBFrameGain_ivas_fx( } -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) +static Word32 pow_off_pk_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) { Word16 i, j; Word32 sum, L_tmp; @@ -4857,7 +5247,10 @@ static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) } -static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ) +static Word32 pow_off_pk_corrected_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) { Word16 i, j; Word32 sum, L_tmp; @@ -5169,6 +5562,7 @@ static void EstimateSHBGainShape_fx( /* RETURN ARGUMENTS : */ /* _ Word16 : index Q0 */ /*--------------------------------------------------------------------------*/ + static Word16 closest_centroid_fx( const Word16 *data, /* i : input data Qx*/ const Word16 *weights, /* i : weights */ @@ -5214,6 +5608,7 @@ static Word16 closest_centroid_fx( /* PURPOSE : Determine a set of closest VQ centroids for a given input */ /* Gain shape is 4 dimensional */ /*--------------------------------------------------------------------------*/ + static Word16 closest_centroid_lc_fx( const Word16 *data, /* i : input data Qx*/ const Word16 *quantizer, /* i : quantizer table Qx*/ @@ -5393,7 +5788,7 @@ static void QuantizeSHBsubgains_fx( return; } - +#ifndef HARMONIZE_TBE /*============================================================*/ /* FUNCTION : static void QuantizeSHBsubgains_ivas_fx() */ /*------------------------------------------------------------*/ @@ -5530,7 +5925,7 @@ static void QuantizeSHBsubgains_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------* * Quant_shb_ener_sf_fx_fx() @@ -5539,6 +5934,7 @@ static void QuantizeSHBsubgains_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ Word16 Q_ener ) @@ -5595,9 +5991,10 @@ static void Quant_shb_ener_sf_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies Q_ener */ - Word16 Q_ener ) + const Word16 Q_ener ) { Word16 idxSubEner_fx; Word16 temp_shb_ener_sf_fx; @@ -5605,6 +6002,9 @@ static void Quant_shb_ener_sf_ivas_fx( Word32 L_tmp1, L_tmp; Word32 sum; Word16 tmp; +#ifdef HARMONIZE_TBE + Word16 Q_fac; +#endif TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ @@ -5613,21 +6013,48 @@ static void Quant_shb_ener_sf_ivas_fx( exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); - exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ + exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ - tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ + tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */ - temp_shb_ener_sf_fx = 0; - move16(); - idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q11 */ + temp_shb_ener_sf_fx = 0; + move16(); + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q12 */ + + Q_fac = -Q10; + move16(); + } + ELSE +#endif + { + L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ + + tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ + + temp_shb_ener_sf_fx = 0; + move16(); + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q11 */ +#ifdef HARMONIZE_TBE + Q_fac = -Q9; + move16(); +#endif + } /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q11+Q13+1 = Q25 */ - L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12/Q11+Q13+1 = Q26/Q25 */ +#ifdef HARMONIZE_TBE + L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ +#else + L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ +#endif + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ move32(); @@ -5650,6 +6077,7 @@ static void Quant_shb_ener_sf_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -5677,7 +6105,6 @@ static void Quant_shb_res_gshape_fx( return; } - /*-------------------------------------------------------------------* * Quant_shb_res_gshape_ivas_fx() * @@ -5685,6 +6112,7 @@ static void Quant_shb_res_gshape_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -5737,6 +6165,7 @@ static void Quant_shb_res_gshape_ivas_fx( /*==========================================================================*/ static void QuantizeSHBframegain_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -5904,6 +6333,7 @@ return; /*==========================================================================*/ static void QuantizeSHBframegain_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -5932,11 +6362,25 @@ static void QuantizeSHBframegain_ivas_fx( singlevectortest_gain_fx( GainFrame, 1, 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, &Q_GainFrame, SHBCB_FrameGain16_fx ); - test(); - IF( GT_64( W_deposit32_l( Q_GainFrame ), W_shl( W_mult_32_16( *GainFrame, 17367 ), 15 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - idxFrameGain--; - Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + { + idxFrameGain--; + Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + } + } + ELSE +#endif + { + test(); + IF( GT_64( W_deposit32_l( Q_GainFrame ), W_shl( W_mult_32_16( *GainFrame, 17367 ), 15 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + { + idxFrameGain--; + Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + } } IF( EQ_16( st_fx->codec_mode, MODE2 ) ) @@ -6142,6 +6586,7 @@ return; /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------*/ + static void determine_gain_weights_fx( const Word32 *gain, /* i : Gain parameter Q18 */ Word16 *weights, /* o : gain weights Q12/Q6*/ @@ -6206,6 +6651,7 @@ static void determine_gain_weights_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------------------------*/ + static void singlevectortest_gain_fx( const Word32 *inp, /* i : input gain vector Q18*/ const Word16 dimen, /* i : dimension of the input vector */ @@ -6274,6 +6720,7 @@ static void singlevectortest_gain_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------------------------*/ + static void return_M_Least_fx_GainFrame( const Word32 *inp, /* i: input Q18*/ const Word32 *codebook, /* i: codebook Q18*/ @@ -6510,6 +6957,7 @@ static Word16 Find_LSF_grid_fx( * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ +#ifndef HARMONIZE_TBE static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, @@ -6632,13 +7080,20 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ -static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, - Word16 *shb_frame_fx /* Q_in */, - const Word16 *lpc_shb_fx /* Q12 */, - const Word16 *lsp_shb_fx /* Q15 */, - Word16 *MA_lsp_shb_spacing /* Q15 */, - Word16 *frGainAttenuate /* Q0 */, - Word16 *frGainSmoothEn /* Q0 */ ) +#endif + +#ifdef HARMONIZE_TBE +static void gainFrSmooth_En_fx( +#else +static void gainFrSmooth_En_ivas_fx( +#endif + Encoder_State *st_fx, + Word16 *shb_frame_fx /* Q_in */, + const Word16 *lpc_shb_fx /* Q12 */, + const Word16 *lsp_shb_fx /* Q15 */, + Word16 *MA_lsp_shb_spacing /* Q15 */, + Word16 *frGainAttenuate /* Q0 */, + Word16 *frGainSmoothEn /* Q0 */ ) { Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; @@ -6686,8 +7141,18 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, /* estimate the mean square error in lsps from current frame to past frames */ tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); - lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); - lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + lsp_slow_evol_rate = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); + lsp_fast_evol_rate = L_mac( lsp_fast_evol_rate, tempQ15_2, tempQ15_2 ); + } + ELSE +#endif + { + lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); + lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); + } /* update the slow and fast interpolation lsps for next frame */ tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 /* 0.7f in Q15 */ ); @@ -6746,12 +7211,25 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, } test(); - if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, INV_1000_Q31, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO && LT_32( lsp_slow_evol_rate, INV_1000_Q31 ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) { *frGainSmoothEn = 1; move16(); } + ELSE IF( st_fx->element_mode > EVS_MONO ) +#endif + { + test(); + if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, INV_1000_Q31, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) + { + *frGainSmoothEn = 1; + move16(); + } + } } + + return; } #define MAXINT32 MAX_32 @@ -7123,7 +7601,7 @@ static void LVQQuant_BWE_LSF_fx( * * Quantize super highband spectral envolope *-------------------------------------------------------------------*/ - +#ifndef HARMONIZE_TBE static void Quant_BWE_LSF_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -7187,9 +7665,14 @@ static void Quant_BWE_LSF_fx( return; } +#endif +#ifdef HARMONIZE_TBE +static void Quant_BWE_LSF_fx( +#else static void Quant_BWE_LSF_ivas_fx( +#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 codec_mode, /* i : codec mode */ @@ -7273,10 +7756,11 @@ static void Quant_BWE_LSF_ivas_fx( *-------------------------------------------------------------------*/ void fb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc ) + const Word16 Q_fb_exc ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -7305,10 +7789,7 @@ void fb_tbe_enc_fx( Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; IF( NE_16( st->last_extl, FB_TBE ) ) @@ -7397,11 +7878,12 @@ void fb_tbe_enc_fx( } void fb_tbe_enc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate Q_new_input */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ - Word16 Q_fb_exc, - Word16 Q_new_input ) + const Word16 Q_fb_exc, + const Word16 Q_new_input ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -7416,13 +7898,30 @@ void fb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; Word16 q_diff, q_input_fhb; Word64 temp1, temp2; +#ifdef HARMONIZE_TBE + Word16 offset; + + offset = 0; + move16(); + if ( st->element_mode > EVS_MONO ) + { + offset = NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); + } +#endif s_max_value = 0; move16(); +#ifdef HARMONIZE_TBE + FOR( i = 0; i < add( L_FRAME48k, offset ); i++ ) + { + s_max_value = s_max( s_max_value, abs_s( new_input[i - offset] ) ); + } +#else FOR( i = 0; i < L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); i++ ) { s_max_value = s_max( s_max_value, abs_s( new_input[i - NS2SA( 48000, DELAY_FIR_RESAMPL_NS )] ) ); } +#endif exp_temp = norm_s( s_max_value ); if ( s_max_value == 0 ) { @@ -7430,27 +7929,36 @@ void fb_tbe_enc_ivas_fx( move16(); } +#ifdef HARMONIZE_TBE + if ( st->element_mode == EVS_MONO ) + { + exp_temp = sub( exp_temp, 1 ); + } +#endif + +#ifdef HARMONIZE_TBE + Copy_Scale_sig( new_input - offset, input_fhb_new, add( L_FRAME48k, offset ), exp_temp ); +#else Copy_Scale_sig( new_input - NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_fhb_new, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), exp_temp ); +#endif exp_temp = add( exp_temp, Q_new_input ); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); } ELSE { - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#ifdef HARMONIZE_TBE + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + offset, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#else + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#endif } test(); IF( GT_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_SCE ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) { Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ) - L_FRAME48k / 2; @@ -7473,71 +7981,144 @@ void fb_tbe_enc_ivas_fx( set16_fx( tmp_vec, 0, L_FRAME16k ); } - q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); - Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q - Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); // exp_temp - IF( q_diff > 0 ) +#ifdef HARMONIZE_TBE + IF( st->element_mode == EVS_MONO ) { - scale_sig( input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ), negate( q_diff ) ); // hBWE_TD->old_input_fhb_fx_Q - q_input_fhb = hBWE_TD->old_input_fhb_fx_Q; + Word32 L_tmp, temp32, fb_exc_energy32; + Word16 tmp1; + + Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ) ); + hBWE_TD->old_input_fhb_fx_Q = exp_temp; + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); + Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k - Sample_Delay_HP ); + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); + temp32 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ + temp32 = L_add_sat( temp32, L_shl_sat( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); /* Q11 */ + hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q11*/ + hBWE_TD->prev_fb_energy_fx_Q = sub( add( exp_temp, exp_temp ), 6 ); + fb_exc_energy32 = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc+1 -7) */ + + /*ratio = (float) sqrt( temp32 / fb_exc_energy );*/ + L_tmp = L_max( 1, temp32 ); /*Q6*/ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( sub( 31, sub( add( exp_temp, exp_temp ), 8 ) ), exp ); /* in Q15 (L_tmp in Q6)*/ + + exp2 = norm_l( fb_exc_energy32 ); + tmp2 = extract_h( L_shl( fb_exc_energy32, exp2 ) ); + tmp1 = sub( add( Q_fb_exc, Q_fb_exc ), 8 ); /*1 - 9*/ + exp2 = sub( sub( 31, tmp1 ), exp2 ); /* in Q15 (L_tmp in Q6)*/ + + exp = sub( exp2, exp ); /* Denormalize and substract */ + IF( GT_16( tmp2, tmp ) ) + { + tmp2 = shr( tmp2, 1 ); + exp = add( exp, 1 ); + } + IF( 0 != tmp ) + { + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ + L_tmp = L_max( L_shr_sat( L_tmp, sub( 31, exp ) ), 0x1 ); /* Q0 */ + } + ELSE + { + L_tmp = 0; + } + + /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + idxGain = max( 0, min(15,idxGain) ); */ + ratio = 0; move16(); + IF( GE_32( L_tmp, 32768 ) ) + { + idxGain = 15; + move16(); + } + ELSE + { + ratio = extract_l( L_tmp ); + idxGain = sub( 14, norm_s( ratio ) ); + idxGain = s_max( 0, idxGain ); + } + + test(); + test(); + IF( GT_16( idxGain, 2 ) && LT_16( idxGain, 15 ) && GT_16( ratio, add( shl( 2, sub( idxGain, 1 ) ), shl( 2, sub( idxGain, 2 ) ) ) ) ) + { + idxGain = add( idxGain, 1 ); + } } ELSE +#endif { - scale_sig( input_fhb, Sample_Delay_HP, q_diff ); // exp_temp - q_input_fhb = exp_temp; + q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q + Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); // exp_temp + IF( q_diff > 0 ) + { + scale_sig( input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ), negate( q_diff ) ); // hBWE_TD->old_input_fhb_fx_Q + q_input_fhb = hBWE_TD->old_input_fhb_fx_Q; + move16(); + } + ELSE + { + scale_sig( input_fhb, Sample_Delay_HP, q_diff ); // exp_temp + q_input_fhb = exp_temp; + move16(); + } + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); + hBWE_TD->old_input_fhb_fx_Q = exp_temp; move16(); - } - Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); - hBWE_TD->old_input_fhb_fx_Q = exp_temp; - move16(); - temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ - temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb + temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ + temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb - temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb - exp = W_norm( temp1 ); - temp1 = W_shl( temp1, exp ); // 2*q_input_fhb+exp - hBWE_TD->prev_fb_energy_fx = W_extract_h( temp1 ); // 2*q_input_fhb+exp-32 - move32(); - hBWE_TD->prev_fb_energy_fx_Q = sub( add( shl( q_input_fhb, 1 ), exp ), 32 ); - move16(); + temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb + exp = W_norm( temp1 ); + temp1 = W_shl( temp1, exp ); // 2*q_input_fhb+exp + hBWE_TD->prev_fb_energy_fx = W_extract_h( temp1 ); // 2*q_input_fhb+exp-32 + move32(); + hBWE_TD->prev_fb_energy_fx_Q = sub( add( shl( q_input_fhb, 1 ), exp ), 32 ); + move16(); - fb_exc_energy = sum2_fx_no_sat( fb_exc, L_FRAME16k ); // 2*Q_fb_exc + fb_exc_energy = sum2_fx_no_sat( fb_exc, L_FRAME16k ); // 2*Q_fb_exc - /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - exp = sub( W_norm( temp2 ), 1 ); - tmp = extract_h( W_extract_h( W_shl( temp2, exp ) ) ); // 2*q_input_fhb+exp-48 - exp = sub( 63, add( shl( q_input_fhb, 1 ), exp ) ); // 15-(2*q_input_fhb+exp-48) + /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ + exp = sub( W_norm( temp2 ), 1 ); + tmp = extract_h( W_extract_h( W_shl( temp2, exp ) ) ); // 2*q_input_fhb+exp-48 + exp = sub( 63, add( shl( q_input_fhb, 1 ), exp ) ); // 15-(2*q_input_fhb+exp-48) - exp2 = W_norm( fb_exc_energy ); - tmp2 = extract_h( W_extract_h( W_shl( fb_exc_energy, exp2 ) ) ); // 2*Q_fb_exc+exp2-48 - exp2 = sub( 63, add( shl( Q_fb_exc, 1 ), exp2 ) ); // 15-(2*Q_fb_exc+exp2-48) + exp2 = W_norm( fb_exc_energy ); + tmp2 = extract_h( W_extract_h( W_shl( fb_exc_energy, exp2 ) ) ); // 2*Q_fb_exc+exp2-48 + exp2 = sub( 63, add( shl( Q_fb_exc, 1 ), exp2 ) ); // 15-(2*Q_fb_exc+exp2-48) - ratio = 0; - idxGain = 0; - move16(); - move16(); - test(); - IF( tmp != 0 && tmp2 != 0 ) - { - ratio = div_s( tmp, tmp2 ); // exp: exp-exp2 - exp = sub( exp, exp2 ); - /* ratio = (float) sqrt( temp2 / fb_exc_energy ); - idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + ratio = 0; + idxGain = 0; + move16(); + move16(); + test(); + IF( tmp != 0 && tmp2 != 0 ) + { + ratio = div_s( tmp, tmp2 ); // exp: exp-exp2 + exp = sub( exp, exp2 ); + /* ratio = (float) sqrt( temp2 / fb_exc_energy ); + idxGain = (short)( log2_f ((float)ratio) + 0.5f ); - => idxGain = (short)( log2_f (sqrt( temp2 / fb_exc_energy )) + 0.5f ) - = (short)(log2f(sqrt(temp2 / fb_exc_energy)) + log2f(sqrt(2))) - = (short)log2f(sqrt(2 * (temp2 / fb_exc_energy))) - increase the exp of division result by one, two accommodate the multiplication with 2 in sqrt - */ - exp = add( exp, 1 ); - ratio = Sqrt16( ratio, &exp ); - /* Since ratio always lie betwwen 16384 and 32767, subtract the Q of sqrt result from 14 to get the integral part of log value */ - idxGain = sub( exp, 1 ); // 14 - (15-exp) + => idxGain = (short)( log2_f (sqrt( temp2 / fb_exc_energy )) + 0.5f ) + = (short)(log2f(sqrt(temp2 / fb_exc_energy)) + log2f(sqrt(2))) + = (short)log2f(sqrt(2 * (temp2 / fb_exc_energy))) + increase the exp of division result by one, two accommodate the multiplication with 2 in sqrt + */ + exp = add( exp, 1 ); + ratio = Sqrt16( ratio, &exp ); + /* Since ratio always lie betwwen 16384 and 32767, subtract the Q of sqrt result from 14 to get the integral part of log value */ + idxGain = sub( exp, 1 ); // 14 - (15-exp) - /* idxGain = max( 0, min( 15, idxGain ) ); */ - idxGain = s_max( 0, s_min( 15, idxGain ) ); + /* idxGain = max( 0, min( 15, idxGain ) ); */ + idxGain = s_max( 0, s_min( 15, idxGain ) ); + } } /* ratio = (float)(1 << idxGain);*/ @@ -7550,8 +8131,17 @@ void fb_tbe_enc_ivas_fx( { push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); } + return; } + + +/*---------------------------------------------------------------------* + * tbe_write_bitstream() + * + * Write TBE bitstream. + *---------------------------------------------------------------------*/ + void tbe_write_bitstream_fx( Encoder_State *st_fx /* i/o: encoder state structure */ ) @@ -7578,7 +8168,6 @@ void tbe_write_bitstream_fx( ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) { /* LSF coefficients */ - test(); IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { @@ -7635,6 +8224,12 @@ void tbe_write_bitstream_fx( } +/*---------------------------------------------------------------------* + * TBEreset_enc() + * + * + *---------------------------------------------------------------------*/ + void TBEreset_enc_fx( TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 last_core, /* i : last core */