Loading lib_com/swb_tbe_com_fx.c +0 −1 Original line number Diff line number Diff line Loading @@ -5810,7 +5810,6 @@ void non_linearity_ivas_fx( Word16 length_half; Word16 sc_factor; #ifdef HARM_NON_LINEARITY Word16 cond; Word32 prev_scale_factor; #endif Loading lib_enc/acelp_core_enc_fx.c +11 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,9 @@ ivas_error acelp_core_enc_fx( error = IVAS_ERR_OK; (void) hStereoTD; #ifdef HARM_NON_LINEARITY (void) ener_fx; #endif /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ Loading Loading @@ -283,7 +286,11 @@ ivas_error acelp_core_enc_fx( #endif /* encode CNG parameters */ #ifdef HARM_NON_LINEARITY CNG_enc_fx( st_fx, Aq_fx, inp_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); #else CNG_enc_fx( st_fx, Aq_fx, inp_fx, ener_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); #endif /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc_fx, exc2_fx, &hTdCngEnc->lp_ener_fx, st_fx->last_core_brate, Loading Loading @@ -990,7 +997,11 @@ ivas_error acelp_core_enc_ivas_fx( #endif /* encode CNG parameters */ #ifdef HARM_NON_LINEARITY CNG_enc_fx( st, Aq, inp, lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); #else CNG_enc_ivas_fx( st, Aq, inp, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); #endif /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate, Loading lib_enc/amr_wb_enc_fx.c +4 −0 Original line number Diff line number Diff line Loading @@ -471,7 +471,11 @@ void amr_wb_enc_fx( IF( EQ_32( st->core_brate, SID_1k75 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* encode CNG parameters */ #ifdef HARM_NON_LINEARITY CNG_enc_fx( st, Aq, inp, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); #else CNG_enc_fx( st, Aq, inp, ener, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); #endif /* comfort noise generation */ CNG_exc_fx( st->core_brate, L_FRAME, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc, exc2, &hTdCngEnc->lp_ener_fx, Loading lib_enc/cng_enc_fx.c +334 −167 Original line number Diff line number Diff line /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include <stdint.h> #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ Loading @@ -8,9 +9,9 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ //#include "basop_mpy.h" #include <assert.h> /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ Loading @@ -20,18 +21,24 @@ #define INT_H 50 #define INT_L 8 /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ static void shb_CNG_encod_fx( Encoder_State *st_fx, const Word16 update_fx ); static Word16 shb_DTX_fx( Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx ); static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update ); /*---------------------------------------------------------------------* * CNG_enc() * * Confort noise generation for the coder *---------------------------------------------------------------------*/ #ifndef HARM_NON_LINEARITY void CNG_enc_fx( Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ Loading Loading @@ -1169,10 +1176,12 @@ void CNG_enc_fx( } void CNG_enc_ivas_fx( #else void CNG_enc_fx( #endif Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ // Word32 L_ener, /* i : residual energy from Levinson-Durbin Q6 */ const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ Loading Loading @@ -1207,9 +1216,14 @@ void CNG_enc_ivas_fx( Word16 max_idx[2]; Word16 ftmp_fx; Word16 lsp_tmp[M]; #ifdef HARM_NON_LINEARITY Word32 dev, max_dev, dist; Word16 dev16, max_dev16, dist16; #else Word32 dev; Word32 max_dev; Word32 dist; #endif Word16 max_idx1[2]; Word16 fft_io[L_FRAME16k]; Word16 *ptR, *ptI; Loading @@ -1233,6 +1247,10 @@ void CNG_enc_ivas_fx( Word64 w_temp; Word32 inv_frame_len; Word32 L_ener; #ifdef HARM_NON_LINEARITY Word16 *pt_res; const Word16 *pt_sp; #endif step_inv = 0; move16(); Loading @@ -1256,7 +1274,6 @@ void CNG_enc_ivas_fx( move16(); st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; move16(); /* Temp variables for floating point functions */ lp_ener_thr_scale = 8; /* 4.0f*/ /* Q1 */ move16(); Loading @@ -1266,6 +1283,38 @@ void CNG_enc_ivas_fx( move16(); } #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { pt_sp = speech; L_ener = L_deposit_l( 1 ); /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) { L_tmp = L_mult0( *pt_sp, *pt_sp ); pt_sp++; L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); pt_sp++; L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ } } ELSE /* L_FRAME16k */ { FOR( j = 0; j < 80; j++ ) { L_tmp = L_mult0( *pt_sp, *pt_sp ); pt_sp++; L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); pt_sp++; L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ } } } ELSE #endif { w_temp = 1; move64(); Loading Loading @@ -1318,6 +1367,7 @@ void CNG_enc_ivas_fx( L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ } hi = norm_l( L_ener ); lo = Log2_norm_lc( L_shl( L_ener, hi ) ); Loading Loading @@ -1374,6 +1424,7 @@ void CNG_enc_ivas_fx( * Find CNG spectral envelope * Find LSP median *-----------------------------------------------------------------*/ test(); test(); IF( ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) && GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) Loading Loading @@ -1456,6 +1507,7 @@ void CNG_enc_ivas_fx( * Quantize CNG spectral envelope (only in SID frame) * Quantize the LSF vector *-----------------------------------------------------------------*/ *allow_cn_step = 0; move16(); test(); Loading Loading @@ -1493,7 +1545,6 @@ void CNG_enc_ivas_fx( } } test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { Loading Loading @@ -1531,6 +1582,7 @@ void CNG_enc_ivas_fx( * CNG spectral envelope update * Find A(z) coefficients *---------------------------------------------------------------------*/ test(); test(); IF( ( st_fx->last_core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_1k75 ) || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) Loading Loading @@ -1635,17 +1687,42 @@ void CNG_enc_ivas_fx( IF( hTdCngEnc->burst_ho_cnt > 0 ) { #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ /*allow_cn_step |= (hDtxEnc->first_CNG || st->element_mode == EVS_MONO) && (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener);*/ /* (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener); */ L_tmp1 = L_shr( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2 ); IF( NE_16( lp_ener_thr_scale, 8 ) ) { L_tmp1 = L_add( L_tmp1, L_shr( hTdCngEnc->lp_ener_fx, 8 ) ); } L_tmp1 = L_sub( L_tmp1, hTdCngEnc->lp_ener_fx ); } ELSE { L_tmp1 = 0; move16(); } #else /**allow_cn_step |= ( hDtxEnc->first_CNG || st->element_mode == EVS_MONO ) && ( hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener );*/ w_temp = W_msu_32_16( W_shl( W_deposit32_l( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 2 ), hTdCngEnc->lp_ener_fx, lp_ener_thr_scale ); /*Q8*/ #endif test(); test(); #ifdef HARM_NON_LINEARITY IF( ( hDtxEnc->first_CNG > 0 || ( st_fx->element_mode == EVS_MONO ) ) && L_tmp1 > 0 ) #else IF( ( hDtxEnc->first_CNG > 0 || ( st_fx->element_mode == EVS_MONO ) ) && w_temp > 0 ) #endif { *allow_cn_step = s_or( *allow_cn_step, 1 ); move16(); } } test(); IF( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) { Loading Loading @@ -1798,6 +1875,30 @@ void CNG_enc_ivas_fx( } } #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { dist16 = 0; /*Q15 */ move16(); max_dev16 = 0; /*Q15 */ move16(); move16(); FOR( i = 0; i < M; i++ ) { dev16 = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15 */ dist16 = add_sat( dist16, dev16 ); /*Q15 */ if ( GT_16( dev16, max_dev16 ) ) { max_dev16 = dev16; move16(); } } dist = L_deposit_l( dist16 ); max_dev = L_deposit_l( max_dev16 ); } ELSE #endif { dist = 0; /*Q15 */ move32(); max_dev = 0; /*Q15 */ Loading @@ -1812,6 +1913,7 @@ void CNG_enc_ivas_fx( move32(); } } } test(); IF( GT_32( dist, 13107 ) || GT_32( max_dev, 3277 ) ) Loading Loading @@ -1865,6 +1967,7 @@ void CNG_enc_ivas_fx( Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ } } IF( st_fx->Opt_AMR_WB != 0 ) { E_LPC_f_isp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); Loading @@ -1872,15 +1975,21 @@ void CNG_enc_ivas_fx( ELSE { E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode != EVS_MONO ) #endif { exp = sub( Q14, norm_s( Aq[0] ) ); Scale_sig( Aq, M + 1, sub( Q12, exp ) ); // Q12 } } tmp_loop = shr( st_fx->L_frame, 6 ); FOR( i = 1; i < tmp_loop; i++ ) { Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); } /*-----------------------------------------------------------------* * Find residual signal * Calculate residual signal energy per sample Loading Loading @@ -1956,6 +2065,59 @@ void CNG_enc_ivas_fx( /* calculate the residual signal energy */ /*enr = dotp( res, res, L_frame ) / L_frame; */ #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { Word16 maxv, scale; maxv = 0; move16(); FOR( i = 0; i < st_fx->L_frame; i++ ) { maxv = s_max( maxv, abs_s( res[i] ) ); } scale = norm_s( maxv ); pt_res = res; L_ener = L_deposit_l( 1 ); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) { tmpv = shl( *pt_res, scale ); L_tmp = L_mult0( tmpv, tmpv ); pt_res++; tmpv = shl( *pt_res, scale ); L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; L_ener = L_add_sat( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ } } ELSE /* L_FRAME16k */ { FOR( j = 0; j < 160; j++ ) { tmpv = shl( *pt_res, scale ); L_tmp = L_mult0( tmpv, tmpv ); pt_res++; tmpv = shl( *pt_res, scale ); L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; L_ener = L_add_sat( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ } } /* convert log2 of residual signal energy */ /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ hi = norm_l( L_ener ); lo = Log2_norm_lc( L_shl( L_ener, hi ) ); hi = sub( 29, hi ); /* log2 exp in Q2*(Q_new+scale) */ hi = sub( hi, shl( add( Q_new, scale ), 1 ) ); /* Q0 */ L_tmp = L_Comp( hi, lo ); /* Q16 */ enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ } ELSE #endif { w_temp = 1; move64(); FOR( j = 0; j < st_fx->L_frame; j++ ) Loading Loading @@ -2022,6 +2184,8 @@ void CNG_enc_ivas_fx( L_tmp = L_Comp( hi, lo ); /* Q16 */ enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ } } /* update the circular buffer of old energies */ hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; move16(); /* Q8 */ Loading @@ -2029,6 +2193,7 @@ void CNG_enc_ivas_fx( /*-----------------------------------------------------------------* * Quantize residual signal energy (only in SID frame) *-----------------------------------------------------------------*/ test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { Loading Loading @@ -2368,6 +2533,8 @@ void CNG_enc_ivas_fx( return; } /*---------------------------------------------------------------------* * swb_CNG_enc() * Loading Loading @@ -2948,7 +3115,6 @@ static Word16 shb_DTX_ivas_fx( { Word16 i; Word16 update; Word16 allow_cn_step = 0; move16(); Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4]; Loading Loading @@ -3011,7 +3177,11 @@ static Word16 shb_DTX_ivas_fx( } ELSE { #ifdef HARM_NON_LINEARITY att_fx = 1664; /*6.5 in Q8*/ #else att_fx = -1664; // Q8 #endif move16(); } Loading @@ -3019,8 +3189,6 @@ static Word16 shb_DTX_ivas_fx( IF( st->hDtxEnc->first_CNG == 0 ) { hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; // Q8 hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; // Q8 hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; // Q8 Loading @@ -3030,6 +3198,7 @@ static Word16 shb_DTX_ivas_fx( move16(); move16(); } IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12 in Q8*/ ) ) { allow_cn_step = 1; Loading Loading @@ -3067,13 +3236,11 @@ static Word16 shb_DTX_ivas_fx( hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); update = 0; move16(); move16(); IF( EQ_32( st->core_brate, SID_2k40 ) ) { test(); { test(); test(); test(); IF( st->hDtxEnc->first_CNG == 0 ) Loading lib_enc/prot_fx_enc.h +5 −4 Original line number Diff line number Diff line Loading @@ -1781,6 +1781,7 @@ void reset_rf_indices_fx( ); void CNG_enc_fx( #ifndef HARM_NON_LINEARITY Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ Loading @@ -1794,10 +1795,10 @@ void CNG_enc_fx( Word16 *sid_bw ); void CNG_enc_ivas_fx( #endif Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ // Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ Loading Loading
lib_com/swb_tbe_com_fx.c +0 −1 Original line number Diff line number Diff line Loading @@ -5810,7 +5810,6 @@ void non_linearity_ivas_fx( Word16 length_half; Word16 sc_factor; #ifdef HARM_NON_LINEARITY Word16 cond; Word32 prev_scale_factor; #endif Loading
lib_enc/acelp_core_enc_fx.c +11 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,9 @@ ivas_error acelp_core_enc_fx( error = IVAS_ERR_OK; (void) hStereoTD; #ifdef HARM_NON_LINEARITY (void) ener_fx; #endif /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ Loading Loading @@ -283,7 +286,11 @@ ivas_error acelp_core_enc_fx( #endif /* encode CNG parameters */ #ifdef HARM_NON_LINEARITY CNG_enc_fx( st_fx, Aq_fx, inp_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); #else CNG_enc_fx( st_fx, Aq_fx, inp_fx, ener_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); #endif /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc_fx, exc2_fx, &hTdCngEnc->lp_ener_fx, st_fx->last_core_brate, Loading Loading @@ -990,7 +997,11 @@ ivas_error acelp_core_enc_ivas_fx( #endif /* encode CNG parameters */ #ifdef HARM_NON_LINEARITY CNG_enc_fx( st, Aq, inp, lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); #else CNG_enc_ivas_fx( st, Aq, inp, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); #endif /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate, Loading
lib_enc/amr_wb_enc_fx.c +4 −0 Original line number Diff line number Diff line Loading @@ -471,7 +471,11 @@ void amr_wb_enc_fx( IF( EQ_32( st->core_brate, SID_1k75 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* encode CNG parameters */ #ifdef HARM_NON_LINEARITY CNG_enc_fx( st, Aq, inp, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); #else CNG_enc_fx( st, Aq, inp, ener, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); #endif /* comfort noise generation */ CNG_exc_fx( st->core_brate, L_FRAME, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc, exc2, &hTdCngEnc->lp_ener_fx, Loading
lib_enc/cng_enc_fx.c +334 −167 Original line number Diff line number Diff line /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include <stdint.h> #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ Loading @@ -8,9 +9,9 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ //#include "basop_mpy.h" #include <assert.h> /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ Loading @@ -20,18 +21,24 @@ #define INT_H 50 #define INT_L 8 /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ static void shb_CNG_encod_fx( Encoder_State *st_fx, const Word16 update_fx ); static Word16 shb_DTX_fx( Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx ); static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update ); /*---------------------------------------------------------------------* * CNG_enc() * * Confort noise generation for the coder *---------------------------------------------------------------------*/ #ifndef HARM_NON_LINEARITY void CNG_enc_fx( Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ Loading Loading @@ -1169,10 +1176,12 @@ void CNG_enc_fx( } void CNG_enc_ivas_fx( #else void CNG_enc_fx( #endif Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ // Word32 L_ener, /* i : residual energy from Levinson-Durbin Q6 */ const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ Loading Loading @@ -1207,9 +1216,14 @@ void CNG_enc_ivas_fx( Word16 max_idx[2]; Word16 ftmp_fx; Word16 lsp_tmp[M]; #ifdef HARM_NON_LINEARITY Word32 dev, max_dev, dist; Word16 dev16, max_dev16, dist16; #else Word32 dev; Word32 max_dev; Word32 dist; #endif Word16 max_idx1[2]; Word16 fft_io[L_FRAME16k]; Word16 *ptR, *ptI; Loading @@ -1233,6 +1247,10 @@ void CNG_enc_ivas_fx( Word64 w_temp; Word32 inv_frame_len; Word32 L_ener; #ifdef HARM_NON_LINEARITY Word16 *pt_res; const Word16 *pt_sp; #endif step_inv = 0; move16(); Loading @@ -1256,7 +1274,6 @@ void CNG_enc_ivas_fx( move16(); st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; move16(); /* Temp variables for floating point functions */ lp_ener_thr_scale = 8; /* 4.0f*/ /* Q1 */ move16(); Loading @@ -1266,6 +1283,38 @@ void CNG_enc_ivas_fx( move16(); } #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { pt_sp = speech; L_ener = L_deposit_l( 1 ); /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) { L_tmp = L_mult0( *pt_sp, *pt_sp ); pt_sp++; L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); pt_sp++; L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ } } ELSE /* L_FRAME16k */ { FOR( j = 0; j < 80; j++ ) { L_tmp = L_mult0( *pt_sp, *pt_sp ); pt_sp++; L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); pt_sp++; L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ } } } ELSE #endif { w_temp = 1; move64(); Loading Loading @@ -1318,6 +1367,7 @@ void CNG_enc_ivas_fx( L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ } hi = norm_l( L_ener ); lo = Log2_norm_lc( L_shl( L_ener, hi ) ); Loading Loading @@ -1374,6 +1424,7 @@ void CNG_enc_ivas_fx( * Find CNG spectral envelope * Find LSP median *-----------------------------------------------------------------*/ test(); test(); IF( ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) && GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) Loading Loading @@ -1456,6 +1507,7 @@ void CNG_enc_ivas_fx( * Quantize CNG spectral envelope (only in SID frame) * Quantize the LSF vector *-----------------------------------------------------------------*/ *allow_cn_step = 0; move16(); test(); Loading Loading @@ -1493,7 +1545,6 @@ void CNG_enc_ivas_fx( } } test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { Loading Loading @@ -1531,6 +1582,7 @@ void CNG_enc_ivas_fx( * CNG spectral envelope update * Find A(z) coefficients *---------------------------------------------------------------------*/ test(); test(); IF( ( st_fx->last_core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_1k75 ) || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) Loading Loading @@ -1635,17 +1687,42 @@ void CNG_enc_ivas_fx( IF( hTdCngEnc->burst_ho_cnt > 0 ) { #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ /*allow_cn_step |= (hDtxEnc->first_CNG || st->element_mode == EVS_MONO) && (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener);*/ /* (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener); */ L_tmp1 = L_shr( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2 ); IF( NE_16( lp_ener_thr_scale, 8 ) ) { L_tmp1 = L_add( L_tmp1, L_shr( hTdCngEnc->lp_ener_fx, 8 ) ); } L_tmp1 = L_sub( L_tmp1, hTdCngEnc->lp_ener_fx ); } ELSE { L_tmp1 = 0; move16(); } #else /**allow_cn_step |= ( hDtxEnc->first_CNG || st->element_mode == EVS_MONO ) && ( hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener );*/ w_temp = W_msu_32_16( W_shl( W_deposit32_l( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 2 ), hTdCngEnc->lp_ener_fx, lp_ener_thr_scale ); /*Q8*/ #endif test(); test(); #ifdef HARM_NON_LINEARITY IF( ( hDtxEnc->first_CNG > 0 || ( st_fx->element_mode == EVS_MONO ) ) && L_tmp1 > 0 ) #else IF( ( hDtxEnc->first_CNG > 0 || ( st_fx->element_mode == EVS_MONO ) ) && w_temp > 0 ) #endif { *allow_cn_step = s_or( *allow_cn_step, 1 ); move16(); } } test(); IF( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) { Loading Loading @@ -1798,6 +1875,30 @@ void CNG_enc_ivas_fx( } } #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { dist16 = 0; /*Q15 */ move16(); max_dev16 = 0; /*Q15 */ move16(); move16(); FOR( i = 0; i < M; i++ ) { dev16 = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15 */ dist16 = add_sat( dist16, dev16 ); /*Q15 */ if ( GT_16( dev16, max_dev16 ) ) { max_dev16 = dev16; move16(); } } dist = L_deposit_l( dist16 ); max_dev = L_deposit_l( max_dev16 ); } ELSE #endif { dist = 0; /*Q15 */ move32(); max_dev = 0; /*Q15 */ Loading @@ -1812,6 +1913,7 @@ void CNG_enc_ivas_fx( move32(); } } } test(); IF( GT_32( dist, 13107 ) || GT_32( max_dev, 3277 ) ) Loading Loading @@ -1865,6 +1967,7 @@ void CNG_enc_ivas_fx( Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ } } IF( st_fx->Opt_AMR_WB != 0 ) { E_LPC_f_isp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); Loading @@ -1872,15 +1975,21 @@ void CNG_enc_ivas_fx( ELSE { E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode != EVS_MONO ) #endif { exp = sub( Q14, norm_s( Aq[0] ) ); Scale_sig( Aq, M + 1, sub( Q12, exp ) ); // Q12 } } tmp_loop = shr( st_fx->L_frame, 6 ); FOR( i = 1; i < tmp_loop; i++ ) { Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); } /*-----------------------------------------------------------------* * Find residual signal * Calculate residual signal energy per sample Loading Loading @@ -1956,6 +2065,59 @@ void CNG_enc_ivas_fx( /* calculate the residual signal energy */ /*enr = dotp( res, res, L_frame ) / L_frame; */ #ifdef HARM_NON_LINEARITY IF( st_fx->element_mode == EVS_MONO ) { Word16 maxv, scale; maxv = 0; move16(); FOR( i = 0; i < st_fx->L_frame; i++ ) { maxv = s_max( maxv, abs_s( res[i] ) ); } scale = norm_s( maxv ); pt_res = res; L_ener = L_deposit_l( 1 ); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) { tmpv = shl( *pt_res, scale ); L_tmp = L_mult0( tmpv, tmpv ); pt_res++; tmpv = shl( *pt_res, scale ); L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; L_ener = L_add_sat( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ } } ELSE /* L_FRAME16k */ { FOR( j = 0; j < 160; j++ ) { tmpv = shl( *pt_res, scale ); L_tmp = L_mult0( tmpv, tmpv ); pt_res++; tmpv = shl( *pt_res, scale ); L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ pt_res++; L_ener = L_add_sat( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ } } /* convert log2 of residual signal energy */ /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ hi = norm_l( L_ener ); lo = Log2_norm_lc( L_shl( L_ener, hi ) ); hi = sub( 29, hi ); /* log2 exp in Q2*(Q_new+scale) */ hi = sub( hi, shl( add( Q_new, scale ), 1 ) ); /* Q0 */ L_tmp = L_Comp( hi, lo ); /* Q16 */ enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ } ELSE #endif { w_temp = 1; move64(); FOR( j = 0; j < st_fx->L_frame; j++ ) Loading Loading @@ -2022,6 +2184,8 @@ void CNG_enc_ivas_fx( L_tmp = L_Comp( hi, lo ); /* Q16 */ enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ } } /* update the circular buffer of old energies */ hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; move16(); /* Q8 */ Loading @@ -2029,6 +2193,7 @@ void CNG_enc_ivas_fx( /*-----------------------------------------------------------------* * Quantize residual signal energy (only in SID frame) *-----------------------------------------------------------------*/ test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { Loading Loading @@ -2368,6 +2533,8 @@ void CNG_enc_ivas_fx( return; } /*---------------------------------------------------------------------* * swb_CNG_enc() * Loading Loading @@ -2948,7 +3115,6 @@ static Word16 shb_DTX_ivas_fx( { Word16 i; Word16 update; Word16 allow_cn_step = 0; move16(); Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4]; Loading Loading @@ -3011,7 +3177,11 @@ static Word16 shb_DTX_ivas_fx( } ELSE { #ifdef HARM_NON_LINEARITY att_fx = 1664; /*6.5 in Q8*/ #else att_fx = -1664; // Q8 #endif move16(); } Loading @@ -3019,8 +3189,6 @@ static Word16 shb_DTX_ivas_fx( IF( st->hDtxEnc->first_CNG == 0 ) { hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; // Q8 hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; // Q8 hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; // Q8 Loading @@ -3030,6 +3198,7 @@ static Word16 shb_DTX_ivas_fx( move16(); move16(); } IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12 in Q8*/ ) ) { allow_cn_step = 1; Loading Loading @@ -3067,13 +3236,11 @@ static Word16 shb_DTX_ivas_fx( hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); update = 0; move16(); move16(); IF( EQ_32( st->core_brate, SID_2k40 ) ) { test(); { test(); test(); test(); IF( st->hDtxEnc->first_CNG == 0 ) Loading
lib_enc/prot_fx_enc.h +5 −4 Original line number Diff line number Diff line Loading @@ -1781,6 +1781,7 @@ void reset_rf_indices_fx( ); void CNG_enc_fx( #ifndef HARM_NON_LINEARITY Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ Loading @@ -1794,10 +1795,10 @@ void CNG_enc_fx( Word16 *sid_bw ); void CNG_enc_ivas_fx( #endif Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ // Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ Loading