From ff8d86dbc1edf122790e64dc429bc5e1b13af235 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 6 Mar 2024 16:16:25 -0500 Subject: [PATCH 01/11] Fix assert for hi-level input --- lib_com/cng_exc_fx.c | 7 +++++-- lib_enc/cng_enc_fx.c | 7 ++++++- lib_enc/cor_shif_fx.c | 4 ++++ lib_enc/detect_transient_fx.c | 8 ++++++++ lib_enc/find_tilt_fx.c | 4 ++++ lib_enc/find_uv_fx.c | 15 +++++++++++++-- lib_enc/nelp_enc_fx.c | 9 ++++++++- lib_enc/pitch_ol2_fx.c | 5 ++++- lib_enc/speech_music_classif_fx.c | 13 ++++++++++++- lib_enc/transition_enc_fx.c | 5 ++++- lib_enc/vad_basop_fx.c | 4 ++++ 11 files changed, 72 insertions(+), 9 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index e8c3e63e7..41e94478f 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -249,8 +249,11 @@ void CNG_exc_fx( exp = norm_l(*Enew); L_tmp = L_shl(*Enew,exp); /* Q(exp+6) */ L_tmp = Mult_32_16(L_tmp,shl(L_frame,5)); /* Q(exp+6+5-15=exp-4) */ - L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ - +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /* Q6 */ +#else + L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /* Q6 */ +#endif exp = norm_l(L_tmp); fra = Log2_norm_lc(L_shl(L_tmp,exp)); exp = sub(sub(30,exp),6); diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index d66280e38..71035252d 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -452,7 +452,7 @@ void CNG_enc_fx( IF(NE_16(lp_ener_thr_scale, 8)) { L_tmp1 = L_add(L_tmp1, L_shr(hTdCngEnc->lp_ener_fx, 8)); - } + } /*fenew = dotp( fexc, fexc, pit_max )/pit_max;*/ L_tmp1 = L_sub(L_tmp1, hTdCngEnc->lp_ener_fx); #else L_tmp1 = L_shr(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr],2); @@ -989,7 +989,12 @@ void CNG_enc_fx( exp = norm_l(hTdCngEnc->Enew_fx); L_tmp = L_shl(hTdCngEnc->Enew_fx,exp); /*Q(exp+6) */ L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame_fx,5));/* Q(exp+6+5-15=exp-4) */ + +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat(L_tmp,sub(exp,10)); /* Q6 */ +#else L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ +#endif exp = norm_l(L_tmp); fra = Log2_norm_lc(L_shl(L_tmp,exp)); diff --git a/lib_enc/cor_shif_fx.c b/lib_enc/cor_shif_fx.c index 94a1a58b7..7f2315512 100644 --- a/lib_enc/cor_shif_fx.c +++ b/lib_enc/cor_shif_fx.c @@ -43,7 +43,11 @@ Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q e_Noise = sub(e_Noise, 14); /* Retreive exponent of wtmp */ Ltmp = Mpy_32_16(8, 837, wtmp); /* 2.4492e-4(Q31) * exp(0.1596*totalNoise) */ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat(Ltmp,add(e_Noise, 15)); /* Result in Q31 */ +#else Ltmp = L_shl(Ltmp,add(e_Noise, 15)); /* Result in Q31 */ +#endif corr_shift_fx = round_fx(L_sub(Ltmp, 47244640)); /* Represents corr_shift in Q15 */ } corr_shift_fx = s_min(corr_shift_fx,16384); /* limit to 0.5 */ diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 47c0de708..d1de7b360 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -341,7 +341,11 @@ Word16 detect_transient_fx( { /*blk++; */ blk = add(blk, 1); +#ifdef BASOP_NOGLOB + E_low_fx = L_add_sat(E_low_fx, Energy_in_fx[i]); +#else E_low_fx = L_add(E_low_fx, Energy_in_fx[i]); +#endif } exp = norm_s(blk); @@ -357,7 +361,11 @@ Word16 detect_transient_fx( { /*blk++; */ blk = add(blk, 1); +#ifdef BASOP_NOGLOB + E_high_fx = L_add_sat( E_high_fx, Energy_in_fx[i] ); +#else E_high_fx = L_add(E_high_fx, Energy_in_fx[i]); +#endif } exp = norm_s(blk); diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index 57a59a883..350a7dc8c 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -241,7 +241,11 @@ void find_tilt_fx( IF (EQ_32(Ltmp, MAX_32)) /* if Overflow: Compute with less precision */ { Ltmp = Mult_32_16(ee[i], 24576); /* 6/8 */ +#ifdef BASOP_NOGLOB + ee[i] = L_shl_sat( Ltmp, 3 ); +#else ee[i] = L_shl(Ltmp, 3); +#endif move32(); /* x8 */ } ELSE diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index d9ef93c1f..35adabf3c 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -241,8 +241,11 @@ Word16 find_uv_fx( /* o : coding type /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923); Ltmp0 = L_mac(Ltmp0, st_fx->voicing_fx[1], 10923); +#ifdef BASOP_NOGLOB // -dtx 12650 amrwb\Dtx3.INP + mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 ); /*Q15*/ +#else mean_voi3 = mac_r(Ltmp0, st_fx->voicing_fx[2], 10923); /*Q15*/ - +#endif /*-----------------------------------------------------------------* * Total frame energy difference (dE3) *-----------------------------------------------------------------*/ @@ -467,7 +470,11 @@ Word16 find_uv_fx( /* o : coding type #else /* BASOP_NOGLOB */ if( ( ( LT_16(add(mean_voi3, corr_shift),add(22774,mean_voi3_offset)))&& /* normalized correlation low */ #endif +#ifdef BASOP_NOGLOB + ( LT_16(add_sat(st_fx->voicing_fx[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ +#else ( LT_16(add(st_fx->voicing_fx[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ +#endif ( LT_32(ee[0], 397) ) && ( GT_32(hp_E[0], E_min_th) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32(ee[1], 397) ) && ( GT_32(hp_E[1], E_min_th) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ @@ -632,7 +639,11 @@ Word16 find_uv_fx( /* o : coding type test(); if( ( GT_16(st_fx->spike_hyst_fx,1))&& ( GT_16(dE3,5<<8) || /* energy increases */ - ( GT_16(relE, -3328)&&(GT_16(add(mean_voi3,corr_shift),22774))))) /* normalized correlation is high */ +#ifdef BASOP_NOGLOB + ( GT_16( relE, -3328 ) && ( GT_16( add_sat( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */ +#else + ( GT_16( relE, -3328 ) && ( GT_16( add( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */ +#endif { st_fx->spike_hyst_fx = -1; move16(); diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index 018c055a9..5115bae43 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -471,10 +471,17 @@ void nelp_encoder_fx( L_tmp = L_deposit_h(tmp1); L_tmp = Isqrt_lc(L_tmp, &exp1); L_tmp = Mult_32_16(L_tmp, sqrt_inv_lag); +#ifdef BASOP_NOGLOB + Ltemp = L_shl_sat( L_tmp, sub( exp1, 12 ) ); /*Q3 */ +#else Ltemp = L_shl(L_tmp, sub(exp1, 12));/*Q3 */ +#endif } - +#ifdef BASOP_NOGLOB + Gains_fx[i] = round_fx_sat( Ltemp ); +#else Gains_fx[i] = round_fx(Ltemp); +#endif } diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index 416801656..91c6df713 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -257,8 +257,11 @@ void StableHighPitchDetect_fx( L_tmp = L_mult(voicing[0],10923); L_tmp = L_mac(L_tmp, voicing[1],10923); L_tmp = L_mac(L_tmp, voicing[2],10923); +#ifdef BASOP_NOGLOB + voicing_m = round_fx_sat( L_tmp ); +#else voicing_m = round_fx(L_tmp); - +#endif /**voicing_sm = 0.75f*(*voicing_sm) + 0.25f*voicing;*/ *voicing_sm = round_fx(L_mac(L_mult(*voicing_sm , 24576), voicing_m , 8192)); diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 57145de95..931daa893 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -477,7 +477,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech L_tmp = L_mult(st_fx->voicing_fx[0], 10923); L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); L_tmp = L_mac(L_tmp, st_fx->voicing_fx[2], 10923); +#ifdef BASOP_NOGLOB + *pFV++ = round_fx_sat( L_tmp ); +#else *pFV++ = round_fx(L_tmp); +#endif } /* [2,3,4,5,6] LSFs Q15*/ @@ -3199,7 +3203,11 @@ static void music_mixed_classif_improv_fx( expn = sub(sub(30,expn),Q_epsP-4); expd = norm_l(ftmp); +#ifdef BASOP_NOGLOB + fracd = round_fx_sat(L_shl(ftmp,expd)); +#else fracd = round_fx(L_shl(ftmp,expd)); +#endif expd = sub(sub(30,expd),sub(Q_epsP,4)); scale = shr(sub(fracd,fracn),15); @@ -3452,8 +3460,11 @@ static void tonal_context_improv_fx( /* voi_mean = 0.33f * (st->voicing_fx[0] + voicing[1] + voicing[2]); */ L_tmp = L_mult(st_fx->voicing_fx[0], 10923); L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); +#ifdef BASOP_NOGLOB // -dtx 12650 amrwb\Dtx3.INP + voi_mean = mac_r_sat( L_tmp, st_fx->voicing_fx[2], 10923 ); /* Q15 */ +#else voi_mean = mac_r(L_tmp, st_fx->voicing_fx[2], 10923); /* Q15 */ - +#endif test(); IF( EQ_16(hVAD->hangover_cnt,10) && EQ_16(st_fx->vad_flag,1)) { diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index baf2a2db7..099c9a477 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -1265,8 +1265,11 @@ void tc_classif_enc_fx( len = add(shr(T_op,1), 2); position_tmp = emaximum_fx(Q_new, res, len, &temp2); - +#ifdef BASOP_NOGLOB + L_sum = L_mac_sat( 1L, res[0], res[0] ); +#else L_sum = L_mac(1L, res[0], res[0]); +#endif FOR(i = 1; i < len; i++) { #ifdef BASOP_NOGLOB diff --git a/lib_enc/vad_basop_fx.c b/lib_enc/vad_basop_fx.c index 9cab551c3..bf1d685f7 100644 --- a/lib_enc/vad_basop_fx.c +++ b/lib_enc/vad_basop_fx.c @@ -118,7 +118,11 @@ Word16 FixSqrt(Word32 i_s32Val, Word16 *io_s16Q) Word16 result, exp; exp = sub(31, *io_s16Q); +#ifdef BASOP_NOGLOB + result = round_fx_sat( Sqrt32( i_s32Val, &exp ) ); +#else result = round_fx(Sqrt32(i_s32Val, &exp)); +#endif move16(); *io_s16Q = sub(15, exp); -- GitLab From 67d7fc1b312fa43b605fe0994fa430ad93d19855 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 7 Mar 2024 09:47:39 -0500 Subject: [PATCH 02/11] more fixes for hi-level content --- lib_com/cng_exc_fx.c | 6 +++++- lib_com/enhancer_fx.c | 6 +++++- lib_com/fd_cng_com_fx.c | 12 ++++++++++-- lib_com/modif_fs_fx.c | 12 ++++++++++-- lib_com/phase_dispersion_fx.c | 7 ++++++- lib_com/swb_bwe_com_fx.c | 6 +++++- lib_com/swb_bwe_com_lr_fx.c | 6 +++++- lib_com/tcx_mdct_fx.c | 16 ++++++++++++---- lib_com/tools_fx.c | 15 +++++++++++---- lib_dec/LD_music_post_filter_fx.c | 6 +++++- lib_dec/core_dec_init_fx.c | 2 +- lib_dec/dec_tcx_fx.c | 12 ++++++++++-- lib_dec/gain_dec_fx.c | 6 +++++- lib_dec/hq_lr_dec_fx.c | 18 +++++++++++++++--- lib_dec/init_dec_fx.c | 2 +- lib_dec/ppp_dec_fx.c | 7 +++++-- lib_dec/swb_bwe_dec_fx.c | 4 ++++ lib_dec/syn_outp_fx.c | 6 +++++- 18 files changed, 120 insertions(+), 29 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 41e94478f..c5b8caaef 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -548,7 +548,11 @@ void CNG_exc_fx( { L_tmp = L_mult0(*pt_fft_io, *pt_fft_io); pt_fft_io++; - L_tmp = L_mac0(L_tmp, *pt_fft_io, *pt_fft_io); /* 2*(Q_exc) */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ +#else + L_tmp = L_mac0( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ +#endif pt_fft_io++; L_tmp2 = L_add(L_tmp2, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_exc)+15+1-16+1, divide by L_frame done here */ } diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 9ffcfabcc..ab9e9f781 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -245,7 +245,11 @@ void enhancer_fx( L_tmp = L_msu(L_tmp, code[i + 1], tmp); tmp16 = msu_r(L_tmp, code[i - 1], tmp); L_tmp = L_shl(L_mult(gain_code_hi, tmp16), sc); - pt_exc2[i] = msu_r(L_tmp, -32768, pt_exc2[i]); +#ifdef BASOP_NOGLOB + pt_exc2[i] = msu_r_sat( L_tmp, -32768, pt_exc2[i] ); +#else + pt_exc2[i] = msu_r( L_tmp, -32768, pt_exc2[i] ); +#endif move16(); /* in Q_exc */ } diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 279a0afee..1b4474a9f 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -2169,7 +2169,11 @@ void AnalysisSTFT ( move32(); move32(); fftBuffer[i+len] = L_mult(shr(timeDomainInput[i],Q), mult_r(olapWin[i].v.re, 23170/*1.4142135623730950488016887242097 Q14*/)); - fftBuffer[i+len+len2] = L_mult(shr(timeDomainInput[i+len2],Q), mult_r(olapWin[len2-1-i].v.im, 23170/*1.4142135623730950488016887242097 Q14*/)); +#ifdef BASOP_NOGLOB + fftBuffer[i + len + len2] = L_mult( shr_sat( timeDomainInput[i + len2], Q ), mult_r( olapWin[len2 - 1 - i].v.im, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); +#else + fftBuffer[i + len + len2] = L_mult( shr( timeDomainInput[i + len2], Q ), mult_r( olapWin[len2 - 1 - i].v.im, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); +#endif } /* Perform FFT */ @@ -2177,7 +2181,11 @@ void AnalysisSTFT ( FOR (i=0; i frameSize,len)+i], Q ); +#ifdef BASOP_NOGLOB + olapBuffer[i] = shr_sat( timeDomainInput[sub( hFdCngCom->frameSize, len ) + i], Q ); +#else + olapBuffer[i] = shr( timeDomainInput[sub( hFdCngCom->frameSize, len ) + i], Q ); +#endif move16(); } diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 8eb7dff6a..7d42b2689 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -1251,7 +1251,11 @@ void interpolate_3_over_1_allpass_fx( move16(); Vm[1] = add(mem_fx[4], mult_r(filt_coeff_fx[4], sub(Vm[0], mem_fx[5]))); move16(); - mem_fx[6] = add(mem_fx[5], mult_r(filt_coeff_fx[5], sub(Vm[1], mem_fx[6]))); +#ifdef BASOP_NOGLOB + mem_fx[6] = add_sat( mem_fx[5], mult_r( filt_coeff_fx[5], sub_sat( Vm[1], mem_fx[6] ) ) ); +#else + mem_fx[6] = add( mem_fx[5], mult_r( filt_coeff_fx[5], sub( Vm[1], mem_fx[6] ) ) ); +#endif move16(); mem_fx[4] = Vm[0]; @@ -1269,7 +1273,11 @@ void interpolate_3_over_1_allpass_fx( move16(); Vl[1] = add(mem_fx[7], mult_r(filt_coeff_fx[7], sub(Vl[0], mem_fx[8]))); move16(); - mem_fx[9] = add(mem_fx[8], mult_r(filt_coeff_fx[8], sub(Vl[1], mem_fx[9]))); +#ifdef BASOP_NOGLOB + mem_fx[9] = add_sat( mem_fx[8], mult_r( filt_coeff_fx[8], sub_sat( Vl[1], mem_fx[9] ) ) ); +#else + mem_fx[9] = add( mem_fx[8], mult_r( filt_coeff_fx[8], sub( Vl[1], mem_fx[9] ) ) ); +#endif move16(); mem_fx[0] = input_fx[i]; diff --git a/lib_com/phase_dispersion_fx.c b/lib_com/phase_dispersion_fx.c index 6874b790c..3c01533c6 100644 --- a/lib_com/phase_dispersion_fx.c +++ b/lib_com/phase_dispersion_fx.c @@ -118,8 +118,13 @@ void phase_dispersion( scale2 = getScaleFactor32(x32, L_subfr); FOR (i=0; ihTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0)); } - if (st->element_mode == EVS_MONO) + if (1)//st->element_mode == EVS_MONO) { if ((st->hTECDec = (TEC_DEC_HANDLE)malloc(sizeof(TEC_DEC_DATA))) == NULL) { diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index a20e8ca65..136832c63 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2205,7 +2205,11 @@ void IMDCT(Word32 *x, Word16 x_e, FOR (i=0; i Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); +#endif move32(); /* Q10 -> Q16*/ } diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 7acc5e8b1..d6e9eee5b 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -670,7 +670,11 @@ void hq_lr_dec_fx( tmp = sub(bands_fx,p2a_bands_fx); tmp = sub(tmp,lowband);/*Q0 */ - tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ +#ifdef BASOP_NOGLOB + tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ +#else + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ +#endif IF(tmp1 != 0) { exp = norm_s(tmp1); @@ -726,7 +730,11 @@ void hq_lr_dec_fx( { tmp = sub(tmp,lowband); - tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ +#ifdef BASOP_NOGLOB + tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ +#else + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ +#endif IF(tmp1 != 0) { exp = norm_s(tmp1); @@ -799,7 +807,11 @@ void hq_lr_dec_fx( move16(); FOR (i = 0; i < lowband; i++) { - tmp = Calc_inv(L_shl(Ep_avrgL_fx,1), &exp); +#ifdef BASOP_NOGLOB + tmp = Calc_inv( L_shl_sat( Ep_avrgL_fx, 1 ), &exp ); +#else + tmp = Calc_inv( L_shl( Ep_avrgL_fx, 1 ), &exp ); +#endif L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(15+exp-15 = exp) */ L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+0-15 = exp-15) */ L_tmp = L_shl(L_tmp,sub(28,exp));/*Q14 0.5 */ diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index cfdf40c98..d18850334 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -627,7 +627,7 @@ ivas_error init_decoder_fx( } /* HF synth init */ - hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); + //hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 9f15cfba8..f9a4faef7 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -168,8 +168,11 @@ static void DTFS_dequant_cw_fx( frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ L_tmp = Pow2(14, frac); exp1 = sub(exp1, 14); - L_temp = L_shl(L_tmp, exp1 + 15); /* Q15 */ - +#ifdef BASOP_NOGLOB + L_temp = L_shl_sat( L_tmp, exp1 + 15 ); /* Q15 */ +#else + L_temp = L_shl( L_tmp, exp1 + 15 ); /* Q15 */ +#endif L_tmp2 = L_temp; if (GE_32(L_temp, 2147483647)) { diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 1e0ffd471..ef505ae45 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -573,7 +573,11 @@ Word16 wb_bwe_dec_fx( { /* de-quantization */ mode = WB_BWE_gain_deq_fx(st_fx, WB_fenv_fx ); +#ifdef BASOP_NOGLOB + st_fx->last_wb_bwe_ener_fx = mult_r(add_sat(WB_fenv_fx[0], WB_fenv_fx[1]), 16384); // this would not saturate if written like : rounf_fx(L_mac(L_mult(WB_fenv_fx[0], 16384), WB_fenv_fx[1], 16384)) +#else st_fx->last_wb_bwe_ener_fx = mult_r(add(WB_fenv_fx[0], WB_fenv_fx[1]), 16384); +#endif } ELSE { diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index ec5cc6bcd..e4299b6dd 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -40,7 +40,11 @@ void syn_output_fx( FOR (i = 0; i < output_frame; i++) { L_tmp = L_deposit_h(synth[i]); - synth_out[i] = round_fx(L_shr(L_tmp, tmp)); +#ifdef BASOP_NOGLOB + synth_out[i] = round_fx_sat( L_shr_sat( L_tmp, tmp ) ); +#else + synth_out[i] = round_fx( L_shr( L_tmp, tmp ) ); +#endif } } ELSE -- GitLab From b6abe1f657df77478ae74cad331c8f9180bded3d Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 7 Mar 2024 11:41:27 -0500 Subject: [PATCH 03/11] more fixes for hi-level content --- lib_com/fd_cng_com_fx.c | 3 ++- lib_com/gs_preech.c | 7 +++++-- lib_com/stat_noise_uv_mod_fx.c | 6 +++++- lib_com/syn_filt_fx.c | 22 ++++++++++++++++++---- lib_com/tcq_position_arith_fx.c | 9 +++++++-- lib_com/tcx_mdct_fx.c | 12 ++++++++++-- lib_dec/cng_dec_fx.c | 7 +++++-- lib_dec/dec_tran_fx.c | 13 +++++++++++-- lib_enc/cod_tcx_fx.c | 12 ++++++++++-- lib_enc/enc_higher_acelp_fx.c | 7 ++++++- lib_enc/ext_sig_ana_fx.c | 6 +++++- lib_enc/find_tar_fx.c | 6 +++++- lib_enc/gaus_enc_fx.c | 7 +++++-- lib_enc/hq_lr_enc_fx.c | 18 +++++++++++++++--- lib_enc/ltd_stable_fx.c | 6 +++++- lib_enc/pit_enc_fx.c | 10 +++++++--- lib_enc/q_gain2p_fx.c | 6 +++++- lib_enc/vlpc_1st_cod_fx.c | 6 +++++- 18 files changed, 131 insertions(+), 32 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 1b4474a9f..74833cc16 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -2168,10 +2168,11 @@ void AnalysisSTFT ( { move32(); move32(); - fftBuffer[i+len] = L_mult(shr(timeDomainInput[i],Q), mult_r(olapWin[i].v.re, 23170/*1.4142135623730950488016887242097 Q14*/)); #ifdef BASOP_NOGLOB + fftBuffer[i + len] = L_mult( shr_sat( timeDomainInput[i], Q ), mult_r( olapWin[i].v.re, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); fftBuffer[i + len + len2] = L_mult( shr_sat( timeDomainInput[i + len2], Q ), mult_r( olapWin[len2 - 1 - i].v.im, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); #else + fftBuffer[i + len] = L_mult( shr( timeDomainInput[i], Q ), mult_r( olapWin[i].v.re, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); fftBuffer[i + len + len2] = L_mult( shr( timeDomainInput[i + len2], Q ), mult_r( olapWin[len2 - 1 - i].v.im, 23170 /*1.4142135623730950488016887242097 Q14*/ ) ); #endif } diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index 164cd0225..8ed594444 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -213,8 +213,11 @@ void pre_echo_att_fx( exp = sub(n1, n2); frac1 = round_fx(L_shl(etmp_fx, n1)); - frac2 = round_fx(L_shl(*Last_frame_ener_fx, n2)); - +#ifdef BASOP_NOGLOB + frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) ); +#else + frac2 = round_fx( L_shl( *Last_frame_ener_fx, n2 ) ); +#endif L_tmp = L_mult0(128, div_s(frac1, frac2)); /* s = gain_out / gain_in */ L_tmp = L_shr(L_tmp, exp); /* add exponent */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index f0ad7721f..32782bc85 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -213,7 +213,11 @@ void stat_noise_uv_mod_fx( FOR (i=1; iEnew_fx); L_tmp = L_shl(hTdCngDec->Enew_fx,exp);/*Q(exp+6)*/ L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame,5));/*Q(exp+6+5-15=exp-4)*/ - L_tmp = L_shr(L_tmp,sub(exp,10));/*Q6*/ - +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /*Q6*/ +#else + L_tmp = L_shr( L_tmp, sub( exp, 10 ) ); /*Q6*/ +#endif exp = norm_l(L_tmp); fra = Log2_norm_lc(L_shl(L_tmp,exp)); exp = sub(sub(30,exp),6); diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index 3192c9cd2..7e5dde3cd 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -179,13 +179,22 @@ void decod_tran_fx( FOR( i = 0; i < L_SUBFR; i++ ) { L_tmp = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q10 -> Q13*/ - L_tmp = L_shl(L_tmp,tmp1_fx); /* Q16 + Q_exc */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ + tmp_fx = round_fx_sat(L_tmp); + exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); + move16(); + exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); + move16(); +#else + L_tmp = L_shl( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ tmp_fx = round_fx(L_tmp); - exc2_fx[i+i_subfr] = add(exc2_fx[i+i_subfr],tmp_fx); move16(); exc_fx[i+i_subfr] = add(exc_fx[i+i_subfr],tmp_fx); move16(); +#endif + } } diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 4510615a8..742fa5ad6 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -2631,7 +2631,11 @@ void QuantizeSpectrum_fx( BASOP_SATURATE_WARNING_OFF_EVS; FOR (i=0; iTxnq[i]), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( add( xn_buf16[i], hTcxEnc->Txnq[i] ), TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( add( xn_buf16[i], hTcxEnc->Txnq[i] ), TCX_IMDCT_HEADROOM ); +#endif move16(); } @@ -2639,7 +2643,11 @@ void QuantizeSpectrum_fx( { FOR ( ; i < L_frame; i++) { - xn_buf16[i] = shl(xn_buf16[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( xn_buf16[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( xn_buf16[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index aa0f93037..fec213b84 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -149,8 +149,13 @@ void transf_cdbk_enc_fx( /*fcorr += fx_tran[i]*(float)ix_norm[i];*/ /*fener += (float)ix_norm[i]*(float)ix_norm[i];*/ stmp = shl(x_norm[i],Q_AVQ_OUT ); - L_corr = L_mac(L_corr, x_tran[i], stmp); +#ifdef BASOP_NOGLOB + L_corr = L_mac_sat( L_corr, x_tran[i], stmp ); + L_ener = L_mac_sat(L_ener, stmp, stmp); +#else + L_corr = L_mac( L_corr, x_tran[i], stmp ); L_ener = L_mac(L_ener, stmp, stmp); +#endif } L_ener = L_max(L_ener,1); diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 4da307b59..6a8341f03 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -326,7 +326,11 @@ void core_signal_analysis_high_bitrate_fx( tmp = shr(right_overlap, 1); FOR(i = 0; i < tmp; i++) { - tcx20Win[L_subframe + folding_offset - 1 - i] = add(tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i]); +#ifdef BASOP_NOGLOB + tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); +#else + tcx20Win[L_subframe + folding_offset - 1 - i] = add( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); +#endif move16(); } /* 2xTCX5 */ diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index dedc4ff4b..f00b77b9f 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -51,7 +51,11 @@ void find_targets_fx( *-----------------------------------------------------------------------*/ FOR (i=0; i Date: Thu, 7 Mar 2024 13:27:27 -0500 Subject: [PATCH 04/11] more fixes for hi-level content --- lib_com/fd_cng_com_fx.c | 6 +++++- lib_com/interpol.c | 7 +++++-- lib_com/stat_noise_uv_mod_fx.c | 7 +++++-- lib_com/swb_bwe_com_fx.c | 6 +++++- lib_com/tools_fx.c | 5 ++++- lib_dec/d_gain2p_fx.c | 8 ++++++-- lib_dec/swb_tbe_dec_fx.c | 4 ++++ lib_enc/gain_enc_fx.c | 7 +++++-- lib_enc/hq_classifier_enc_fx.c | 8 ++++++-- lib_enc/nelp_enc_fx.c | 23 ++++++++++++++++++----- lib_enc/swb_bwe_enc_fx.c | 6 +++++- lib_enc/swb_tbe_enc_fx.c | 10 +++++++++- lib_enc/tcx_utils_enc_fx.c | 12 ++++++++++-- lib_enc/tns_base_enc_fx.c | 6 +++++- 14 files changed, 92 insertions(+), 23 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 74833cc16..941e458fe 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -574,7 +574,11 @@ void minimum_statistics ( { /* calculate scalar with normalized msPeriodogSum[cnt], exponent -2*s1 */ s1 = norm_l(msPeriodogSum[cnt]); - msPeriodogSum16 = round_fx(L_shl(msPeriodogSum[cnt],s1)); +#ifdef BASOP_NOGLOB + msPeriodogSum16 = round_fx_sat( L_shl_sat( msPeriodogSum[cnt], s1 ) ); +#else + msPeriodogSum16 = round_fx( L_shl( msPeriodogSum[cnt], s1 ) ); +#endif scalar = L_mult(msPeriodogSum16, msPeriodogSum16); /* calculate difference, both elements in 16Q15 format, use absolute value diff --git a/lib_com/interpol.c b/lib_com/interpol.c index ca33b80c3..7969b8ab2 100644 --- a/lib_com/interpol.c +++ b/lib_com/interpol.c @@ -109,8 +109,11 @@ Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ } L_sum = W_sat_l(L_sum64); } - L_sum = L_shl(L_sum, 1); - +#ifdef BASOP_NOGLOB + L_sum = L_shl_sat( L_sum, 1 ); +#else + L_sum = L_shl( L_sum, 1 ); +#endif return L_sum; } diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 32782bc85..32be86394 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -403,8 +403,11 @@ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ r1 = L_abs(r1); L_tmp_res = Div_32(r1,extract_h(r0), extract_l(r0)); - L_tmp_res = L_shl(L_tmp_res, tmp_shift); /*Q31 */ - +#ifdef BASOP_NOGLOB + L_tmp_res = L_shl_sat( L_tmp_res, tmp_shift ); /*Q31 */ +#else + L_tmp_res = L_shl( L_tmp_res, tmp_shift ); /*Q31 */ +#endif if (tmp_sign != 0) { L_tmp_res = L_negate(L_tmp_res); /*Q31 */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 82b7aed38..808dbfef7 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -1418,7 +1418,11 @@ void SWB_BWE_decoding_fx( L_tmp = L_deposit_h(tmp); L_tmp = Isqrt_lc(L_tmp, &exp); - fenvL_16 = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ +#ifdef BASOP_NOGLOB + fenvL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ +#else + fenvL_16 = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ +#endif } #ifdef BASOP_NOGLOB IF( GT_16( fenvL_16, shl_sat( SWB_fenv[0], 5 ) ) ) diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 44852d268..bdce2a896 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -2012,8 +2012,11 @@ void pz_filter_sp_fx ( Lacc = L_deposit_h( x[i] ); /* Lacc in Q(16+Qn)*/ Lacc = L_shl( Lacc, s ); /* Lacc=x[i] in Q(16+Qn-2Qa+1)*/ FOR ( j = PDR - 1; j >= 0; j-- ) +#ifdef BASOP_NOGLOB + Lacc = L_msu_sat( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ +#else Lacc = L_msu( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ - +#endif Lacc = L_shr( Lacc, 1 ); diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index 4bf6c098e..ce1f1b908 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -261,8 +261,12 @@ static void gain_dec_gacelp_uv( /* g_code2 = pred_nrg_frame * norm_code2; */ L_tmp = Mpy_32_16_1(pred_nrg_frame, norm_code2); /* 18Q13 */ i = norm_l(L_tmp); - g_code2 = round_fx(L_shl(L_tmp, i)); - exp_gcode2 = sub(18, i); +#ifdef BASOP_NOGLOB + g_code2 = round_fx_sat( L_shl_sat( L_tmp, i ) ); +#else + g_code2 = round_fx( L_shl( L_tmp, i ) ); +#endif + exp_gcode2 = sub( 18, i ); /*-----------------------------------------------------------------* * Decode pitch gain diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 9338482cc..dadc23390 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -1409,7 +1409,11 @@ void wb_tbe_dec_fx( 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) */ +#ifdef BASOP_NOGLOB + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ +#else shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ +#endif } 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) */ diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index dfdfda24e..e18463c2e 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -1216,8 +1216,11 @@ static Word16 Find_Opt_gainQ_fx( g_code = *p++; /* selected code gain in Q9 */ move16(); L_tmp = L_mult(g_code, gcode0); /* Q9*Q0 -> Q10 */ - L_tmp = L_shl(L_tmp, add(exp_gcode0, 6)); /* Q10 -> Q16 */ - +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16 */ +#else + L_tmp = L_shl( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16 */ +#endif *gain_code = L_tmp; /* gain of code in Q16 */ move16(); return index; } diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index 75422d569..04d66ceb3 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -474,9 +474,13 @@ void hvq_classifier_fx( L_pe = L_add(L_pe, L_tmp); /*Q12 */ } - L_nf_mean[i] = L_add(L_nf_mean[i], L_nf); +#ifdef BASOP_NOGLOB + L_nf_mean[i] = L_add_sat( L_nf_mean[i], L_nf ); + L_pe_mean[i] = L_add_sat(L_pe_mean[i], L_pe); +#else + L_nf_mean[i] = L_add( L_nf_mean[i], L_nf ); L_pe_mean[i] = L_add(L_pe_mean[i], L_pe); - +#endif IF ( GT_32(L_d, L_peak)) { L_peak = L_add(L_d, 0); diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index 5115bae43..acb653c74 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -506,11 +506,18 @@ void nelp_encoder_fx( L_tmp = L_deposit_h(tmp1); L_tmp = Isqrt_lc(L_tmp, &exp1); L_tmp = Mult_32_16(L_tmp, sqrt_inv_lframe_lag); - Ltemp = L_shl(L_tmp, sub(exp1, 12)); +#ifdef BASOP_NOGLOB + Ltemp = L_shl_sat( L_tmp, sub( exp1, 12 ) ); +#else + Ltemp = L_shl( L_tmp, sub( exp1, 12 ) ); +#endif } - Gains_fx[i] = round_fx(Ltemp); - +#ifdef BASOP_NOGLOB + Gains_fx[i] = round_fx_sat( Ltemp ); +#else + Gains_fx[i] = round_fx( Ltemp ); +#endif IF(EQ_16(reduce_gains, 1)) { FOR(i = 0; i < 10; i++) @@ -624,8 +631,14 @@ void nelp_encoder_fx( IF(e_Noise > 0) { - L_tmp = L_shl(etmp, e_Noise); /* Result in Q30 */ - L_tmp = L_add(1, L_tmp); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( etmp, e_Noise ); /* Result in Q30 */ + L_tmp = L_add_sat( 1, L_tmp ); +#else + L_tmp = L_shl( etmp, e_Noise ); /* Result in Q30 */ + L_tmp = L_add( 1, L_tmp ); +#endif + exp1 = norm_l(L_tmp); tmp1 = extract_h(L_shl(L_tmp, exp1));/*exp1-16 */ diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index d244708cc..11d369501 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -2707,7 +2707,11 @@ static Word16 decision_hq_generic_class_fx_32 ( { p_fx = L_add(L_tmp, 0);/*6 */ } - a_fx = L_add(a_fx, L_tmp);/*6 */ +#ifdef BASOP_NOGLOB + a_fx = L_add_sat( a_fx, L_tmp ); /*6 */ +#else + a_fx = L_add( a_fx, L_tmp ); /*6 */ +#endif } IF (a_fx > 0) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index e18647af7..0f7d10575 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -890,7 +890,11 @@ void wb_tbe_enc_fx( 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) */ +#ifdef BASOP_NOGLOB + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ +#else shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ +#endif } Lscale = root_a_fx( Lscale, 31 - exp, &exp ); @@ -1491,7 +1495,11 @@ void swb_tbe_enc_fx( FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++) { /* shbEner = shbEner + in[i] * in[i] */ - shb_ener_sf_Q31 = L_mac0(shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i]); +#ifdef BASOP_NOGLOB + shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); +#else + shb_ener_sf_Q31 = L_mac0( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); +#endif /* o: shb_ener_sf_Q31 in (2*Q_shb) */ } shb_ener_sf_Q31= Mult_32_16(shb_ener_sf_Q31, 102/*0.003125f Q15*/); diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index bd6e31cf0..e7d2ea4bb 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -263,7 +263,11 @@ void AnalyzePowerSpectrum_fx( tmp = round_fx(L_shl(mdctSpectrum[i], s1)); tmp32 = L_mult0(tmp, tmp); - tmp = round_fx(L_shl(powerSpec[i], s2)); +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( powerSpec[i], s2 ) ); +#else + tmp = round_fx( L_shl( powerSpec[i], s2 ) ); +#endif tmp32 = L_mac0(tmp32, tmp, tmp); powerSpec[i] = tmp32; @@ -901,7 +905,11 @@ Word16 tcx_scalar_quantization_rateloop_fx( /* convert to normalized 16 bit */ tmp = norm_l(tmp32); - sqGain = round_fx(L_shl(tmp32, tmp)); +#ifdef BASOP_NOGLOB + sqGain = round_fx_sat( L_shl_sat( tmp32, tmp ) ); +#else + sqGain = round_fx( L_shl( tmp32, tmp ) ); +#endif sqGain_e = sub(sqGain_e, tmp); /* divide */ diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index cddd8ff75..a50ea1557 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -232,7 +232,11 @@ Word16 DetectTnsFilt_fx(STnsConfig const * pTnsConfig, L_tmp = L_deposit_l(0); FOR (i = 0; i < n; i++) { - L_tmp = L_mac0(L_tmp, tmpbuf[i], tmpbuf[i+lag]); +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, tmpbuf[i], tmpbuf[i + lag] ); +#else + L_tmp = L_mac0( L_tmp, tmpbuf[i], tmpbuf[i + lag] ); +#endif } if (lag != 0) L_tmp = Mpy_32_16_1(L_tmp, *pWindow++); -- GitLab From 85a2f73fb141ff8084537745130362f14ff3d23c Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 7 Mar 2024 13:40:26 -0500 Subject: [PATCH 05/11] more fixes for hi-level content --- lib_com/swb_tbe_com_fx.c | 7 +++++-- lib_com/tns_base.c | 7 ++++++- lib_com/trans_inv_fx.c | 6 +++++- lib_dec/gain_dec_fx.c | 6 +++++- lib_dec/swb_tbe_dec_fx.c | 7 +++++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 91267d3cd..1d39003e5 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -2225,8 +2225,11 @@ void GenShapedSHBExcitation_fx( #endif { L_tmp = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &exp); - scale = round_fx(L_shl(L_tmp, exp)); /*Q15 */ - +#ifdef BASOP_NOGLOB + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ +#else + scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ +#endif FOR(k = 0; k < L_FRAME16k; k++) { /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 200bf1a78..6806b4b0e 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -395,7 +395,12 @@ Word16 ITF_Detect_fx( L_tmp = L_shl(L_tmp, sub(shift, tmp)); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ - facs[iSubdivisions] = div_s(0x2000, round_fx(L_tmp)); /* L_tmp is >= 0x2000000 */ move16(); +#ifdef BASOP_NOGLOB + facs[iSubdivisions] = div_s( 0x2000, round_fx_sat( L_tmp ) ); /* L_tmp is >= 0x2000000 */ +#else + facs[iSubdivisions] = div_s( 0x2000, round_fx( L_tmp ) ); /* L_tmp is >= 0x2000000 */ +#endif + move16(); } } diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index c006f6824..67fc70bfe 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -694,7 +694,11 @@ void preecho_sb_fx( { tmp_fx1 = shr(*ptr_fx, qtmp); /* q-1, to have same shift as es_mdct_.. */ - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); +#ifdef BASOP_NOGLOB + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); +#else + tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); +#endif ptr_fx++; } if( GT_32(tmp_fxL1, max_plus_es_mdct_fx)) diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 1c6d3b0bb..360d05a87 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -664,7 +664,11 @@ void gain_dec_lbr_fx( move16(); L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); +#endif move16(); /* Q10 -> Q16*/ gc_mem[1] = *gain_code_fx; diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index dadc23390..662b9ff9c 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -2872,8 +2872,11 @@ void swb_tbe_dec_fx( L_tmp1 = Mult_32_16(ener_tmp[i], GainShape_tmp[i]); /* (2*Q_bwe_exc) */ L_tmp2 = Mult_32_16(hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx); /* (2*st_fx->prev_ener_fx_Q) */ tmp = sub(shl(Q_bwe_exc, 1), shl(st_fx->prev_ener_fx_Q, 1)); - L_tmp2 = L_shl(L_tmp2, tmp); /* new Q = (2*Q_bwe_exc) */ - +#ifdef BASOP_NOGLOB + L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ +#else + L_tmp2 = L_shl( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ +#endif IF (GT_32(L_tmp1,L_tmp2)) { /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ -- GitLab From f7dbc3209b4aeea319100282871df3ce1f0efe83 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 7 Mar 2024 14:42:36 -0500 Subject: [PATCH 06/11] more fixes for hi-level content --- lib_com/pvq_com_fx.c | 2 +- lib_enc/enc_acelpx_fx.c | 6 +++++- lib_enc/igf_enc_fx.c | 6 +++++- lib_enc/set_impulse_fx.c | 13 +++++++++++-- lib_enc/swb_bwe_enc_fx.c | 12 ++++++++++-- lib_enc/swb_tbe_enc_fx.c | 6 +++++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 05d86c074..3fd4f8800 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -526,7 +526,7 @@ void fine_gain_quant_fx( L_tmp = L_Comp(tmp1, exp2); Mpy_32_16_ss(L_tmp, 24660, &L_tmp, &lsb); /* 24660 = 20*log10(2) in Q12 */ /*16+12-15=13 */ #ifdef BASOP_NOGLOB - gain_db = round_fx(L_shl_o(L_tmp, 17, &Overflow)); + gain_db = round_fx_sat(L_shl_o(L_tmp, 17, &Overflow)); #else /* BASOP_NOGLOB */ gain_db = round_fx(L_shl(L_tmp, 17)); #endif diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index 075b078ba..b7e8fbb21 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -153,7 +153,11 @@ static void E_ACELP_2pulse_searchx( move16(); /*alp0 = *alp + 2.0f*R[0]; move16();*/ alp0 = L_deposit_h(*alp); /* Qalp = Q_R*Q_signval */ - alp0 = L_mac(alp0, R[0], sign_val_2); +#ifdef BASOP_NOGLOB + alp0 = L_mac_sat( alp0, R[0], sign_val_2 ); +#else + alp0 = L_mac( alp0, R[0], sign_val_2 ); +#endif /* Ensure that in the loop below s > 0 in the first iteration, the actual values do not matter. */ sqk[0] = -1; diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 1efb50d02..7f0cd9bdf 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -741,7 +741,11 @@ static Word16 IGF_getSFM( /*Transform to Q15*/ s = norm_l(SFM32); - SFM = round_fx(L_shl(SFM32, s)); +#ifdef BASOP_NOGLOB + SFM = round_fx_sat( L_shl_sat( SFM32, s ) ); +#else + SFM = round_fx( L_shl( SFM32, s ) ); +#endif *SFM_exp = sub(*SFM_exp, s); /**SFM_exp = s_min(*SFM_exp, 0);*/ diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index adbb356d5..ad603ae7e 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -376,8 +376,17 @@ static void correlate_tc_fx( s = L_deposit_l(0); FOR (j = i; j < L_1; j++) { - s = L_mac(s, x[j],h[j-i]); +#ifdef BASOP_NOGLOB + s = L_mac_sat( s, x[j], h[j - i] ); +#else + s = L_mac( s, x[j], h[j - i] ); +#endif } - y[i] = round_fx(s); +#ifdef BASOP_NOGLOB + y[i] = round_fx_sat( s ); +#else + y[i] = round_fx( s ); +#endif } + } diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 11d369501..25f911ab3 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -1047,7 +1047,11 @@ static void vqWithCand_w_fx( FOR( i = 0; i < E_ROM_dico_size; i++ ) { - dist = sub(x[0],*p_E_ROM_dico++);/*Q8 */ +#ifdef BASOP_NOGLOB + dist = sub_sat( x[0], *p_E_ROM_dico++ ); /*Q8 */ +#else + dist = sub( x[0], *p_E_ROM_dico++ ); /*Q8 */ +#endif L_dist = L_mult(dist,dist);/*Q17 */ L_dist = L_shr(L_dist,12);/*Q5 */ @@ -2702,7 +2706,11 @@ static Word16 decision_hq_generic_class_fx_32 ( exp = norm_l(coefs_fx[i]); tmp = extract_h(L_shl(coefs_fx[i], exp));/*12 + exp - 16 */ L_tmp = L_mult0(tmp, tmp);/*2 * exp - 8 */ - L_tmp = L_shl(L_tmp, sub(14, shl(exp, 1)));/*6 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, sub( 14, shl( exp, 1 ) ) ); /*6 */ +#else + L_tmp = L_shl( L_tmp, sub( 14, shl( exp, 1 ) ) ); /*6 */ +#endif IF (GT_32(L_tmp , p_fx)) { p_fx = L_add(L_tmp, 0);/*6 */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 0f7d10575..af51961b6 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1592,7 +1592,11 @@ void swb_tbe_enc_fx( FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { - bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); +#ifdef BASOP_NOGLOB + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); +#else + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); +#endif } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); -- GitLab From 14807b0410cb922736b7310f20db98c887b2eee3 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 7 Mar 2024 21:02:26 -0500 Subject: [PATCH 07/11] more fixes for hi-level content --- lib_dec/swb_tbe_dec_fx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 662b9ff9c..05a0fbe2f 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -2888,7 +2888,11 @@ void swb_tbe_dec_fx( } expb = norm_l(L_tmp); - fracb = round_fx(L_shl(L_tmp,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) ); +#else + fracb = round_fx( L_shl( L_tmp, expb ) ); +#endif expb = 30-expb; /* - (2*Q_bwe_exc_ext); */ expa = norm_l(ener_tmp[i]); -- GitLab From f42d02d3aa0f6a79d2e9b96d701c1c15a28398c0 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 7 Mar 2024 21:15:54 -0500 Subject: [PATCH 08/11] un-comment code commented by accident --- lib_dec/init_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index d18850334..cfdf40c98 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -627,7 +627,7 @@ ivas_error init_decoder_fx( } /* HF synth init */ - //hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); + hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); -- GitLab From da3bd7a852defef3bb84128657e414cda6809192 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 08:42:15 -0500 Subject: [PATCH 09/11] Basop fix for Hi-level content FEC --- lib_com/gs_preech.c | 6 +++++- lib_dec/FEC_HQ_core_fx.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index 8ed594444..324c7562a 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -186,7 +186,11 @@ void pre_echo_att_fx( etmp_fx = L_shr(etmp_fx, add(2 + 1 - 4, shl(Q_new, 1)));/*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */ etmp1_fx = etmp_fx; move32(); - *Last_frame_ener_fx = L_shl(*Last_frame_ener_fx, 2); +#ifdef BASOP_NOGLOB + *Last_frame_ener_fx = L_shl_sat( *Last_frame_ener_fx, 2 ); +#else + *Last_frame_ener_fx = L_shl( *Last_frame_ener_fx, 2 ); +#endif move32(); /*2*Q_new+1 */ /* If the maximum normalized energy > last frame energy + 6dB */ diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index d1493f8b9..61620e003 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -1008,8 +1008,13 @@ static Word16 find_best_delay_fx( accB_fx = L_deposit_l(0); FOR ( i = 0; i < lin; i += delta ) { - accA_fx = L_add(accA_fx, L_shr(L_mult(mu_o_fx[d1+i], mu_o_fx[d1+i]),2)); +#ifdef BASOP_NOGLOB + accA_fx = L_add_sat( accA_fx, L_shr( L_mult_sat( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); + accB_fx = L_add_sat(accB_fx, L_shr(L_mult_sat(mu_o_fx[d1+i], in_fx[i]),2)); +#else + accA_fx = L_add( accA_fx, L_shr( L_mult( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); accB_fx = L_add(accB_fx, L_shr(L_mult(mu_o_fx[d1+i], in_fx[i]),2)); +#endif } Rxy_fx[k] = accB_fx; @@ -1262,7 +1267,11 @@ static Word16 FEC_phase_matching_fx( tmp = shl(tmp, sub(sub(exp2, exp1), 1));/*14*/ FOR (i = N_ZERO_NB; i < 2*L; i++) { - ImdctOutWin_fx[i] = shl(mult(ImdctOutWin_fx[i], tmp), 1); +#ifdef BASOP_NOGLOB + ImdctOutWin_fx[i] = shl_sat( mult( ImdctOutWin_fx[i], tmp ), 1 ); +#else + ImdctOutWin_fx[i] = shl( mult( ImdctOutWin_fx[i], tmp ), 1 ); +#endif } } Smoothing_vector_NB_fx(OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB], SmoothingWin_NB2_fx, auOut_fx, ol_size); -- GitLab From fd2e4320dc6713ad0f35712d7c91e1c1703412c6 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 09:24:20 -0500 Subject: [PATCH 10/11] Basop fix for Hi-level content FEC --- lib_com/fft_fx_evs.c | 11 ++++++++++- lib_dec/FEC_HQ_phase_ecu_fx.c | 13 ++++++++++--- lib_dec/FEC_scale_syn_fx.c | 6 +++++- lib_dec/dec_gen_voic_fx.c | 7 ++++++- lib_dec/tonalMDCTconcealment_fx.c | 6 +++++- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index 2e11c96c0..b6ed50554 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -3341,12 +3341,21 @@ void ifft3_fx(const Word16 Z[], Word16 X[], const Word16 n) pX = X; FOR (i = 0; i < m; i++) { - *pX++ = shl(mult_r(*y0++, FFT3_ONE_THIRD), 1); +#ifdef BASOP_NOGLOB + *pX++ = shl_sat( mult_r( *y0++, FFT3_ONE_THIRD ), 1 ); + move16(); + *pX++ = shl_sat( mult_r( *y1++, FFT3_ONE_THIRD ), 1 ); + move16(); + *pX++ = shl_sat( mult_r( *y2++, FFT3_ONE_THIRD ), 1 ); + move16(); +#else + *pX++ = shl( mult_r( *y0++, FFT3_ONE_THIRD ), 1 ); move16(); *pX++ = shl(mult_r(*y1++, FFT3_ONE_THIRD), 1); move16(); *pX++ = shl(mult_r(*y2++, FFT3_ONE_THIRD), 1); move16(); +#endif } return; diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 128d0db6a..08c2955f2 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -3319,7 +3319,11 @@ void fir_dwn_fx( FOR (j = 1; j <= i; j++) { - s = L_mac0(s, *ptr_h++, *ptr_x--); +#ifdef BASOP_NOGLOB + s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); +#else + s = L_mac0( s, *ptr_h++, *ptr_x-- ); +#endif } #ifdef BASOP_NOGLOB @@ -3633,8 +3637,11 @@ void sin_cos_est_fx(Word32 phi, Word16 *cosfreq, Word16 *sinfreq) tmp = L_shl(Mult_32_16(delta, cosb),1); /*Q31 */ sinv = L_add(L_deposit_h(sinb), tmp); tmp = L_shl(Mult_32_16(delta, sinb),1); /*Q31 */ - cosv = L_sub(L_deposit_h(cosb), tmp); - +#ifdef BASOP_NOGLOB + cosv = L_sub_sat( L_deposit_h( cosb ), tmp ); +#else + cosv = L_sub( L_deposit_h( cosb ), tmp ); +#endif #ifdef BASOP_NOGLOB *sinfreq = round_fx_sat(sinv); *cosfreq = round_fx_sat(cosv); diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index df9c7c5b2..0e45ca98d 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -379,7 +379,11 @@ void FEC_scale_syn_fx( /*rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.1f;*/ /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ /*tilt = rr1 / rr0;*/ - tilt = extract_h(L_shl(get_gain(h1+1, h1, L_FRAME/2-1),15)); +#ifdef BASOP_NOGLOB + tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); +#else + tilt = extract_h( L_shl( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); +#endif test(); test(); test(); diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index a86895941..d32daf514 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -317,8 +317,13 @@ ivas_error decod_gen_voic_fx( prev_spch_nrg = L_deposit_l(1); FOR( i=0; iprev_Q_exc_fr */ +#ifdef BASOP_NOGLOB + prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */ + prev_spch_nrg = L_mac0_sat(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */ +#else + prev_res_nrg = L_mac0( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */ prev_spch_nrg = L_mac0(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */ +#endif p_exc++; p_syn++; } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 373b83108..18f61e15a 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -854,7 +854,11 @@ PMTE() #endif FOR (i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++) { - powerSpectrum[i] = L_shl(Mpy_32_16_1(powerSpectrum[i], invScaleFactors[FDNS_NPTS-1]), invScaleFactors_exp[FDNS_NPTS-1]); +#ifdef BASOP_NOGLOB + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); +#else + powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); +#endif move32(); } -- GitLab From 8ac987e3bdce35cd4d7e05682feb8df095503d75 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 8 Mar 2024 09:43:53 -0500 Subject: [PATCH 11/11] Merge branch 'main' into VA_basop_no_glob_hi_level --- lib_enc/cng_enc_fx.c | 3158 +++++++++++++++++++++--------------------- 1 file changed, 1579 insertions(+), 1579 deletions(-) diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 71035252d..e18b66d00 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1,1579 +1,1579 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ -#include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -//#include "basop_mpy.h" - -#include -/*---------------------------------------------------------------------* -* Local constants -*---------------------------------------------------------------------*/ - -#define MAX_DELTA 1 -#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ -#define INT_H 50 -#define INT_L 8 - -/*---------------------------------------------------------------------* - * Local function prototypes - *---------------------------------------------------------------------*/ -static void shb_CNG_encod_fx(Encoder_State_fx *st_fx, const Word16 update_fx ); -static Word16 shb_DTX_fx(Encoder_State_fx *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); -/*---------------------------------------------------------------------* -* CNG_enc() -* -* Confort noise generation for the coder -*---------------------------------------------------------------------*/ -void CNG_enc_fx( - Encoder_State_fx *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_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) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 Q_new, /* i : Q value of speech */ - Word32 *q_env, - Word16 *sid_bw -) -{ - Word16 enr_index; - Word16 i, j, ptr; - Word16 m1; - Word16 res[L_FRAME16k]; - Word16 step_inv=0; - Word16 hi, lo; - Word16 maxl=0; - Word16 num_bits=0; - Word16 step=0; - Word16 *pt_res; - const Word16 *pt_sp; - Word16 enr; - Word32 L_tmp, L_ener; - Word16 k, tmp1; - Word16 weights; - Word16 sp_enr; - Word32 L_tmp1; - Word16 exp; - Word16 m = 0; - Word16 tmp[HO_HIST_SIZE*M]; - Word16 ll, s_ptr; - Word16 tmpv, maxv, scale, att = 1; - Word16 lsf_tmp[M]; - Word32 C[M]; - Word32 max_val[2]; - Word16 max_idx[2]; - Word16 ftmp_fx; - Word16 lsp_tmp[M]; - Word16 dev; - Word16 max_dev; - Word16 dist; - Word16 max_idx1[2]= {0,0}; - Word16 fft_io[L_FRAME16k]; - Word16 *ptR,*ptI; - Word32 enr1=0; - Word32 env[NUM_ENV_CNG]; - Word32 min1; - Word16 min1_idx; - Word32 d; - Word16 res1[L_FRAME16k]; - Word32 tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 fra; - Word16 temp_lo_fx, temp_hi_fx; - Word16 exp_pow; - Word16 force_cn_step=0; - Word16 tmp_loop; - Word16 st_lp_sp_enr; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; - Word16 lp_ener_thr_scale; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif - /* Temp variables for floating point functions */ - - lp_ener_thr_scale = 8; /* 4.0f*/ /*IVAS_CODE Q2 */ - move16(); - if (NE_16(st_fx->element_mode, EVS_MONO)) - { - lp_ener_thr_scale = 7; /* 3.5f;*/ - move16(); - } - /*sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f);*//*9.1 */ - 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_fx, 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 (i=0; i<2; i++) - { - 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 */ - } - } - } - - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(29, hi); /* log2 exp in Q2*Q_new */ - hi = sub(hi, shl(Q_new, 1)); /* Q0 */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - sp_enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ - - if (sp_enr < 0) - { - sp_enr = 0; - move16(); - } - test(); - IF (hDtxEnc->first_CNG == 0 || hTdCngEnc->old_enr_index < 0 ) - { - hTdCngEnc->lp_sp_enr_fx = sp_enr; - move16(); /* Q8 */ - } - ELSE - { - test(); - test(); - test(); - test(); - IF( GT_32(st_fx->last_core_brate_fx, SID_2k40) && ( EQ_16( st_fx->last_core_fx, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && - GT_16(sub(sp_enr, hTdCngEnc->lp_sp_enr_fx), 1024) && GT_16(sp_enr, 1536) ) - { - hTdCngEnc->lp_sp_enr_fx = sp_enr; - move16(); - force_cn_step = 1; - move16(); - } - ELSE - { - hTdCngEnc->lp_sp_enr_fx = round_fx(L_mac(L_mult(29491 /* 0.9, Q15 */,hTdCngEnc->lp_sp_enr_fx), 3277 /* 0.1, Q15 */,sp_enr)); /* Q8 (8+15+1-16) */ - } - } - /* update the pointer to circular buffer of old LSP vectors */ - hTdCngEnc->cng_hist_ptr = add(hTdCngEnc->cng_hist_ptr,1); - if(EQ_16(hTdCngEnc->cng_hist_ptr, DTX_HIST_SIZE)) - { - hTdCngEnc->cng_hist_ptr = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(hTdCngEnc->cng_lsp_hist_fx[(hTdCngEnc->cng_hist_ptr)*M]), M ); - - /*-----------------------------------------------------------------* - * Find CNG spectral envelope - * Find LSP median - *-----------------------------------------------------------------*/ - test(); - test(); - IF( (EQ_32(st_fx->core_brate_fx, SID_2k40) || EQ_32(st_fx->core_brate_fx,SID_1k75)) && GE_16(hDtxEnc->cng_cnt,sub(hDtxEnc->cng_hist_size,1))) - { - set32_fx( max_val, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i=0; i< hDtxEnc->cng_hist_size; i++ ) - { - IF ( EQ_16(st_fx->L_frame_fx,L_FRAME)) - { - lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16();/*QX2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - ELSE - { - lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; - move16();/*QX2.56 */ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ - FOR ( j=0; jcng_hist_size; j++ ) - { - L_tmp = L_add(L_tmp,L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[j*M+i])); /*Q15 */ - } - - L_tmp = L_sub(L_tmp,L_add(L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[0]*M+i]),L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[1]*M+i]))); /*Q15 */ - tmpv= div_s(1,sub(hDtxEnc->cng_hist_size,2)); /*Q15 */ - L_tmp = Mpy_32_16_1(L_tmp,tmpv); /*Q15 */ - lsp_new[i] = extract_l(L_tmp); /*Q15 */ - } - max_idx1[0] = max_idx[0]; - move16(); - max_idx1[1] = max_idx[1]; - move16(); - } - - /*-----------------------------------------------------------------* - * Quantize CNG spectral envelope (only in SID frame) - * Quantize the LSF vector - *-----------------------------------------------------------------*/ - *allow_cn_step = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ((hDtxEnc->cng_cnt == 0) && - GT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && - (LT_16(add(st_lp_sp_enr, 1024 /* 4.0, Q8 */), sp_enr)) && - (hDtxEnc->first_CNG != 0) && - (hTdCngEnc->old_enr_index >= 0) && - (GT_32(st_fx->last_core_brate_fx, SID_2k40))) || - EQ_16(force_cn_step, 1)) - { - *allow_cn_step = 1; - move16(); - } - - /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF(hDtxEnc->first_CNG == 0) - { - Copy(st_fx->lsp_old_fx, hDtxEnc->lspCNG_fx, M); - - /* Average the CNG spectral envelope in case of the very first CNG frame */ - IF (NE_16(st_fx->element_mode, EVS_MONO)) - { - FOR (i = 0; i < M; i++) - { - /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ - lsp_new[i] = mac_r(L_mult(lsp_mid[i], 16384), lsp_new[i], 16384); - move16(); - } - } - } - - - test(); - IF( EQ_32(st_fx->core_brate_fx, SID_2k40) || EQ_32(st_fx->core_brate_fx,SID_1k75)) - { - /* LSF quantization */ - IF ( st_fx->Opt_AMR_WB_fx != 0 ) - { - isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0); - } - ELSE - { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - lsf_enc_fx(st_fx, lsf_new, lsp_new, NULL, NULL, 100, 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(); - if ( EQ_16(st_fx->bwidth_fx,WB) && hDtxEnc->first_CNG!=0 && NE_16(st_fx->L_frame_fx, hDtxEnc->last_CNG_L_frame)) - { - hTdCngEnc->ho_hist_size = 0; - move16(); - } - } - ELSE - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); - Copy( st_fx->lsf_old_fx, lsf_new, M ); - } - - /*---------------------------------------------------------------------* - * CNG spectral envelope update - * Find A(z) coefficients - *---------------------------------------------------------------------*/ - - IF( LE_32(st_fx->last_core_brate_fx, SID_2k40)) - { - /* Reset hangover counter if not first SID period */ - if( GT_32(st_fx->core_brate_fx,FRAME_NO_DATA)) - { - hTdCngEnc->num_ho = 0; - move16(); - } - /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ - test(); - IF( LT_16(hTdCngEnc->num_ho,3) || LT_32(Mult_32_16(hTdCngEnc->Enew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) - { - FOR( i=0; ilspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i]),32768-CNG_ISF_FACT_FX,lsp_new[i]); - move16(); /* Q15 (15+15+1-16) */ - } - } - } - ELSE - { - /* Update CNG_mode if allowed */ - test(); - test(); - test(); - IF( EQ_16(st_fx->element_mode, EVS_MONO) && (( st_fx->Opt_AMR_WB_fx || EQ_16(st_fx->bwidth_fx,WB)) - && ( !hDtxEnc->first_CNG || GE_16(hTdCngEnc->act_cnt2,MIN_ACT_CNG_UPD) ) ) ) - { - IF (GT_32(hDtxEnc->last_active_brate, ACELP_16k40)) - { - hDtxEnc->CNG_mode = -1; - move16(); - } - ELSE - { - hDtxEnc->CNG_mode = get_cng_mode(hDtxEnc->last_active_brate); - } - } - - /* If first sid after active burst update LSF history from circ buffer */ - hTdCngEnc->burst_ho_cnt = s_min(hTdCngEnc->burst_ho_cnt, hTdCngEnc->ho_circ_size); - hTdCngEnc->act_cnt = 0; - move16(); - s_ptr = add(sub(hTdCngEnc->ho_circ_ptr, hTdCngEnc->burst_ho_cnt),1); - - if( s_ptr < 0 ) - { - s_ptr = add(s_ptr, hTdCngEnc->ho_circ_size); - } - - FOR( ll = hTdCngEnc->burst_ho_cnt; ll > 0; ll-- ) - { - hTdCngEnc->ho_hist_ptr = add(hTdCngEnc->ho_hist_ptr,1); - if( EQ_16(hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE)) - { - hTdCngEnc->ho_hist_ptr = 0; - move16(); - } - - /* Conversion between 12.8k and 16k LSPs */ - test(); - test(); - IF( EQ_16(st_fx->L_frame_fx,L_FRAME )&&EQ_16(hTdCngEnc->ho_16k_lsp[s_ptr],1)) - { - /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), st_fx->L_frame_fx, 0 ); - } - ELSE IF ( EQ_16(st_fx->L_frame_fx,L_FRAME16k)&& hTdCngEnc->ho_16k_lsp[s_ptr]==0) - { - /* 16k LSPs already converted and stored, just copy to the other buffer */ - Copy(&(hTdCngEnc->ho_lsp_circ2_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), M ); - } - /* update the circular buffers */ - Copy(&(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_hist_fx[hTdCngEnc->ho_hist_ptr*M]), M ); - Copy32(&(hTdCngEnc->ho_ener_circ_fx[s_ptr]), &(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr]), 1 ); - hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - Copy32(&(hTdCngEnc->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(hTdCngEnc->ho_env_hist_fx[hTdCngEnc->ho_hist_ptr*NUM_ENV_CNG]), NUM_ENV_CNG ); - - hTdCngEnc->ho_hist_size = add(hTdCngEnc->ho_hist_size,1); - if (GT_16(hTdCngEnc->ho_hist_size, HO_HIST_SIZE)) - { - hTdCngEnc->ho_hist_size = HO_HIST_SIZE; - move16(); - } - - s_ptr = add(s_ptr,1); - - if( EQ_16(s_ptr, hTdCngEnc->ho_circ_size)) - { - s_ptr = 0; - move16(); - } - } - - IF(hTdCngEnc->burst_ho_cnt > 0) - { - /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ -#if 1 - /*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)); - } /*fenew = dotp( fexc, fexc, pit_max )/pit_max;*/ - L_tmp1 = L_sub(L_tmp1, hTdCngEnc->lp_ener_fx); -#else - L_tmp1 = L_shr(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr],2); - L_tmp1 = L_sub(L_tmp1,hTdCngEnc->lp_ener_fx); -#endif - test();test(); - IF((hDtxEnc->first_CNG > 0 || EQ_16(st_fx->element_mode, EVS_MONO)) && L_tmp1>0) - { - *allow_cn_step = s_or(*allow_cn_step,1); - } - } - test(); - IF ( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) - { - /* Use average of energies below last energy */ - ptr = hTdCngEnc->ho_hist_ptr; - move16(); - Copy( &(hTdCngEnc->ho_lsp_hist_fx[ptr*M]), tmp, M ); - m1 = 0; - move16(); - IF( L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x1) == 0 ) - { - Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); - m1 = 1; - move16(); - } - L_enr = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ - - weights = W_DTX_HO_FX[0]; /* Q15 */ - - m = 1; - move16(); - FOR( k=1; kho_hist_size; k++ ) - { - ptr = sub(ptr,1); - if( ptr < 0 ) - { - ptr = HO_HIST_SIZE - 1; - move16(); - } - - test(); - IF ( LT_32(Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr])&& - GT_32(hTdCngEnc->ho_ener_hist_fx[ptr],Mult_32_16(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], BUF_L_NRG_FX)) ) - { - /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr]; */ - L_tmp1 = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ - L_enr = L_add(L_enr,L_tmp1); /* Q6 */ - - /*weights += W_DTX_HO[k]; */ - weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ - - Copy( &hTdCngEnc->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); - IF( L_and(hTdCngEnc->ho_sid_bw, L_shl((Word32)0x1,k)) == 0 ) - { - Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); - m1 = add(m1,1); - } - m = add(m,1); - } - } - - /*enr /= weights; */ - exp = norm_s(weights); - tmp1 = div_s(shl(1,sub(14,exp)),weights); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16(L_enr,tmp1); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl(L_tmp1,add(exp,1)); /* Q6 */ - - hTdCngEnc->lp_ener_fx = L_enr; - move32();/* Q6 */ - - set32_fx( max_val, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i=0; iL_frame_fx,L_FRAME)) - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16();/*QX2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - ELSE - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; - move16();/*QX2.56 */ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ - FOR ( j=0; jlspCNG_fx[i] = lsp_tmp[i]; - move16(); /*Q15 */ - } - } - ELSE - { - FOR( i=0; ilspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); - move16(); - } - } - IF( m1 > 0 ) - { - FOR ( i=0; ilp_ener_fx; */ - IF(EQ_16(m1,1)) - { - L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); - } - ELSE - { - tmp1 = div_s(1,m1); - L_tmp = Mult_32_16(L_tmp,tmp1); - L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); - } - - env[i] = L_tmp; - move32(); - } - Copy32(env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG); - } - } - ELSE - { - Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ - } - } - IF ( st_fx->Opt_AMR_WB_fx != 0 ) - { - E_LPC_f_isp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); - } - ELSE - { - E_LPC_f_lsp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ - } - - tmp_loop = shr(st_fx->L_frame_fx,6); - FOR( i=1; iL_frame_fx, 0); - Copy(res, res1, st_fx->L_frame_fx); - test(); - IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) - { - //PMT("Code to be completed") -#ifdef IVAS_CODE - att = powf(10.0f, hTdCngEnc->CNG_att / 20.0f); - v_multc(res1, att, res1, st->L_frame); -#endif - } - ELSE IF( NE_16(st_fx->bwidth_fx,NB)) - { - test(); - IF( EQ_16(st_fx->bwidth_fx,WB) && hDtxEnc->CNG_mode>=0) - { - ftmp_fx = HO_ATT_FX[hDtxEnc->CNG_mode]; - } - ELSE - { - ftmp_fx = 19661; - move16(); - } - - att = mult(ftmp_fx,5461);/* Q15 */ - L_tmp = L_mult(att,8);/* Q16 */ - tmp1 = extract_l(L_shr(L_tmp,2));/* Q14 */ - tmp1 = add(16384,tmp1); - att = div_s(16374,tmp1); /* Q15 */ - - att = s_max(att, ftmp_fx); - FOR( i = 0; i < st_fx->L_frame_fx; i++ ) - { - /*res1[i] *= att;*/ - res1[i] = mult(res1[i],att); - move16();/* Q_new */ - } - att = shr(att,7);/* Q8 */ - } - - /* calculate the spectrum of residual signal */ - Copy(res1, fft_io, st_fx->L_frame_fx); - - IF ( EQ_16(st_fx->L_frame_fx,L_FRAME16k)) - { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx,0); - } - - fft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); - ptR = &fft_io[1]; - ptI = &fft_io[L_FFT-1]; - FOR ( i=0; icng_res_env_fx[(hTdCngEnc->cng_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); - - /* calculate the residual signal energy */ - /*enr = dotp( res, res, L_frame ) / L_frame; */ - maxv = 0; - move16(); - FOR(i = 0; i < st_fx->L_frame_fx; 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_fx, 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(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(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(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(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) */ - - /* update the circular buffer of old energies */ - hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; - move16(); /* Q8 */ - - /*-----------------------------------------------------------------* - * Quantize residual signal energy (only in SID frame) - *-----------------------------------------------------------------*/ - test(); - IF( EQ_32(st_fx->core_brate_fx, SID_2k40)||EQ_32(st_fx->core_brate_fx,SID_1k75)) - { - IF( GE_16(hDtxEnc->cng_cnt,sub(hDtxEnc->cng_hist_size,1))) - { - /* average the envelope except outliers */ - FOR ( i=0; icng_hist_size; j++ ) - { - L_tmp1 = L_add(L_tmp1,hTdCngEnc->cng_res_env_fx[j*NUM_ENV_CNG+i]); - } - L_tmp = L_add(hTdCngEnc->cng_res_env_fx[max_idx1[0]*NUM_ENV_CNG+i],hTdCngEnc->cng_res_env_fx[max_idx1[1]*NUM_ENV_CNG+i]); - L_tmp1 = L_sub(L_tmp1,L_tmp); - - /* env[i] /= (float)(st_fx->cng_hist_size - 2); */ - tmp1 = sub(hDtxEnc->cng_hist_size,2); - IF(GT_16(tmp1,1)) - { - tmp1 = div_s(1,tmp1); - L_tmp1 = Mult_32_16(L_tmp1,tmp1); - } - - env[i] = L_tmp1; - move32(); - } - /* compute average excitation energy */ - L_tmp = L_deposit_l(0); - ptr = hTdCngEnc->cng_hist_ptr; - move16(); - - FOR (k=0; k< hDtxEnc->cng_hist_size; k++) - { - /* enr += W_HIST[k]*cng_ener_hist[ptr] */ - L_tmp = L_mac0(L_tmp, W_HIST_FX[k], hTdCngEnc->cng_ener_hist_fx[ptr]); /* Q24 (8+16) */ - ptr = sub(ptr, 1); - if (ptr < 0) /* check for circular pointer */ - { - ptr = DTX_HIST_SIZE - 1; - move16(); - } - } - /*----------------------------------------------------------- - * here we want to divide L_tmp by the sum - * of all the coefs used W_HIST[0..cng_hist_size-1] - * The table W_HIST_S already contains the inverted sum. - * That is - * W_HIST_S[k] 1 - * ------------- = --------------------------- - * 4096 W_HIST[0] + ... + W_HIST[k] - * - * 1 / Sum(W_HIST[0..k]) is always > 1 since the sum - * of the coefs 0..k is always < 1 but > 0 - * enr is in Q8 since the history buffer constains Q8 energies - *-----------------------------------------------------------*/ - /*L_tmp = Mpy_32_16_1(L_tmp, W_HIST_S_FX[k-1]); */ /* normalize average value */ - L_tmp = Mult_32_16(L_tmp, W_HIST_S_FX[k-1]); /* Q21 (24+12+1-16) */ - L_tmp = L_shl(L_tmp, 3); /* Q24 */ - enr = round_fx(L_tmp); /* Q8 */ - } - /* decrease the energy in case of WB input */ - IF ( EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) - { - //PMT("CNG IVAS_SCE and IVAS_CPE_DFT code missing") - //IVAS_CODE - //enr += hTdCngEnc->CNG_att * FAC_LOG2 / 10.0f; - } - ELSE IF( NE_16(st_fx->bwidth_fx, NB)) - { - IF( EQ_16(st_fx->bwidth_fx,WB)) - { - IF(hDtxEnc->CNG_mode >= 0 ) - { - /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[hDtxEnc->CNG_mode]; - move16(); - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = ENR_ATT_fx[4]; - move16(); - } - } - ELSE - { - att = 384; - move16();/*Q8*/ - } - enr = sub(enr, att ); - } - /* intialize the energy quantization parameters */ - IF( st_fx->Opt_AMR_WB_fx == 0 ) - { - step = STEP_SID_FX; - move16(); - step_inv = ISTEP_SID_FX; - move16(); - maxl = 127; - move16(); - num_bits = 7; - move16(); - } - ELSE - { - step = STEP_AMR_WB_SID_FX; - move16(); - step_inv = ISTEP_AMR_WB_SID_FX; - move16(); - maxl = 63; - move16(); - num_bits = 6; - move16(); - } - - /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, step), 12+8)); /* Q0 (8+12-(8+12)) */ - - /* limit the energy quantization index */ - enr_index = s_min(enr_index, maxl); - enr_index = s_max(enr_index, 0); - - /* allow only slow energy increase */ - test(); - IF( hTdCngEnc->old_enr_index >= 0 && GT_16(enr_index, add(hTdCngEnc->old_enr_index, MAX_DELTA))) - { - IF( *allow_cn_step != 0 ) - { - tmp1 = mult(27853 /* Q15(0.85) */,sub(enr_index,hTdCngEnc->old_enr_index)); - enr_index = add(hTdCngEnc->old_enr_index,tmp1); - } - ELSE - { - enr_index = add(hTdCngEnc->old_enr_index, MAX_DELTA); - } - } - hTdCngEnc->old_enr_index = enr_index; - move16(); - - push_indice_fx( hBstr, IND_ENERGY, enr_index, num_bits ); - if ( enr_index == 0 ) - { - enr_index = -5; - move16(); - } - /* Find quantized energy */ - /* *Enew = (float)enr_index / step - 2.0 */ - /* *Enew = (float)pow(2.0, *Enew) */ - L_tmp = L_mult(enr_index, step_inv); /* Q16(0+15+1) */ - /* substract by 2 not done to leave Energy in Q2 */ - lo = L_Extract_lc(L_tmp, &hi); - hTdCngEnc->Enew_fx = Pow2(add(hi, 4), lo); /* Q6 */ - IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l(hTdCngEnc->Enew_fx); - L_tmp = L_shl(hTdCngEnc->Enew_fx,exp); /*Q(exp+6) */ - L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame_fx,5));/* Q(exp+6+5-15=exp-4) */ - -#ifdef BASOP_NOGLOB - L_tmp = L_shr_sat(L_tmp,sub(exp,10)); /* Q6 */ -#else - L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ -#endif - - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr1 = L_shr(L_tmp,10);/* Q6 */ - - FOR ( i=0; iEnew;*/ - L_tmp1 = L_add(env[i], 0); - L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); - L_tmp1 = L_sub(L_tmp1,L_tmp); /*Q6*/ - - IF ( L_tmp1 < 0 ) - { - L_tmp1 = L_deposit_l(6); /* (0.1)Q6 */ - } - /* env[i] = (float)log10( env[i] + 0.1f ) / (float)log10( 2.0f ); */ - exp = norm_l(L_tmp1); - fra = Log2_norm_lc(L_shl(L_tmp1,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - L_tmp1 = L_shr(L_tmp,10); /* Q6 */ - - L_tmp = L_shr(L_deposit_l(att),2);/* Q6 */ - L_tmp1 = L_sub(L_tmp1,L_tmp); - - IF ( L_tmp1 < 0 ) - { - L_tmp1 = L_deposit_l(0); - } - - L_tmp1 = L_sub(enr1,L_tmp1); - - env[i] = L_tmp1; - move32(); - } - - /* codebook search */ - min1 = L_add(1310588928, 0); /* Q17 */ - min1_idx = 0; - move16(); - - FOR ( i=0; i<64; i++ ) - { - d = L_deposit_l(0); - FOR ( j=0; jEnew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) - { - /* update the pointer to circular buffer of old LSP vectors */ - hTdCngEnc->ho_hist_ptr = add(hTdCngEnc->ho_hist_ptr, 1); - if( EQ_16(hTdCngEnc->ho_hist_ptr,HO_HIST_SIZE)) - { - hTdCngEnc->ho_hist_ptr = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(hTdCngEnc->ho_lsp_hist_fx[(hTdCngEnc->ho_hist_ptr)*M]), M ); - - /* update the hangover energy buffer */ - hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] = hTdCngEnc->Enew_fx; - move32(); - IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - FOR ( i=0; iEnew;*/ - L_tmp = L_sub(enr1,q_env[i]);/* Q6 */ - L_tmp = L_shl(L_tmp, 10);/* 16 */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ - env[i] = L_shl(L_tmp, sub(6, exp_pow)); - move32(); /* Q6 */ - L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); - env[i] = L_add(env[i],L_tmp); - move32();/* Q6 */ - } - Copy32( env, &(hTdCngEnc->ho_env_hist_fx[(hTdCngEnc->ho_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); - } - hTdCngEnc->ho_hist_size = add(hTdCngEnc->ho_hist_size,1); - if( GT_16(hTdCngEnc->ho_hist_size,HO_HIST_SIZE)) - { - hTdCngEnc->ho_hist_size = HO_HIST_SIZE; - move16(); - } - } - } - /* dithering bit for AMR-WB IO mode is always set to 0 */ - IF( EQ_32(st_fx->core_brate_fx, SID_1k75)) - { - push_indice_fx( hBstr, IND_DITHERING, 0, 1 ); - } - IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - IF(EQ_16(st_fx->L_frame_fx, L_FRAME16k)) - { - push_indice_fx( hBstr, IND_ACELP_16KHZ, 1, 1 ); - } - ELSE - { - push_indice_fx( hBstr, IND_ACELP_16KHZ, 0, 1 ); - } - - push_indice_fx( hBstr, IND_CNG_HO, s_min(hTdCngEnc->burst_ho_cnt, 7 ), 3 ); - hTdCngEnc->num_ho = m; - move16(); - push_indice_fx( hBstr, IND_SID_TYPE, 0, 1 ); - - IF ( LT_32(st_fx->input_Fs_fx, 32000) && NE_16(st_fx->element_mode, IVAS_CPE_DFT)) - { - push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); - *sid_bw = 0; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - /* update the SID frames counter */ - test(); - IF( EQ_32(st_fx->core_brate_fx, SID_2k40)||EQ_32(st_fx->core_brate_fx,SID_1k75)) - { - hDtxEnc->cng_cnt = 0; - move16(); - hTdCngEnc->cng_hist_ptr = -1; - move16(); - /* update frame length memory */ - hDtxEnc->last_CNG_L_frame = st_fx->L_frame_fx; - move16(); - } - ELSE - { - hDtxEnc->cng_cnt = add(hDtxEnc->cng_cnt,1); - } - - return; -} -/*---------------------------------------------------------------------* - * swb_CNG_enc() - * - * SWB DTX/CNG encoding - *---------------------------------------------------------------------*/ -void swb_CNG_enc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ -) -{ - Word16 shb_SID_updt_fx=0; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - - test(); - IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)||st_fx->core_brate_fx==FRAME_NO_DATA) - { - IF (EQ_16(st_fx->cng_type_fx,LP_CNG)) - { - IF (GE_32(st_fx->input_Fs_fx, L_FRAME32k * FRAMES_PER_SEC)) - { - /* decide if SHB SID encoding or not */ - shb_SID_updt_fx = shb_DTX_fx(st_fx, shb_speech_fx, syn_12k8_16k_fx); - - /* SHB CNG encoding */ - shb_CNG_encod_fx(st_fx, shb_SID_updt_fx); - } - ELSE IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - //PMT("CNG IVAS_CPE_DFT code not implemented") -#ifdef IVAS_CODE - /* LF-boost not used in DFT-stereo, instead the bandwidth is transmitted */ - delete_indice(st->hBstr, IND_CNG_ENV1); - push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); - push_indice(st->hBstr, IND_UNUSED, 0, 4); - push_indice(st->hBstr, IND_SID_BW, 1, 1); -#endif - } - } - hTdCngEnc->last_vad = 0; - move16(); - } - ELSE - { - hTdCngEnc->last_vad = 1; - move16(); - } - - return; -} - -/*---------------------------------------------------------------------* - * shb_CNG_encod() - * - * SID parameters encoding for SHB signal - *---------------------------------------------------------------------*/ -static void shb_CNG_encod_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 update_fx /* i : SID update flag */ -) -{ - Word16 idx_ener_fx; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; -#ifdef IVAS_CODE - Word16 ener_mid_dec_thr; -#endif - - idx_ener_fx = 0; - move16(); - IF ( EQ_16(update_fx, 1)) - { - /* SHB energy quantization */ - IF (EQ_16(st_fx->element_mode, EVS_MONO)) - { - idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ - } - ELSE - { - /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/ - //PMT("shb_CNG_encod_fx quantization in missing") -#if 0 - idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ -#endif - } - - if ( LT_16(st_fx->bwidth_fx, SWB)) - { - idx_ener_fx = 0; - move16(); - } - - IF ( GT_16(idx_ener_fx, 15)) - { - idx_ener_fx = 15; - move16(); - } - ELSE - { - idx_ener_fx = s_max(idx_ener_fx,0); - } -#ifdef IVAS_CODE - /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */ - if (st->element_mode != EVS_MONO) - { - if (abs(idx_ener - st->hTdCngEnc->last_idx_ener) == 1) - { - ener_mid_dec_thr = 0.5f * ((st->hTdCngEnc->last_idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); - ener_mid_dec_thr += 0.5f * ((idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); - - if (fabs(st->hTdCngEnc->mov_shb_cng_ener - ener_mid_dec_thr) / ener_mid_dec_thr < ENER_MID_DEAD_ZONE) - { - idx_ener = st->hTdCngEnc->last_idx_ener; - } - } - } - - st->hTdCngEnc->last_idx_ener = idx_ener; -#endif - push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4); - push_indice_fx( hBstr, IND_SID_BW, 1, 1 ); -#ifndef IVAS_CODE - hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits); - hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; -#else - delete_indice(hBstr, IND_CNG_ENV1); -#endif - move16(); -#ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_DFT) - { - push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); - } - else -#endif - { - push_indice_fx(hBstr, IND_UNUSED, 0, 2); - } - hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - hTdCngEnc->ho_sid_bw = L_or(hTdCngEnc->ho_sid_bw, 0x1L); - } - ELSE - { - IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); - push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); - } - } - - return; -} - -/*---------------------------------------------------------------------* -* shb_DTX() -* -* Decide if encoding SHB SID or not -*---------------------------------------------------------------------*/ -static Word16 shb_DTX_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ -) -{ - Word16 i; - Word16 update_fx; - Word16 shb_old_speech_fx[(ACELP_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/4]; - Word16 *shb_new_speech_fx; - Word32 wb_ener_fx; - Word32 shb_ener_fx; - Word16 log_wb_ener_fx; - Word16 log_shb_ener_fx; - Word16 tmp; - Word16 exp; - Word16 fra; - Word16 att; /*Q8*/ - Word16 allow_cn_step_fx=0; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif - shb_new_speech_fx = shb_old_speech_fx + (ACELP_LOOK_12k8 + L_SUBFR) * 5/4; - Copy(hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); - Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); - - shb_ener_fx = L_deposit_l(0); - FOR ( i=0; iL_frame_fx; i++ ) - { -#ifdef BASOP_NOGLOB - wb_ener_fx = L_mac_o(wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i], &Overflow); -#else - wb_ener_fx = L_mac(wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i]); -#endif - } - - wb_ener_fx = L_add(Mpy_32_16_1(wb_ener_fx, 128), 1); /* 128 in Q15, wb_ener_fx in Q1 */ - - exp = norm_l(wb_ener_fx); - fra = Log2_norm_lc(L_shl(wb_ener_fx, exp)); - exp = sub(30-1, exp); - wb_ener_fx = Mpy_32_16(exp, fra, LG10); -#ifdef BASOP_NOGLOB - log_wb_ener_fx = round_fx_o(L_shl_o(wb_ener_fx, 10, &Overflow), &Overflow); /* log_wb_ener_fx in Q8 */ -#else - log_wb_ener_fx = round_fx(L_shl(wb_ener_fx, 10)); /* log_wb_ener_fx in Q8 */ -#endif - exp = norm_l(shb_ener_fx); - fra = Log2_norm_lc(L_shl(shb_ener_fx, exp)); - exp = sub(30-1, exp); - shb_ener_fx = Mpy_32_16(exp, fra, LG10); - - test(); - IF (EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) - { - att = 0; - move16(); - //PMT("apply_scale is not implemented") -#if 0 - apply_scale(&att, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); -#endif - } - else - { - att = 1664; /*6.5 in Q8*/ - move16(); - } - -#ifdef BASOP_NOGLOB - log_shb_ener_fx = sub_o(round_fx_o(L_shl_o(shb_ener_fx, 10, &Overflow), &Overflow), att, &Overflow); /* log_shb_ener_fx in Q8 */ -#else - log_shb_ener_fx = sub(round_fx(L_shl(shb_ener_fx, 10)), att); /* log_shb_ener_fx in Q8 */ -#endif - IF (hDtxEnc->first_CNG == 0 ) - { - hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - hTdCngEnc->last_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - } - - if ( GT_16(abs_s(sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx)), 3072)) - { - allow_cn_step_fx = 1; - move16(); - } -#ifdef IVAS_CODE - /* Also allow step if shb energy has dropped 12 dB */ - if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && ((hTdCngEnc->mov_shb_cng_ener - log_shb_ener) > 12.0f)) - { - allow_cn_step = 1; - } -#endif - IF ( EQ_16(allow_cn_step_fx, 1)) - { - hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - } - ELSE - { - tmp = sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx); /* Q8 */ - tmp = mult(tmp, 29491); /* Q8 */ - hTdCngEnc->mov_wb_cng_ener_fx = add(hTdCngEnc->mov_wb_cng_ener_fx, tmp); /* Q8 */ - - tmp = sub(log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx); - tmp = mult(tmp, 8192); /* Q8 */ - hTdCngEnc->mov_shb_cng_ener_fx = add(hTdCngEnc->mov_shb_cng_ener_fx, tmp); /* Q8 */ - } - hTdCngEnc->shb_NO_DATA_cnt = add(hTdCngEnc->shb_NO_DATA_cnt, 1); - - update_fx = 0; - move16(); - IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - test(); - test(); - IF (hDtxEnc->first_CNG == 0 || EQ_16(hTdCngEnc->last_vad, 1)||GE_16(hTdCngEnc->shb_NO_DATA_cnt,100)) - { - update_fx = 1; - move16(); - } - ELSE - { - IF ( hTdCngEnc->shb_cng_ini_cnt > 0 ) - { - update_fx = 1; - move16(); - hTdCngEnc->shb_cng_ini_cnt = sub(hTdCngEnc->shb_cng_ini_cnt, 1); - } - ELSE - { - IF ( GT_16(abs_s(sub(sub(hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx), sub(hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx))), 768)) - { - update_fx = 1; - move16(); - } - ELSE - { - test(); - IF ( GE_16(st_fx->bwidth_fx, SWB)&<_16(hTdCngEnc->last_SID_bwidth,SWB)) - { - update_fx = 1; - move16(); - } - ELSE - { - test(); - IF ( LT_16(st_fx->bwidth_fx, SWB)&&GE_16(hTdCngEnc->last_SID_bwidth,SWB)) - { - update_fx = 1; - move16(); - } - } - } - } - } - - hTdCngEnc->last_SID_bwidth = st_fx->bwidth_fx; - move16(); - } - /* LF-boost not yet implemented in decoder which means that the specific wb_sid information is not used */ - test();test(); - if ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - update_fx = 1; - move16(); - } - - IF ( EQ_16(update_fx, 1)) - { - hTdCngEnc->last_wb_cng_ener_fx = hTdCngEnc->mov_wb_cng_ener_fx; - move16(); - hTdCngEnc->last_shb_cng_ener_fx = hTdCngEnc->mov_shb_cng_ener_fx; - move16(); - hTdCngEnc->shb_NO_DATA_cnt = 0; - move16(); - } - - - return (update_fx); -} - -/*---------------------------------------------------------------------* - * calculate_hangover_attenuation_gain_fx() - * - * - *---------------------------------------------------------------------*/ - -void calculate_hangover_attenuation_gain_fx( - Encoder_State_fx* st, /* i : encoder state structure */ - Word16* att, /* o : attenuation factor */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -) -{ - Word16 offset; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; - - *att = 32767; - - move16(); - /* smoothing in case of CNG */ - IF (hTdCngEnc != NULL) - { - test();test();test(); - IF( hTdCngEnc->burst_ho_cnt > 0 && (vad_hover_flag != 0) && (NE_16(st->bwidth_fx, NB) || GT_16(st->element_mode, EVS_MONO))) /* corresponds to line 504 in FLT acelp_core_enc.c */ - { -#ifdef IVAS_CODE - if (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) - { - *att = powf(10.0f, (st->hTdCngEnc->CNG_att / 160.0f) * st->hTdCngEnc->burst_ho_cnt); - } - else -#endif - { - offset = 5; - test(); - if (EQ_16(st->bwidth_fx, WB) && st->hDtxEnc->CNG_mode >= 0) - { - offset = st->hDtxEnc->CNG_mode; - move16(); - } - assert(hTdCngEnc->burst_ho_cnt > 0); - *att = CNG_burst_att_fx[offset][sub(hTdCngEnc->burst_ho_cnt, 1)]; /*Q15*/ - move16(); - } - } - - - } - return; -} +/*==================================================================================== + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + ====================================================================================*/ +#include +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +//#include "prot_fx.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +//#include "basop_mpy.h" + +#include +/*---------------------------------------------------------------------* +* Local constants +*---------------------------------------------------------------------*/ + +#define MAX_DELTA 1 +#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ +#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 ); +/*---------------------------------------------------------------------* +* CNG_enc() +* +* Confort noise generation for the coder +*---------------------------------------------------------------------*/ +void CNG_enc_fx( + 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_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) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 Q_new, /* i : Q value of speech */ + Word32 *q_env, + Word16 *sid_bw +) +{ + Word16 enr_index; + Word16 i, j, ptr; + Word16 m1; + Word16 res[L_FRAME16k]; + Word16 step_inv=0; + Word16 hi, lo; + Word16 maxl=0; + Word16 num_bits=0; + Word16 step=0; + Word16 *pt_res; + const Word16 *pt_sp; + Word16 enr; + Word32 L_tmp, L_ener; + Word16 k, tmp1; + Word16 weights; + Word16 sp_enr; + Word32 L_tmp1; + Word16 exp; + Word16 m = 0; + Word16 tmp[HO_HIST_SIZE*M]; + Word16 ll, s_ptr; + Word16 tmpv, maxv, scale, att = 1; + Word16 lsf_tmp[M]; + Word32 C[M]; + Word32 max_val[2]; + Word16 max_idx[2]; + Word16 ftmp_fx; + Word16 lsp_tmp[M]; + Word16 dev; + Word16 max_dev; + Word16 dist; + Word16 max_idx1[2]= {0,0}; + Word16 fft_io[L_FRAME16k]; + Word16 *ptR,*ptI; + Word32 enr1=0; + Word32 env[NUM_ENV_CNG]; + Word32 min1; + Word16 min1_idx; + Word32 d; + Word16 res1[L_FRAME16k]; + Word32 tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; + Word16 fra; + Word16 temp_lo_fx, temp_hi_fx; + Word16 exp_pow; + Word16 force_cn_step=0; + Word16 tmp_loop; + Word16 st_lp_sp_enr; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; + Word16 lp_ener_thr_scale; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + /* Temp variables for floating point functions */ + + lp_ener_thr_scale = 8; /* 4.0f*/ /*IVAS_CODE Q2 */ + move16(); + if (NE_16(st_fx->element_mode, EVS_MONO)) + { + lp_ener_thr_scale = 7; /* 3.5f;*/ + move16(); + } + /*sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f);*//*9.1 */ + 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 (i=0; i<2; i++) + { + 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 */ + } + } + } + + hi = norm_l(L_ener); + lo = Log2_norm_lc(L_shl(L_ener, hi)); + hi = sub(29, hi); /* log2 exp in Q2*Q_new */ + hi = sub(hi, shl(Q_new, 1)); /* Q0 */ + L_tmp = L_Comp(hi, lo); /* Q16 */ + sp_enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ + + if (sp_enr < 0) + { + sp_enr = 0; + move16(); + } + test(); + IF (hDtxEnc->first_CNG == 0 || hTdCngEnc->old_enr_index < 0 ) + { + hTdCngEnc->lp_sp_enr_fx = sp_enr; + move16(); /* Q8 */ + } + ELSE + { + test(); + test(); + test(); + test(); + IF( GT_32(st_fx->last_core_brate, SID_2k40) && ( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && + GT_16(sub(sp_enr, hTdCngEnc->lp_sp_enr_fx), 1024) && GT_16(sp_enr, 1536) ) + { + hTdCngEnc->lp_sp_enr_fx = sp_enr; + move16(); + force_cn_step = 1; + move16(); + } + ELSE + { + hTdCngEnc->lp_sp_enr_fx = round_fx(L_mac(L_mult(29491 /* 0.9, Q15 */,hTdCngEnc->lp_sp_enr_fx), 3277 /* 0.1, Q15 */,sp_enr)); /* Q8 (8+15+1-16) */ + } + } + /* update the pointer to circular buffer of old LSP vectors */ + hTdCngEnc->cng_hist_ptr = add(hTdCngEnc->cng_hist_ptr,1); + if(EQ_16(hTdCngEnc->cng_hist_ptr, DTX_HIST_SIZE)) + { + hTdCngEnc->cng_hist_ptr = 0; + move16(); + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + Copy( lsp_new, &(hTdCngEnc->cng_lsp_hist_fx[(hTdCngEnc->cng_hist_ptr)*M]), M ); + + /*-----------------------------------------------------------------* + * 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))) + { + set32_fx( max_val, 0, 2 ); + set16_fx( max_idx, 0, 2 ); + + FOR( i=0; i< hDtxEnc->cng_hist_size; i++ ) + { + IF ( EQ_16(st_fx->L_frame,L_FRAME)) + { + lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_FX ); + ftmp_fx = 964; + move16();/*QX2.56 */ + tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ + L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + } + ELSE + { + lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_16k ); + ftmp_fx = 1205; + move16();/*QX2.56 */ + tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ + L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + } + + tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ + L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ + FOR ( j=0; jcng_hist_size; j++ ) + { + L_tmp = L_add(L_tmp,L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[j*M+i])); /*Q15 */ + } + + L_tmp = L_sub(L_tmp,L_add(L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[0]*M+i]),L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[1]*M+i]))); /*Q15 */ + tmpv= div_s(1,sub(hDtxEnc->cng_hist_size,2)); /*Q15 */ + L_tmp = Mpy_32_16_1(L_tmp,tmpv); /*Q15 */ + lsp_new[i] = extract_l(L_tmp); /*Q15 */ + } + max_idx1[0] = max_idx[0]; + move16(); + max_idx1[1] = max_idx[1]; + move16(); + } + + /*-----------------------------------------------------------------* + * Quantize CNG spectral envelope (only in SID frame) + * Quantize the LSF vector + *-----------------------------------------------------------------*/ + *allow_cn_step = 0; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ((hDtxEnc->cng_cnt == 0) && + GT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && + (LT_16(add(st_lp_sp_enr, 1024 /* 4.0, Q8 */), sp_enr)) && + (hDtxEnc->first_CNG != 0) && + (hTdCngEnc->old_enr_index >= 0) && + (GT_32(st_fx->last_core_brate, SID_2k40))) || + EQ_16(force_cn_step, 1)) + { + *allow_cn_step = 1; + move16(); + } + + /* Initialize the CNG spectral envelope in case of the very first CNG frame */ + IF(hDtxEnc->first_CNG == 0) + { + Copy(st_fx->lsp_old_fx, hDtxEnc->lspCNG_fx, M); + + /* Average the CNG spectral envelope in case of the very first CNG frame */ + IF (NE_16(st_fx->element_mode, EVS_MONO)) + { + FOR (i = 0; i < M; i++) + { + /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ + lsp_new[i] = mac_r(L_mult(lsp_mid[i], 16384), lsp_new[i], 16384); + move16(); + } + } + } + + + test(); + IF( EQ_32(st_fx->core_brate, SID_2k40) || EQ_32(st_fx->core_brate,SID_1k75)) + { + /* LSF quantization */ + IF ( st_fx->Opt_AMR_WB != 0 ) + { + isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0); + } + ELSE + { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + lsf_enc_fx(st_fx, lsf_new, lsp_new, NULL, NULL, 100, 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(); + if ( EQ_16(st_fx->bwidth,WB) && hDtxEnc->first_CNG!=0 && NE_16(st_fx->L_frame, hDtxEnc->last_CNG_L_frame)) + { + hTdCngEnc->ho_hist_size = 0; + move16(); + } + } + ELSE + { + /* Use old LSP vector */ + Copy( st_fx->lsp_old_fx, lsp_new, M ); + Copy( st_fx->lsf_old_fx, lsf_new, M ); + } + + /*---------------------------------------------------------------------* + * CNG spectral envelope update + * Find A(z) coefficients + *---------------------------------------------------------------------*/ + + IF( LE_32(st_fx->last_core_brate, SID_2k40)) + { + /* Reset hangover counter if not first SID period */ + if( GT_32(st_fx->core_brate,FRAME_NO_DATA)) + { + hTdCngEnc->num_ho = 0; + move16(); + } + /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ + test(); + IF( LT_16(hTdCngEnc->num_ho,3) || LT_32(Mult_32_16(hTdCngEnc->Enew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) + { + FOR( i=0; ilspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i]),32768-CNG_ISF_FACT_FX,lsp_new[i]); + move16(); /* Q15 (15+15+1-16) */ + } + } + } + ELSE + { + /* Update CNG_mode if allowed */ + test(); + test(); + test(); + IF( EQ_16(st_fx->element_mode, EVS_MONO) && (( st_fx->Opt_AMR_WB || EQ_16(st_fx->bwidth,WB)) + && ( !hDtxEnc->first_CNG || GE_16(hTdCngEnc->act_cnt2,MIN_ACT_CNG_UPD) ) ) ) + { + IF (GT_32(hDtxEnc->last_active_brate, ACELP_16k40)) + { + hDtxEnc->CNG_mode = -1; + move16(); + } + ELSE + { + hDtxEnc->CNG_mode = get_cng_mode(hDtxEnc->last_active_brate); + } + } + + /* If first sid after active burst update LSF history from circ buffer */ + hTdCngEnc->burst_ho_cnt = s_min(hTdCngEnc->burst_ho_cnt, hTdCngEnc->ho_circ_size); + hTdCngEnc->act_cnt = 0; + move16(); + s_ptr = add(sub(hTdCngEnc->ho_circ_ptr, hTdCngEnc->burst_ho_cnt),1); + + if( s_ptr < 0 ) + { + s_ptr = add(s_ptr, hTdCngEnc->ho_circ_size); + } + + FOR( ll = hTdCngEnc->burst_ho_cnt; ll > 0; ll-- ) + { + hTdCngEnc->ho_hist_ptr = add(hTdCngEnc->ho_hist_ptr,1); + if( EQ_16(hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE)) + { + hTdCngEnc->ho_hist_ptr = 0; + move16(); + } + + /* Conversion between 12.8k and 16k LSPs */ + test(); + test(); + IF( EQ_16(st_fx->L_frame,L_FRAME )&&EQ_16(hTdCngEnc->ho_16k_lsp[s_ptr],1)) + { + /* Conversion from 16k LPSs to 12k8 */ + lsp_convert_poly_fx( &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), st_fx->L_frame, 0 ); + } + ELSE IF ( EQ_16(st_fx->L_frame,L_FRAME16k)&& hTdCngEnc->ho_16k_lsp[s_ptr]==0) + { + /* 16k LSPs already converted and stored, just copy to the other buffer */ + Copy(&(hTdCngEnc->ho_lsp_circ2_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), M ); + } + /* update the circular buffers */ + Copy(&(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_hist_fx[hTdCngEnc->ho_hist_ptr*M]), M ); + Copy32(&(hTdCngEnc->ho_ener_circ_fx[s_ptr]), &(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr]), 1 ); + hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); + Copy32(&(hTdCngEnc->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(hTdCngEnc->ho_env_hist_fx[hTdCngEnc->ho_hist_ptr*NUM_ENV_CNG]), NUM_ENV_CNG ); + + hTdCngEnc->ho_hist_size = add(hTdCngEnc->ho_hist_size,1); + if (GT_16(hTdCngEnc->ho_hist_size, HO_HIST_SIZE)) + { + hTdCngEnc->ho_hist_size = HO_HIST_SIZE; + move16(); + } + + s_ptr = add(s_ptr,1); + + if( EQ_16(s_ptr, hTdCngEnc->ho_circ_size)) + { + s_ptr = 0; + move16(); + } + } + + IF(hTdCngEnc->burst_ho_cnt > 0) + { + /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ +#if 1 + /*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 = L_shr(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr],2); + L_tmp1 = L_sub(L_tmp1,hTdCngEnc->lp_ener_fx); +#endif + test();test(); + IF((hDtxEnc->first_CNG > 0 || EQ_16(st_fx->element_mode, EVS_MONO)) && L_tmp1>0) + { + *allow_cn_step = s_or(*allow_cn_step,1); + } + } + test(); + IF ( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) + { + /* Use average of energies below last energy */ + ptr = hTdCngEnc->ho_hist_ptr; + move16(); + Copy( &(hTdCngEnc->ho_lsp_hist_fx[ptr*M]), tmp, M ); + m1 = 0; + move16(); + IF( L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x1) == 0 ) + { + Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + m1 = 1; + move16(); + } + L_enr = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ + + weights = W_DTX_HO_FX[0]; /* Q15 */ + + m = 1; + move16(); + FOR( k=1; kho_hist_size; k++ ) + { + ptr = sub(ptr,1); + if( ptr < 0 ) + { + ptr = HO_HIST_SIZE - 1; + move16(); + } + + test(); + IF ( LT_32(Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr])&& + GT_32(hTdCngEnc->ho_ener_hist_fx[ptr],Mult_32_16(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], BUF_L_NRG_FX)) ) + { + /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr]; */ + L_tmp1 = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ + L_enr = L_add(L_enr,L_tmp1); /* Q6 */ + + /*weights += W_DTX_HO[k]; */ + weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ + + Copy( &hTdCngEnc->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); + IF( L_and(hTdCngEnc->ho_sid_bw, L_shl((Word32)0x1,k)) == 0 ) + { + Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); + m1 = add(m1,1); + } + m = add(m,1); + } + } + + /*enr /= weights; */ + exp = norm_s(weights); + tmp1 = div_s(shl(1,sub(14,exp)),weights); /* Q(15+14-exp-15) */ + L_tmp1 = Mult_32_16(L_enr,tmp1); /* Q(14-exp+6-15)->Q(5-exp) */ + L_enr = L_shl(L_tmp1,add(exp,1)); /* Q6 */ + + hTdCngEnc->lp_ener_fx = L_enr; + move32();/* Q6 */ + + set32_fx( max_val, 0, 2 ); + set16_fx( max_idx, 0, 2 ); + + FOR( i=0; iL_frame,L_FRAME)) + { + lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); + ftmp_fx = 964; + move16();/*QX2.56 */ + tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ + L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + } + ELSE + { + lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); + ftmp_fx = 1205; + move16();/*QX2.56 */ + tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ + L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ + } + + tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ + L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ + FOR ( j=0; jlspCNG_fx[i] = lsp_tmp[i]; + move16(); /*Q15 */ + } + } + ELSE + { + FOR( i=0; ilspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); + move16(); + } + } + IF( m1 > 0 ) + { + FOR ( i=0; ilp_ener_fx; */ + IF(EQ_16(m1,1)) + { + L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); + } + ELSE + { + tmp1 = div_s(1,m1); + L_tmp = Mult_32_16(L_tmp,tmp1); + L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); + } + + env[i] = L_tmp; + move32(); + } + Copy32(env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG); + } + } + ELSE + { + Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ + } + } + IF ( st_fx->Opt_AMR_WB != 0 ) + { + E_LPC_f_isp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); + } + ELSE + { + E_LPC_f_lsp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ + } + + tmp_loop = shr(st_fx->L_frame,6); + FOR( i=1; iL_frame, 0); + Copy(res, res1, st_fx->L_frame); + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + //PMT("Code to be completed") +#ifdef IVAS_CODE + att = powf(10.0f, hTdCngEnc->CNG_att / 20.0f); + v_multc(res1, att, res1, st->L_frame); +#endif + } + ELSE IF( NE_16(st_fx->bwidth,NB)) + { + test(); + IF( EQ_16(st_fx->bwidth,WB) && hDtxEnc->CNG_mode>=0) + { + ftmp_fx = HO_ATT_FX[hDtxEnc->CNG_mode]; + } + ELSE + { + ftmp_fx = 19661; + move16(); + } + + att = mult(ftmp_fx,5461);/* Q15 */ + L_tmp = L_mult(att,8);/* Q16 */ + tmp1 = extract_l(L_shr(L_tmp,2));/* Q14 */ + tmp1 = add(16384,tmp1); + att = div_s(16374,tmp1); /* Q15 */ + + att = s_max(att, ftmp_fx); + FOR( i = 0; i < st_fx->L_frame; i++ ) + { + /*res1[i] *= att;*/ + res1[i] = mult(res1[i],att); + move16();/* Q_new */ + } + att = shr(att,7);/* Q8 */ + } + + /* calculate the spectrum of residual signal */ + Copy(res1, fft_io, st_fx->L_frame); + + IF ( EQ_16(st_fx->L_frame,L_FRAME16k)) + { + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx,0); + } + + fft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); + ptR = &fft_io[1]; + ptI = &fft_io[L_FFT-1]; + FOR ( i=0; icng_res_env_fx[(hTdCngEnc->cng_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + + /* calculate the residual signal energy */ + /*enr = dotp( res, res, L_frame ) / L_frame; */ + 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(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add(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(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add(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) */ + + /* update the circular buffer of old energies */ + hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; + move16(); /* Q8 */ + + /*-----------------------------------------------------------------* + * 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)) + { + IF( GE_16(hDtxEnc->cng_cnt,sub(hDtxEnc->cng_hist_size,1))) + { + /* average the envelope except outliers */ + FOR ( i=0; icng_hist_size; j++ ) + { + L_tmp1 = L_add(L_tmp1,hTdCngEnc->cng_res_env_fx[j*NUM_ENV_CNG+i]); + } + L_tmp = L_add(hTdCngEnc->cng_res_env_fx[max_idx1[0]*NUM_ENV_CNG+i],hTdCngEnc->cng_res_env_fx[max_idx1[1]*NUM_ENV_CNG+i]); + L_tmp1 = L_sub(L_tmp1,L_tmp); + + /* env[i] /= (float)(st_fx->cng_hist_size - 2); */ + tmp1 = sub(hDtxEnc->cng_hist_size,2); + IF(GT_16(tmp1,1)) + { + tmp1 = div_s(1,tmp1); + L_tmp1 = Mult_32_16(L_tmp1,tmp1); + } + + env[i] = L_tmp1; + move32(); + } + /* compute average excitation energy */ + L_tmp = L_deposit_l(0); + ptr = hTdCngEnc->cng_hist_ptr; + move16(); + + FOR (k=0; k< hDtxEnc->cng_hist_size; k++) + { + /* enr += W_HIST[k]*cng_ener_hist[ptr] */ + L_tmp = L_mac0(L_tmp, W_HIST_FX[k], hTdCngEnc->cng_ener_hist_fx[ptr]); /* Q24 (8+16) */ + ptr = sub(ptr, 1); + if (ptr < 0) /* check for circular pointer */ + { + ptr = DTX_HIST_SIZE - 1; + move16(); + } + } + /*----------------------------------------------------------- + * here we want to divide L_tmp by the sum + * of all the coefs used W_HIST[0..cng_hist_size-1] + * The table W_HIST_S already contains the inverted sum. + * That is + * W_HIST_S[k] 1 + * ------------- = --------------------------- + * 4096 W_HIST[0] + ... + W_HIST[k] + * + * 1 / Sum(W_HIST[0..k]) is always > 1 since the sum + * of the coefs 0..k is always < 1 but > 0 + * enr is in Q8 since the history buffer constains Q8 energies + *-----------------------------------------------------------*/ + /*L_tmp = Mpy_32_16_1(L_tmp, W_HIST_S_FX[k-1]); */ /* normalize average value */ + L_tmp = Mult_32_16(L_tmp, W_HIST_S_FX[k-1]); /* Q21 (24+12+1-16) */ + L_tmp = L_shl(L_tmp, 3); /* Q24 */ + enr = round_fx(L_tmp); /* Q8 */ + } + /* decrease the energy in case of WB input */ + IF ( EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) + { + //PMT("CNG IVAS_SCE and IVAS_CPE_DFT code missing") + //IVAS_CODE + //enr += hTdCngEnc->CNG_att * FAC_LOG2 / 10.0f; + } + ELSE IF( NE_16(st_fx->bwidth, NB)) + { + IF( EQ_16(st_fx->bwidth,WB)) + { + IF(hDtxEnc->CNG_mode >= 0 ) + { + /* Bitrate adapted attenuation */ + att = ENR_ATT_fx[hDtxEnc->CNG_mode]; + move16(); + } + ELSE + { + /* Use least attenuation for higher bitrates */ + att = ENR_ATT_fx[4]; + move16(); + } + } + ELSE + { + att = 384; + move16();/*Q8*/ + } + enr = sub(enr, att ); + } + /* intialize the energy quantization parameters */ + IF( st_fx->Opt_AMR_WB == 0 ) + { + step = STEP_SID_FX; + move16(); + step_inv = ISTEP_SID_FX; + move16(); + maxl = 127; + move16(); + num_bits = 7; + move16(); + } + ELSE + { + step = STEP_AMR_WB_SID_FX; + move16(); + step_inv = ISTEP_AMR_WB_SID_FX; + move16(); + maxl = 63; + move16(); + num_bits = 6; + move16(); + } + + /* calculate the energy quantization index */ + enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ + enr_index = extract_l(L_shr(L_mult0(enr_index, step), 12+8)); /* Q0 (8+12-(8+12)) */ + + /* limit the energy quantization index */ + enr_index = s_min(enr_index, maxl); + enr_index = s_max(enr_index, 0); + + /* allow only slow energy increase */ + test(); + IF( hTdCngEnc->old_enr_index >= 0 && GT_16(enr_index, add(hTdCngEnc->old_enr_index, MAX_DELTA))) + { + IF( *allow_cn_step != 0 ) + { + tmp1 = mult(27853 /* Q15(0.85) */,sub(enr_index,hTdCngEnc->old_enr_index)); + enr_index = add(hTdCngEnc->old_enr_index,tmp1); + } + ELSE + { + enr_index = add(hTdCngEnc->old_enr_index, MAX_DELTA); + } + } + hTdCngEnc->old_enr_index = enr_index; + move16(); + + push_indice_fx( hBstr, IND_ENERGY, enr_index, num_bits ); + if ( enr_index == 0 ) + { + enr_index = -5; + move16(); + } + /* Find quantized energy */ + /* *Enew = (float)enr_index / step - 2.0 */ + /* *Enew = (float)pow(2.0, *Enew) */ + L_tmp = L_mult(enr_index, step_inv); /* Q16(0+15+1) */ + /* substract by 2 not done to leave Energy in Q2 */ + lo = L_Extract_lc(L_tmp, &hi); + hTdCngEnc->Enew_fx = Pow2(add(hi, 4), lo); /* Q6 */ + IF ( EQ_32(st_fx->core_brate, SID_2k40)) + { + /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ + exp = norm_l(hTdCngEnc->Enew_fx); + L_tmp = L_shl(hTdCngEnc->Enew_fx,exp); /*Q(exp+6) */ + L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame,5));/* Q(exp+6+5-15=exp-4) */ + +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat(L_tmp,sub(exp,10)); /* Q6 */ +#else + L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ +#endif + + exp = norm_l(L_tmp); + fra = Log2_norm_lc(L_shl(L_tmp,exp)); + exp = sub(sub(30,exp),6); + L_tmp = L_Comp(exp,fra); + enr1 = L_shr(L_tmp,10);/* Q6 */ + + FOR ( i=0; iEnew;*/ + L_tmp1 = L_add(env[i], 0); + L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); + L_tmp1 = L_sub(L_tmp1,L_tmp); /*Q6*/ + + IF ( L_tmp1 < 0 ) + { + L_tmp1 = L_deposit_l(6); /* (0.1)Q6 */ + } + /* env[i] = (float)log10( env[i] + 0.1f ) / (float)log10( 2.0f ); */ + exp = norm_l(L_tmp1); + fra = Log2_norm_lc(L_shl(L_tmp1,exp)); + exp = sub(sub(30,exp),6); + L_tmp = L_Comp(exp,fra); + L_tmp1 = L_shr(L_tmp,10); /* Q6 */ + + L_tmp = L_shr(L_deposit_l(att),2);/* Q6 */ + L_tmp1 = L_sub(L_tmp1,L_tmp); + + IF ( L_tmp1 < 0 ) + { + L_tmp1 = L_deposit_l(0); + } + + L_tmp1 = L_sub(enr1,L_tmp1); + + env[i] = L_tmp1; + move32(); + } + + /* codebook search */ + min1 = L_add(1310588928, 0); /* Q17 */ + min1_idx = 0; + move16(); + + FOR ( i=0; i<64; i++ ) + { + d = L_deposit_l(0); + FOR ( j=0; jEnew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) + { + /* update the pointer to circular buffer of old LSP vectors */ + hTdCngEnc->ho_hist_ptr = add(hTdCngEnc->ho_hist_ptr, 1); + if( EQ_16(hTdCngEnc->ho_hist_ptr,HO_HIST_SIZE)) + { + hTdCngEnc->ho_hist_ptr = 0; + move16(); + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + Copy( lsp_new, &(hTdCngEnc->ho_lsp_hist_fx[(hTdCngEnc->ho_hist_ptr)*M]), M ); + + /* update the hangover energy buffer */ + hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] = hTdCngEnc->Enew_fx; + move32(); + IF ( EQ_32(st_fx->core_brate, SID_2k40)) + { + FOR ( i=0; iEnew;*/ + L_tmp = L_sub(enr1,q_env[i]);/* Q6 */ + L_tmp = L_shl(L_tmp, 10);/* 16 */ + temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); + + exp_pow = sub(14, temp_hi_fx); + L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ + env[i] = L_shl(L_tmp, sub(6, exp_pow)); + move32(); /* Q6 */ + L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); + env[i] = L_add(env[i],L_tmp); + move32();/* Q6 */ + } + Copy32( env, &(hTdCngEnc->ho_env_hist_fx[(hTdCngEnc->ho_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + } + hTdCngEnc->ho_hist_size = add(hTdCngEnc->ho_hist_size,1); + if( GT_16(hTdCngEnc->ho_hist_size,HO_HIST_SIZE)) + { + hTdCngEnc->ho_hist_size = HO_HIST_SIZE; + move16(); + } + } + } + /* dithering bit for AMR-WB IO mode is always set to 0 */ + IF( EQ_32(st_fx->core_brate, SID_1k75)) + { + push_indice_fx( hBstr, IND_DITHERING, 0, 1 ); + } + IF ( EQ_32(st_fx->core_brate, SID_2k40)) + { + IF(EQ_16(st_fx->L_frame, L_FRAME16k)) + { + push_indice_fx( hBstr, IND_ACELP_16KHZ, 1, 1 ); + } + ELSE + { + push_indice_fx( hBstr, IND_ACELP_16KHZ, 0, 1 ); + } + + push_indice_fx( hBstr, IND_CNG_HO, s_min(hTdCngEnc->burst_ho_cnt, 7 ), 3 ); + hTdCngEnc->num_ho = m; + move16(); + push_indice_fx( hBstr, IND_SID_TYPE, 0, 1 ); + + IF ( LT_32(st_fx->input_Fs, 32000) && NE_16(st_fx->element_mode, IVAS_CPE_DFT)) + { + push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); + *sid_bw = 0; + move16(); + } + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + /* update the SID frames counter */ + test(); + IF( EQ_32(st_fx->core_brate, SID_2k40)||EQ_32(st_fx->core_brate,SID_1k75)) + { + hDtxEnc->cng_cnt = 0; + move16(); + hTdCngEnc->cng_hist_ptr = -1; + move16(); + /* update frame length memory */ + hDtxEnc->last_CNG_L_frame = st_fx->L_frame; + move16(); + } + ELSE + { + hDtxEnc->cng_cnt = add(hDtxEnc->cng_cnt,1); + } + + return; +} +/*---------------------------------------------------------------------* + * swb_CNG_enc() + * + * SWB DTX/CNG encoding + *---------------------------------------------------------------------*/ +void swb_CNG_enc_fx( + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ +) +{ + Word16 shb_SID_updt_fx=0; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + + test(); + IF ( EQ_32(st_fx->core_brate, SID_2k40)||st_fx->core_brate==FRAME_NO_DATA) + { + IF (EQ_16(st_fx->cng_type,LP_CNG)) + { + IF (GE_32(st_fx->input_Fs, L_FRAME32k * FRAMES_PER_SEC)) + { + /* decide if SHB SID encoding or not */ + shb_SID_updt_fx = shb_DTX_fx(st_fx, shb_speech_fx, syn_12k8_16k_fx); + + /* SHB CNG encoding */ + shb_CNG_encod_fx(st_fx, shb_SID_updt_fx); + } + ELSE IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && EQ_32(st_fx->core_brate, SID_2k40)) + { + //PMT("CNG IVAS_CPE_DFT code not implemented") +#ifdef IVAS_CODE + /* LF-boost not used in DFT-stereo, instead the bandwidth is transmitted */ + delete_indice(st->hBstr, IND_CNG_ENV1); + push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); + push_indice(st->hBstr, IND_UNUSED, 0, 4); + push_indice(st->hBstr, IND_SID_BW, 1, 1); +#endif + } + } + hTdCngEnc->last_vad = 0; + move16(); + } + ELSE + { + hTdCngEnc->last_vad = 1; + move16(); + } + + return; +} + +/*---------------------------------------------------------------------* + * shb_CNG_encod() + * + * SID parameters encoding for SHB signal + *---------------------------------------------------------------------*/ +static void shb_CNG_encod_fx( + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 update_fx /* i : SID update flag */ +) +{ + Word16 idx_ener_fx; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; +#ifdef IVAS_CODE + Word16 ener_mid_dec_thr; +#endif + + idx_ener_fx = 0; + move16(); + IF ( EQ_16(update_fx, 1)) + { + /* SHB energy quantization */ + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ + } + ELSE + { + /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/ + //PMT("shb_CNG_encod_fx quantization in missing") +#if 0 + idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ +#endif + } + + if ( LT_16(st_fx->bwidth, SWB)) + { + idx_ener_fx = 0; + move16(); + } + + IF ( GT_16(idx_ener_fx, 15)) + { + idx_ener_fx = 15; + move16(); + } + ELSE + { + idx_ener_fx = s_max(idx_ener_fx,0); + } +#ifdef IVAS_CODE + /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */ + if (st->element_mode != EVS_MONO) + { + if (abs(idx_ener - st->hTdCngEnc->last_idx_ener) == 1) + { + ener_mid_dec_thr = 0.5f * ((st->hTdCngEnc->last_idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); + ener_mid_dec_thr += 0.5f * ((idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); + + if (fabs(st->hTdCngEnc->mov_shb_cng_ener - ener_mid_dec_thr) / ener_mid_dec_thr < ENER_MID_DEAD_ZONE) + { + idx_ener = st->hTdCngEnc->last_idx_ener; + } + } + } + + st->hTdCngEnc->last_idx_ener = idx_ener; +#endif + push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4); + push_indice_fx( hBstr, IND_SID_BW, 1, 1 ); +#ifndef IVAS_CODE + hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits); + hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; +#else + delete_indice(hBstr, IND_CNG_ENV1); +#endif + move16(); +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_DFT) + { + push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); + } + else +#endif + { + push_indice_fx(hBstr, IND_UNUSED, 0, 2); + } + hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); + hTdCngEnc->ho_sid_bw = L_or(hTdCngEnc->ho_sid_bw, 0x1L); + } + ELSE + { + IF ( EQ_32(st_fx->core_brate, SID_2k40)) + { + hTdCngEnc->ho_sid_bw = L_shl(L_and(hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1); + push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); + } + } + + return; +} + +/*---------------------------------------------------------------------* +* shb_DTX() +* +* Decide if encoding SHB SID or not +*---------------------------------------------------------------------*/ +static Word16 shb_DTX_fx( + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ + const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ +) +{ + Word16 i; + Word16 update_fx; + Word16 shb_old_speech_fx[(ACELP_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/4]; + Word16 *shb_new_speech_fx; + Word32 wb_ener_fx; + Word32 shb_ener_fx; + Word16 log_wb_ener_fx; + Word16 log_shb_ener_fx; + Word16 tmp; + Word16 exp; + Word16 fra; + Word16 att; /*Q8*/ + Word16 allow_cn_step_fx=0; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + shb_new_speech_fx = shb_old_speech_fx + (ACELP_LOOK_12k8 + L_SUBFR) * 5/4; + Copy(hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); + Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); + Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); + + shb_ener_fx = L_deposit_l(0); + FOR ( i=0; iL_frame; i++ ) + { +#ifdef BASOP_NOGLOB + wb_ener_fx = L_mac_o(wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i], &Overflow); +#else + wb_ener_fx = L_mac(wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i]); +#endif + } + + wb_ener_fx = L_add(Mpy_32_16_1(wb_ener_fx, 128), 1); /* 128 in Q15, wb_ener_fx in Q1 */ + + exp = norm_l(wb_ener_fx); + fra = Log2_norm_lc(L_shl(wb_ener_fx, exp)); + exp = sub(30-1, exp); + wb_ener_fx = Mpy_32_16(exp, fra, LG10); +#ifdef BASOP_NOGLOB + log_wb_ener_fx = round_fx_o(L_shl_o(wb_ener_fx, 10, &Overflow), &Overflow); /* log_wb_ener_fx in Q8 */ +#else + log_wb_ener_fx = round_fx(L_shl(wb_ener_fx, 10)); /* log_wb_ener_fx in Q8 */ +#endif + exp = norm_l(shb_ener_fx); + fra = Log2_norm_lc(L_shl(shb_ener_fx, exp)); + exp = sub(30-1, exp); + shb_ener_fx = Mpy_32_16(exp, fra, LG10); + + test(); + IF (EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) + { + att = 0; + move16(); + //PMT("apply_scale is not implemented") +#if 0 + apply_scale(&att, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); +#endif + } + else + { + att = 1664; /*6.5 in Q8*/ + move16(); + } + +#ifdef BASOP_NOGLOB + log_shb_ener_fx = sub_o(round_fx_o(L_shl_o(shb_ener_fx, 10, &Overflow), &Overflow), att, &Overflow); /* log_shb_ener_fx in Q8 */ +#else + log_shb_ener_fx = sub(round_fx(L_shl(shb_ener_fx, 10)), att); /* log_shb_ener_fx in Q8 */ +#endif + IF (hDtxEnc->first_CNG == 0 ) + { + hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; + move16(); + hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; + move16(); + hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; + move16(); + hTdCngEnc->last_shb_cng_ener_fx = log_shb_ener_fx; + move16(); + } + + if ( GT_16(abs_s(sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx)), 3072)) + { + allow_cn_step_fx = 1; + move16(); + } +#ifdef IVAS_CODE + /* Also allow step if shb energy has dropped 12 dB */ + if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && ((hTdCngEnc->mov_shb_cng_ener - log_shb_ener) > 12.0f)) + { + allow_cn_step = 1; + } +#endif + IF ( EQ_16(allow_cn_step_fx, 1)) + { + hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; + move16(); + hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; + move16(); + } + ELSE + { + tmp = sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx); /* Q8 */ + tmp = mult(tmp, 29491); /* Q8 */ + hTdCngEnc->mov_wb_cng_ener_fx = add(hTdCngEnc->mov_wb_cng_ener_fx, tmp); /* Q8 */ + + tmp = sub(log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx); + tmp = mult(tmp, 8192); /* Q8 */ + hTdCngEnc->mov_shb_cng_ener_fx = add(hTdCngEnc->mov_shb_cng_ener_fx, tmp); /* Q8 */ + } + hTdCngEnc->shb_NO_DATA_cnt = add(hTdCngEnc->shb_NO_DATA_cnt, 1); + + update_fx = 0; + move16(); + IF ( EQ_32(st_fx->core_brate, SID_2k40)) + { + test(); + test(); + IF (hDtxEnc->first_CNG == 0 || EQ_16(hTdCngEnc->last_vad, 1)||GE_16(hTdCngEnc->shb_NO_DATA_cnt,100)) + { + update_fx = 1; + move16(); + } + ELSE + { + IF ( hTdCngEnc->shb_cng_ini_cnt > 0 ) + { + update_fx = 1; + move16(); + hTdCngEnc->shb_cng_ini_cnt = sub(hTdCngEnc->shb_cng_ini_cnt, 1); + } + ELSE + { + IF ( GT_16(abs_s(sub(sub(hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx), sub(hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx))), 768)) + { + update_fx = 1; + move16(); + } + ELSE + { + test(); + IF ( GE_16(st_fx->bwidth, SWB)&<_16(hTdCngEnc->last_SID_bwidth,SWB)) + { + update_fx = 1; + move16(); + } + ELSE + { + test(); + IF ( LT_16(st_fx->bwidth, SWB)&&GE_16(hTdCngEnc->last_SID_bwidth,SWB)) + { + update_fx = 1; + move16(); + } + } + } + } + } + + hTdCngEnc->last_SID_bwidth = st_fx->bwidth; + move16(); + } + /* LF-boost not yet implemented in decoder which means that the specific wb_sid information is not used */ + test();test(); + if ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && EQ_32(st_fx->core_brate, SID_2k40)) + { + update_fx = 1; + move16(); + } + + IF ( EQ_16(update_fx, 1)) + { + hTdCngEnc->last_wb_cng_ener_fx = hTdCngEnc->mov_wb_cng_ener_fx; + move16(); + hTdCngEnc->last_shb_cng_ener_fx = hTdCngEnc->mov_shb_cng_ener_fx; + move16(); + hTdCngEnc->shb_NO_DATA_cnt = 0; + move16(); + } + + + return (update_fx); +} + +/*---------------------------------------------------------------------* + * calculate_hangover_attenuation_gain_fx() + * + * + *---------------------------------------------------------------------*/ + +void calculate_hangover_attenuation_gain_fx( + Encoder_State* st, /* i : encoder state structure */ + Word16* att, /* o : attenuation factor */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ +) +{ + Word16 offset; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + + *att = 32767; + + move16(); + /* smoothing in case of CNG */ + IF (hTdCngEnc != NULL) + { + test();test();test(); + IF( hTdCngEnc->burst_ho_cnt > 0 && (vad_hover_flag != 0) && (NE_16(st->bwidth, NB) || GT_16(st->element_mode, EVS_MONO))) /* corresponds to line 504 in FLT acelp_core_enc.c */ + { +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) + { + *att = powf(10.0f, (st->hTdCngEnc->CNG_att / 160.0f) * st->hTdCngEnc->burst_ho_cnt); + } + else +#endif + { + offset = 5; + test(); + if (EQ_16(st->bwidth, WB) && st->hDtxEnc->CNG_mode >= 0) + { + offset = st->hDtxEnc->CNG_mode; + move16(); + } + assert(hTdCngEnc->burst_ho_cnt > 0); + *att = CNG_burst_att_fx[offset][sub(hTdCngEnc->burst_ho_cnt, 1)]; /*Q15*/ + move16(); + } + } + + + } + return; +} -- GitLab