diff --git a/lib_com/int_lsp_fx.c b/lib_com/int_lsp_fx.c index 08ab6ba85458ce3160f9acf2d05af088bff5434e..81c57c60fa0bda3523a22af7472ac54221d8be0e 100644 --- a/lib_com/int_lsp_fx.c +++ b/lib_com/int_lsp_fx.c @@ -43,13 +43,13 @@ void int_lsp_fx( - const Word16 L_frame, /* i : length of the frame */ + const Word16 L_frame, /* i : length of the frame */ const Word16 lsp_old[], /* i : Q15 LSPs from past frame */ const Word16 lsp_new[], /* i : Q15 LSPs from present frame */ Word16 *Aq, /* o : Q12 LP coefficients in both subframes */ - const Word16 m, /* i : order of LP filter */ + const Word16 m, /* i : order of LP filter */ const Word16 *int_coeffs, /* i : Q15 interpolation coefficients */ - const Word16 Opt_AMR_WB /* i : Q0 flag indicating AMR-WB IO mode */ + const Word16 Opt_AMR_WB /* i : Q0 flag indicating AMR-WB IO mode */ ) { Word16 lsp[M], fnew, fold; @@ -132,6 +132,12 @@ void int_lsp4_fx( { pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; /*Q15*/ } +#ifdef HARM_LSF_ENC + ELSE IF( EQ_16( relax_prev_lsf_interp, -2 ) ) + { + pt_int_coeffs = interpol_frac2_mid_fx; /*Q15*/ + } +#endif ELSE { pt_int_coeffs = interpol_frac_mid_fx; /*Q15*/ @@ -177,6 +183,7 @@ void int_lsp4_fx( return; } +#ifndef HARM_LSF_ENC void int_lsp4_ivas_fx( const Word16 L_frame, /* i : length of the frame */ @@ -257,3 +264,4 @@ void int_lsp4_ivas_fx( return; } +#endif diff --git a/lib_com/options.h b/lib_com/options.h index 7c094c8fc83796ab6ddb78ef062b3a77ba8a4617..0ca24719e6e32cba663f6aa822a43318f2cbff1e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -119,6 +119,7 @@ #define CLEANUP_VBR_CAM_ENC /* VA: basop issue 2299: Remove unused core-encoder VBR and CAM code */ #define FIX_1494_SET_SPLITBFI_UNUSED /* Dolby: Fix issue 1494, remove unused function setting BFI flag in ISAR renderer */ #define FIX_1479_MSAN_SPAR_UNINITIALIZED_VALUE /* Dolby: Fix for issue 1479, MSAN error due to uninitialized value in SPAR */ +#define HARM_LSF_ENC /* VA: basop issue 2301: Remove duplicated code in LSF quantizer */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index abb050c02ec7f9a2b17f7a25d946293ce351f86d..47313dff95fe99a7370c58a0d7b290ce87850517 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1670,6 +1670,7 @@ void int_lsp4_fx( Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ ); +#ifndef HARM_LSF_ENC void int_lsp4_ivas_fx( const Word16 L_frame, /* i : length of the frame */ const Word16 lsp_old[], /* i : LSPs from past frame Q15*/ @@ -1679,7 +1680,7 @@ void int_lsp4_ivas_fx( const Word16 m, /* i : order of LP filter */ Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ ); - +#endif void de_interleave_spectrum_fx( Word32 *coefs, /* i/o: i and output coefficients Q? */ const Word16 length /* i : length of spectrum Q0 */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index ad87695e831dd5092ddb9456261828e46ca5ec72..f117f11e4b9c3be104dd35b05c22ef9e28796bfc 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -614,7 +614,11 @@ void stat_noise_uv_mod_ivas_fx( mult( sub( 32767, beta ), lspnew_s[i] ) ); } +#ifdef HARM_LSF_ENC + int_lsp4_fx( L_FRAME, oldlsp_mix, midlsp_mix, newlsp_mix, Aq, M, 0 ); +#else int_lsp4_ivas_fx( L_FRAME, oldlsp_mix, midlsp_mix, newlsp_mix, Aq, M, 0 ); +#endif Copy( lspnew_s, lspold_s, M ); } ELSE /* (unvoiced_vad != 0) */ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index e163662c8d2a4a4f9b14b3103e64850f3146151c..8015f5cda1dece7c84617e1b2478187b357eb22e 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1035,7 +1035,11 @@ ivas_error acelp_core_dec_fx( test(); IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) { +#ifdef HARM_LSF_ENC + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); +#else int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); +#endif } /*---------------------------------------------------------------* diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 9515aefe898464d21f318f419e654ab748d92957..6a610063c8987b8bb6aa16ed9bbd59b20d2a84bd 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -556,7 +556,11 @@ void decoder_LPD_fx( move16(); } +#ifdef HARM_LSF_ENC + int_lsp4_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); +#else int_lsp4_ivas_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); +#endif } ELSE { diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 3af2e35ed787b63cec3d72949833666bf8ed04e8..bfb92005a66485ebdfdc01283e4307015a834d66 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -236,10 +236,12 @@ void lsf_dec_fx( } lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); } + /*-------------------------------------------------------------------------------------* * Mid-frame LSF decoding * LSP interpolation and conversion of LSPs to A(z) *-------------------------------------------------------------------------------------*/ + IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ @@ -298,13 +300,22 @@ void lsf_dec_fx( } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ +#ifdef HARM_LSF_ENC + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); +#else int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); +#endif } ELSE { /* LSP interpolation and conversion of LSPs to A(z) */ +#ifdef HARM_LSF_ENC + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); +#else int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); +#endif } + /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index b612626cf8d9ed34c2a253ac14eede0580e822ff..5c38aae3b51b2fb3ecd5cc6b6e1b518a5c42cf9d 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -446,7 +446,11 @@ ivas_error acelp_core_enc_fx( if ( !tdm_lp_reuse_flag ) { +#ifdef HARM_LSF_ENC + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, NULL, Q_new ); +#else lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); +#endif } /*---------------------------------------------------------------* @@ -520,7 +524,11 @@ ivas_error acelp_core_enc_fx( config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, st_fx->idchan, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /* redo LSF quantization */ +#ifdef HARM_LSF_ENC + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, 0, -1, NULL, Q_new ); +#else lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); +#endif /* recalculation of LP residual (filtering through A[z] filter) */ calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); @@ -1004,11 +1012,19 @@ ivas_error acelp_core_enc_ivas_fx( IF( st->rate_switching_reset ) { /*extrapolation in case of unstable LSP*/ +#ifdef HARM_LSF_ENC + int_lsp4_fx( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); +#else int_lsp4_ivas_fx( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); +#endif } ELSE { +#ifdef HARM_LSF_ENC + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, A, M, 0 ); +#else int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, A, M, 0 ); +#endif } /* Reset LPC mem */ @@ -1245,7 +1261,11 @@ ivas_error acelp_core_enc_ivas_fx( #endif IF( !tdm_lp_reuse_flag ) { +#ifdef HARM_LSF_ENC + lsf_enc_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new ); +#else lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new ); +#endif } ELSE { @@ -1406,7 +1426,11 @@ ivas_error acelp_core_enc_ivas_fx( config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); /* redo LSF quantization */ +#ifdef HARM_LSF_ENC + lsf_enc_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new ); +#else lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new ); +#endif /* recalculation of LP residual (filtering through A[z] filter) */ calc_residu_fx( st, inp, res_fx, Aq ); diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index ee8b57c6be351442a4d1903798d32a92d469c305..e61f7f76bb166ad75dd68745fcce32a0029065dc 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -115,12 +115,20 @@ void analy_lp_fx( IF( EQ_16( sec_chan_low_rate, 1 ) ) { /* LSP interpolation */ +#ifdef HARM_LSF_ENC + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); +#else int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); +#endif } ELSE { /* LSP interpolation */ +#ifdef HARM_LSF_ENC + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); +#else int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); +#endif } Copy( lsp_new, lsp_old, M ); /* Q15 */ *ener = L_Comp( epsP_h[M], epsP_l[M] ); /* Q_r */ diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index cf4c06203a2a6ada90da0d9b7d20ca928f0da4ca..de211162b805250f8985064aed20edfe56622ca6 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -331,8 +331,13 @@ void CNG_enc_fx( } ELSE { +#ifdef HARM_LSF_ENC + lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 0, 0, NULL, Q_new ); +#else lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, Q_new ); +#endif } + /* Reset CNG history if CNG frame length is changed */ test(); test(); @@ -1499,7 +1504,11 @@ void CNG_enc_ivas_fx( } ELSE { +#ifdef HARM_LSF_ENC + lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 0, 0, NULL, Q_new ); +#else lsf_enc_ivas_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 0, 0, NULL, Q_new ); +#endif } /* Reset CNG history if CNG frame length is changed */ diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index 95e52bc694249b1e1adf0fd8769b0991fac17c52..18d79f26d4d86aa6bb7ab12399c0c651109f7b0d 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -420,8 +420,13 @@ void stereo_tcx_core_enc( move16(); } +#ifdef HARM_LSF_ENC + lpc_quantization_fx( st, lsp_new_fx, lsp_mid_fx, lsp_q_fx, lsf_q_fx, lspmid_q_fx, NULL, st->clip_var_fx, AUDIO, 0, /*No acelp->no need to compute any mid-LPC*/ + param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, Q_ener ); +#else lpc_quantization_ivas_fx( st, lsp_new_fx, lsp_mid_fx, lsp_q_fx, lsf_q_fx, lspmid_q_fx, AUDIO, 0, /*No acelp->no need to compute any mid-LPC*/ param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, Q_ener ); +#endif /*--------------------------------------------------------------* * Rate switching diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index d62b97f1db7151d0069de760c28b827077d2d2d5..4fc0777c78d0f0fced41a40c7a6e6c53d3834f5a 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -24,15 +24,23 @@ * Local function prototypes *---------------------------------------------------------------------*/ +#ifdef HARM_LSF_ENC +static void lsfq_CNG_fx( const Word16 element_mode, BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ); +#else static void lsfq_CNG_fx( BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ); +#endif static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word32 p_offset_scale1[][MAX_NO_SCALES + 1], Word32 p_offset_scale2[][MAX_NO_SCALES + 1], Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ); static Word32 vq_lvq_lsf_enc_ivas_fx( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word16 *resq, Word16 *lsfq ); +#ifdef HARM_LSF_ENC +static void lsf_mid_enc_fx( const Word16 element_mode, BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); +#else static void lsf_mid_enc_fx( BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); static void lsf_mid_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Word32 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); +#endif /*===========================================================================*/ @@ -62,15 +70,21 @@ static void lsf_mid_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Wo /* RETURN ARGUMENTS : */ /* _ None */ /*===========================================================================*/ + void lsf_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ Word16 *lsf_new, /* o : quantized LSF vector */ Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ Word16 *Aq, /* o : quantized A(z) for 4 subframes */ +#ifndef HARM_LSF_ENC const Word16 Nb_ACELP_frames, +#endif const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ +#ifdef HARM_LSF_ENC + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ +#endif const Word16 Q_new ) { Word16 nBits = 0; @@ -78,6 +92,10 @@ void lsf_enc_fx( Word16 int_fs; Word16 force_sf = 0; move16(); +#ifdef HARM_LSF_ENC + Word16 no_param_lpc; + Word16 param_lpc[NPRM_LPC_NEW]; +#endif Word16 fec_lsf[M], stab, i; Word32 L_tmp; Word16 coder_type, ppp_mode, nelp_mode; @@ -101,6 +119,9 @@ void lsf_enc_fx( move16(); } +#ifdef HARM_LSF_ENC + no_param_lpc = 0; +#endif move16(); IF( st_fx->Opt_SC_VBR ) @@ -122,11 +143,24 @@ void lsf_enc_fx( assert( st_fx->sr_core <= 32000 ); int_fs = extract_l( st_fx->sr_core ); move32(); + /* convert LSPs to LSFs */ lsp2lsf_fx( lsp_new, lsf_new, M, int_fs ); /* check resonance for pitch clipping algorithm */ +#ifdef HARM_LSF_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + gp_clip_test_lsf_fx( st_fx->element_mode, lsf_new, st_fx->clip_var_fx, 0 ); + } + ELSE + { + gp_clip_test_lsf_ivas_fx( st_fx->element_mode, st_fx->core_brate, lsf_new, st_fx->clip_var_fx, 0 ); + } +#else gp_clip_test_lsf_fx( st_fx->element_mode, lsf_new, st_fx->clip_var_fx, 0 ); +#endif + /* Find the number of bits for LSF quantization */ nBits = 0; @@ -161,12 +195,17 @@ void lsf_enc_fx( move16(); } } + force_sf = 0; move16(); - /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ test(); +#ifdef HARM_LSF_ENC + if ( LT_16( st_fx->Nb_ACELP_frames, 3 ) && NE_32( st_fx->core_brate, SID_2k40 ) ) +#else if ( LT_16( Nb_ACELP_frames, 3 ) && NE_32( st_fx->core_brate, SID_2k40 ) ) +#endif { + /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ force_sf = 1; move16(); } @@ -184,8 +223,13 @@ void lsf_enc_fx( * Frame end LSF quantization *-------------------------------------------------------------------------------------*/ +#ifdef HARM_LSF_ENC + lsf_end_enc_fx( st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, + force_sf, param_lpc, &no_param_lpc, NULL, st_fx->coder_type_raw, tdm_lsfQ_PCh ); +#else lsf_end_enc_fx( st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, force_sf, NULL, NULL, NULL, st_fx->coder_type_raw ); +#endif /* convert quantized LSFs back to LSPs */ lsf2lsp_fx( lsf_new, lsp_new, M, int_fs ); @@ -196,7 +240,23 @@ void lsf_enc_fx( /* don't use old LSF values if this is the first ACELP frame after HQ frames */ Copy( lsf_new, st_fx->lsf_old_fx, M ); } + /* set seed_acelp used in UC mode */ +#ifdef HARM_LSF_ENC + test(); + IF( EQ_16( coder_type, UNVOICED ) && ( st_fx->element_mode > EVS_MONO ) ) + { + st_fx->seed_acelp = 0; + move16(); + FOR( i = no_param_lpc - 1; i >= 0; i-- ) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st_fx->seed_acelp = add( i_mult( add( shr( st_fx->seed_acelp, 1 ), param_lpc[i] ), 31821 ), 13849 ); + move16(); + } + } +#endif + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* return if SID frame (conversion to A(z) done in the calling function) */ @@ -218,7 +278,18 @@ void lsf_enc_fx( FEC_lsf_estim_enc_fx( st_fx, fec_lsf ); /* in case of FEC in decoder - calculate LSF stability */ +#ifdef HARM_LSF_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + stab = lsf_stab_fx( lsf_new, fec_lsf, 0, st_fx->L_frame ); // Q15 + } + ELSE + { + stab = lsf_stab_ivas_fx( lsf_new, fec_lsf, 0, st_fx->L_frame ); // Q15 + } +#else stab = lsf_stab_fx( lsf_new, fec_lsf, 0, st_fx->L_frame ); // Q15 +#endif test(); test(); @@ -249,19 +320,24 @@ void lsf_enc_fx( Copy( st_fx->lsfoldbfi0_fx, st_fx->lsfoldbfi1_fx, M ); Copy( lsf_new, st_fx->lsfoldbfi0_fx, M ); - /*-------------------------------------------------------------------------------------* * Mid-frame LSF encoding * LSP interpolation and conversion of LSPs to A(z) *-------------------------------------------------------------------------------------*/ - if ( st_fx->rate_switching_reset ) + + IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ Copy( lsp_new, st_fx->lsp_old_fx, M ); // Q15 Copy( lsf_new, st_fx->lsf_old_fx, M ); // Q15 } + /* Mid-frame LSF encoding */ +#ifdef HARM_LSF_ENC + lsf_mid_enc_fx( st_fx->element_mode, st_fx->hBstr, st_fx->acelp_cfg.mid_lsf_bits, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); +#else lsf_mid_enc_fx( st_fx->hBstr, st_fx->acelp_cfg.mid_lsf_bits, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); +#endif test(); IF( EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) ) @@ -296,12 +372,24 @@ void lsf_enc_fx( IF( NE_32( st_fx->core_brate, SID_2k40 ) ) { +#ifdef HARM_LSF_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); + } + ELSE + { + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); // Q15 + } +#else st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); +#endif } return; } +#ifndef HARM_LSF_ENC void lsf_enc_ivas_fx( Encoder_State *st, /* i/o: state structure */ Word16 *lsf_new, /* o : quantized LSF vector Q(x2.56)*/ @@ -439,8 +527,8 @@ void lsf_enc_ivas_fx( /* don't use old LSF values if this is the first ACELP frame after HQ frames */ Copy( lsf_new, st->lsf_old_fx, M ); } - /* set seed_acelp used in UC mode */ + /* set seed_acelp used in UC mode */ test(); IF( EQ_16( coder_type, UNVOICED ) && ( st->element_mode > EVS_MONO ) ) { @@ -540,21 +628,34 @@ void lsf_enc_ivas_fx( } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ +#ifdef HARM_LSF_ENC + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); +#else int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); +#endif } ELSE { +#ifdef HARM_LSF_ENC + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); +#else int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); +#endif } + /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ + IF( NE_32( st->core_brate, SID_2k40 ) ) { st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st->lsf_old_fx, 0, st->L_frame ); // Q15 } + return; } +#endif + /*-------------------------------------------------------------------* * lsfq_CNG_fx() * @@ -567,7 +668,10 @@ void lsf_enc_ivas_fx( *-------------------------------------------------------------------*/ static void lsfq_CNG_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ +#ifdef HARM_LSF_ENC + const Word16 element_mode, /* i : element mode */ +#endif + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ const Word16 *lsf, /*x2.56 unquantized LSF vector */ const Word16 *wghts, /*Q10 LSF weights */ Word16 *qlsf, /*x2.56 quantized LSF vecotor */ @@ -610,7 +714,6 @@ static void lsfq_CNG_fx( move16(); } - min_dist = L_add( MAXINT32, 0 ); FOR( i = first_cb; i < last_cb; i++ ) { @@ -643,10 +746,27 @@ static void lsfq_CNG_fx( /* quantize the difference with LVQ */ /* MSVQ_ROM to be updated */ +#ifdef HARM_LSF_ENC + IF( element_mode == EVS_MONO ) + { + mslvq_cng_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts, p_no_scales ); + + index_lvq_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, + p_offset_scale1, p_offset_scale2, p_no_scales ); + } + ELSE + { + mslvq_cng_ivas_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts ); + + index_lvq_ivas_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG_IVAS + idx_cv, idx_lvq, 0 ); + } +#else mslvq_cng_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts, p_no_scales ); index_lvq_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, p_offset_scale1, p_offset_scale2, p_no_scales ); +#endif + Vr_add( qlsf, &CNG_SN1_fx[idx_cv * M], qlsf, M ); /* write the VQ index to the bitstream */ @@ -659,6 +779,7 @@ static void lsfq_CNG_fx( return; } +#ifndef HARM_LSF_ENC static void lsfq_CNG_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *lsf, /*x2.56 unquantized LSF vector */ @@ -748,13 +869,14 @@ static void lsfq_CNG_ivas_fx( return; } +#endif + /*-------------------------------------------------------------------* * qlsf_Mode_Select_fx() * * Mode selection for LSF quantizer *-------------------------------------------------------------------*/ - static Word16 qlsf_Mode_Select_fx( const Word16 *w, /* i : weighting vector Q8 */ const Word16 *pred1, /* i : prediction vector x2.56 */ @@ -847,6 +969,7 @@ static Word16 qlsf_Mode_Select_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*========================================================================*/ +#ifndef HARM_LSF_ENC void lsf_end_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) x2.56*/ @@ -1352,28 +1475,32 @@ void lsf_end_enc_fx( return; } +#endif - +#ifdef HARM_LSF_ENC +void lsf_end_enc_fx( +#else void lsf_end_enc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) x2.56*/ - Word16 *qlsf, /* o : quantized LSF x2.56*/ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) x2.56*/ + Word16 *qlsf, /* o : quantized LSF x2.56*/ const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ - const Word16 coder_type_org, /* i : coding type */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + const Word16 coder_type_org, /* i : coding type */ + const Word16 Q_ener, /* i : Q value for Bin_Ener */ + const Word16 force_sf, /* i : Force safety-net usage if coding type supports */ Word16 *lpc_param, Word16 *no_indices, Word16 *bits_param_lpc, - Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases)*/ - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases) */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ) { Word16 i; Word16 Idx0[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for safety-net quantizer */ Word16 Idx1[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for predictive quantizer */ Word16 indice[MAX_VQ_STAGES + 3]; /* Temp. array of indice for vector de-quantizer */ - Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ + Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; const Word16 *Bit_alloc1 = NULL; Word32 Err[2]; /* Quantization error for safety-net(0) and predictive(1) quantizers */ @@ -1403,15 +1530,25 @@ void lsf_end_enc_ivas_fx( Word16 pred3[M]; Word16 dummy, dummy_v[5]; +#ifdef HARM_LSF_ENC + flag_1bit_gran = 0; + move16(); + if ( GT_16( st->element_mode, EVS_MONO ) ) + { + flag_1bit_gran = 1; + move16(); + } +#else flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); +#endif nBits = nBits_in; move16(); + /* Update LSF coder_type for LSF quantizer for some special cases */ test(); test(); test(); - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) && ( st->idchan == 0 ) ) /* this bit is used only for primary channel or mono */ { IF( EQ_16( coder_type_raw, VOICED ) ) @@ -1443,14 +1580,25 @@ void lsf_end_enc_ivas_fx( IF( st->bwidth == NB ) { +#ifdef HARM_LSF_ENC + abs_threshold = L_add( SFNETLOWLIMIT_NB, 0 ); +#else abs_threshold = SFNETLOWLIMIT_NB / 2; +#endif move32(); } ELSE { abs_threshold = SFNETLOWLIMIT_WB / 2; move32(); +#ifdef HARM_LSF_ENC + if ( flag_1bit_gran == 0 ) + { + abs_threshold = L_add( SFNETLOWLIMIT_WB, 0 ); + } +#endif } + /* Calculate LSF weighting coefficients */ Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], Q_ener, lsf, wghts, (Word16) EQ_16( st->bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), st->sr_core, M ); @@ -1460,12 +1608,17 @@ void lsf_end_enc_ivas_fx( IF( EQ_32( st->core_brate, SID_2k40 ) ) { +#ifdef HARM_LSF_ENC + lsfq_CNG_fx( st->element_mode, hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); +#else lsfq_CNG_ivas_fx( hBstr, lsf, wghts, qlsf ); +#endif sort_fx( qlsf, 0, M - 1 ); reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); return; } + /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ find_pred_mode( &predmode, coder_type, st->bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); @@ -1510,7 +1663,18 @@ void lsf_end_enc_ivas_fx( Vr_subt( lsf, pred0, Tmp, M ); /* LVQ quantization (safety-net only) */ - Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); +#ifdef HARM_LSF_ENC + IF( flag_1bit_gran == 0 ) + { + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, + st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + } + ELSE +#endif + { + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); + } + safety_net = 1; move16(); st->pstreaklen = 0; @@ -1519,12 +1683,23 @@ void lsf_end_enc_ivas_fx( ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ { Vr_subt( lsf, pred1, Tmp1, M ); - Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq ); + +#ifdef HARM_LSF_ENC + IF( flag_1bit_gran == 0 ) + { + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); + } + ELSE +#endif + { + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq ); + } safety_net = 0; move16(); } - ELSE + ELSE /* Switched Safety-Net/AR prediction */ { IF( EQ_16( predmode, 2 ) ) { @@ -1590,15 +1765,35 @@ void lsf_end_enc_ivas_fx( /* all other frames (not VOICED@16kHz) */ ELSE { - /* safety-net */ + /* Switched Safety-Net/AR prediction */ +#ifdef HARM_LSF_ENC + IF( flag_1bit_gran == 0 ) + { + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + } + ELSE +#endif + { + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); + } - Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); /* Predictive quantizer is calculated only if it can be selected */ test(); IF( !force_sf || GT_32( Err[0], abs_threshold ) ) { - Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M] ); +#ifdef HARM_LSF_ENC + IF( flag_1bit_gran == 0 ) + { + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); + } + ELSE +#endif + { + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M] ); + } } + test(); test(); /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: @@ -1899,7 +2094,19 @@ void lsf_end_enc_ivas_fx( } ELSE { - vq_dec_lvq_ivas_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); +#ifdef HARM_LSF_ENC + IF( flag_1bit_gran == 0 ) + { + vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + } + ELSE +#endif + { + vq_dec_lvq_ivas_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); + } + Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } @@ -1917,7 +2124,19 @@ void lsf_end_enc_ivas_fx( ELSE { /* LVQ */ - vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); +#ifdef HARM_LSF_ENC + IF( flag_1bit_gran == 0 ) + { + vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], + &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + } + ELSE +#endif + { + vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + } + IF( EQ_16( predmode, 1 ) ) { Copy( qlsf, st->mem_MA_fx, M ); @@ -2476,14 +2695,13 @@ static Word32 vq_lvq_lsf_enc_ivas_fx( IF( pred_flag == 0 ) /* safety net*/ { cb = &Quantizers_fx[CB_lsf[mode]]; + move16(); IF( LT_16( mode, 6 ) ) { - move16(); mode_glb = add( offset_lvq_modes_SN[mode], offset_in_lvq_mode_SN[mode][( levels[stagesVQ] - min_lat_bits_SN[mode] )] ); } ELSE { - move16(); mode_glb = add( offset_lvq_modes_SN[mode], levels[stagesVQ] - min_lat_bits_SN[mode] ); } } @@ -3460,8 +3678,11 @@ static void FFT_Mid_Interpol_16k_fx( static void lsf_mid_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 nb_bits, /* i : number of bits */ +#ifdef HARM_LSF_ENC + const Word16 element_mode, /* i : element mode */ +#endif + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 nb_bits, /* i : number of bits */ const Word16 int_fs, /* i : internal (ACELP) sampling frequency*/ const Word16 qlsp0[], /* i : quantized LSPs from frame beginning*/ const Word16 qlsp1[], /* i : quantized LSPs from frame end */ @@ -3487,12 +3708,30 @@ static void lsf_mid_enc_fx( lsp2lsf_fx( qlsp0, qlsf0, M, int_fs ); lsp2lsf_fx( qlsp1, qlsf1, M, int_fs ); +#ifdef HARM_LSF_ENC + IF( element_mode == EVS_MONO ) + { + /* calculate weights */ + FFT_Mid_Interpol_16k_fx( Bin_Ener_old, &Bin_Ener[L_FFT / 2], Bin_Ener_mid ); + + /* LSF weighting */ + Unified_weighting_fx( Bin_Ener_mid, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); + move16(); + } + ELSE + { + Unified_weighting_fx( Bin_Ener_old, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); + move16(); + } +#else /* calculate weights */ FFT_Mid_Interpol_16k_fx( Bin_Ener_old, &Bin_Ener[L_FFT / 2], Bin_Ener_mid ); /* LSF weighting */ Unified_weighting_fx( Bin_Ener_mid, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); move16(); +#endif + /* codebook selection, number of bits, size of the codebook */ test(); IF( ppp_mode == 0 && nelp_mode == 0 ) @@ -3514,6 +3753,14 @@ static void lsf_mid_enc_fx( move16(); BREAK; } +#ifdef HARM_LSF_ENC + case 1: + { + ratio = tbl_mid_voi_wb_1b_fx; // Q13 + move16(); + BREAK; + } +#endif } } ELSE IF( EQ_16( coder_type, UNVOICED ) ) @@ -3531,6 +3778,14 @@ static void lsf_mid_enc_fx( move16(); BREAK; } +#ifdef HARM_LSF_ENC + case 4: + { + ratio = tbl_mid_gen_wb_4b_fx; // Q13 + move16(); + BREAK; + } +#endif case 2: { ratio = tbl_mid_gen_wb_2b_fx; @@ -3576,7 +3831,7 @@ static void lsf_mid_enc_fx( FOR( j = 0; j < M; j++ ) { /* qlsf[j] = (1.0f - ratio[k*M+j]) * qlsf0[j] + ratio[k*M+j] * qlsf1[j]; */ - L_tmp = L_mult( sub( 0x2000, ratio[k1 + j] ), qlsf0[j] ); + L_tmp = L_mult( sub( 0x2000 /*1.Q13*/, ratio[k1 + j] ), qlsf0[j] ); L_tmp = L_mac( L_tmp, ratio[k1 + j], qlsf1[j] ); qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); @@ -3613,7 +3868,7 @@ static void lsf_mid_enc_fx( FOR( j = 0; j < M; j++ ) { /* qlsf[j] = (1.0f - ratio[idx*M+j]) * qlsf0[j] + ratio[idx*M+j] * qlsf1[j]; */ - L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); + L_tmp = L_mult( sub( 0x2000 /*1.Q13*/, ratio[idx * M + j] ), qlsf0[j] ); L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); @@ -3634,6 +3889,7 @@ static void lsf_mid_enc_fx( return; } +#ifndef HARM_LSF_ENC static void lsf_mid_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -3817,3 +4073,4 @@ static void lsf_mid_enc_ivas_fx( return; } +#endif diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index e16ae844bb8dc274745a1baf85c09e936029c5be..85a1a9ed2288790929c0f6928ddd86078145a2fa 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -890,6 +890,7 @@ void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); +#ifndef HARM_LSF_ENC void lsf_end_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ @@ -905,17 +906,20 @@ void lsf_end_enc_fx( ); void lsf_end_enc_ivas_fx( +#else +void lsf_end_enc_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ Word16 *qlsf, /* o : quantized LSF */ const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ const Word16 coder_type_org, /* i : coding type */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + const Word16 Q_ener, /* i : Q value for Bin_Ener */ + const Word16 force_sf, /* i : Force safety-net usage if coding type supports */ Word16 *lpc_param, Word16 *no_indices, Word16 *bits_param_lpc, - Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases)*/ + const Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases)*/ const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ); @@ -1530,6 +1534,7 @@ void lpc_quantization_fx( Word16 *no_param_lpc, /* Q0 */ const Word16 Q_ener ); +#ifndef HARM_LSF_ENC void lpc_quantization_ivas_fx( Encoder_State *st, const Word16 lsp[], /* Q15 */ @@ -1544,7 +1549,7 @@ void lpc_quantization_ivas_fx( Word16 *bits_param_lpc, /* Q0 */ Word16 *no_param_lpc, /* Q0 */ const Word16 Q_ener ); - +#endif void Mode2_pit_encode_fx( const Word16 coder_type, /* i : coding model */ const Word16 i_subfr, /* i : subframe index */ @@ -1820,11 +1825,17 @@ void lsf_enc_fx( Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ Word16 *Aq, /* o : quantized A(z) for 4 subframes */ +#ifndef HARM_LSF_ENC const Word16 Nb_ACELP_frames, +#endif const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ +#ifdef HARM_LSF_ENC + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ +#endif const Word16 Q_new ); +#ifndef HARM_LSF_ENC void lsf_enc_ivas_fx( Encoder_State *st, /* i/o: state structure */ Word16 *lsf_new, /* o : quantized LSF vector */ @@ -1835,7 +1846,7 @@ void lsf_enc_ivas_fx( const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const Word16 Q_new ); - +#endif void Es_pred_enc_fx( Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ Word16 *indice, /* o : indice of quantization Q0*/ diff --git a/lib_enc/qlpc_stoch_fx.c b/lib_enc/qlpc_stoch_fx.c index 0964d7421b26fa9036127c67b2dc4e23b6cf6094..0e0672abde4ccc2be39742d3f990c99cf087a30a 100644 --- a/lib_enc/qlpc_stoch_fx.c +++ b/lib_enc/qlpc_stoch_fx.c @@ -25,6 +25,7 @@ * * *--------------------------------------------------------------------*/ + void lpc_quantization_fx( Encoder_State *st, const Word16 lsp[], /* Q15 */ @@ -116,28 +117,36 @@ void lpc_quantization_fx( test(); IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) ) { +#ifdef HARM_LSF_ENC + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL ); +#else lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); +#endif nb_indices = *no_param_lpc; // Q0 move16(); } ELSE { +#ifdef HARM_LSF_ENC + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL ); +#else lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); +#endif nb_indices = *no_param_lpc; // Q0 move16(); } - FEC_lsf_estim_enc_fx( st, fec_lsf ); /* FEC - calculate LSF stability */ stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/ - test(); test(); test(); @@ -172,11 +181,9 @@ void lpc_quantization_fx( } /* Mid-frame LPC quantization */ - test(); IF( st->lpcQuantization && acelp_midLpc ) { - IF( st->rate_switching_reset == 0 ) { lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) ); @@ -196,10 +203,10 @@ void lpc_quantization_fx( } } - return; } +#ifndef HARM_LSF_ENC void lpc_quantization_ivas_fx( Encoder_State *st, const Word16 lsp[], /* Q15 */ @@ -281,16 +288,26 @@ void lpc_quantization_ivas_fx( test(); IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) ) { +#ifdef HARM_LSF_ENC + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL ); +#else lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL ); +#endif nb_indices = *no_param_lpc; // Q0 move16(); } ELSE { +#ifdef HARM_LSF_ENC + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL ); +#else lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL ); +#endif nb_indices = *no_param_lpc; // Q0 move16(); @@ -361,7 +378,7 @@ void lpc_quantization_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------* * Unified_weighting()