diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index e8c3e63e7da930657b67fd57ff86559103467176..c5b8caaef4abbfaeb9d2883fc41f7360f2c656f0 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); @@ -545,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 9ffcfabccd7f22800f859dbe1ed862a1e8212590..ab9e9f781426b55af7404efc6c2c044d3f9561e6 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 279a0afeeb6f3977bebd586226b9f736d29e7898..941e458feb2df74472e85a68aa3cd25df13f63e8 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 @@ -2168,8 +2172,13 @@ 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] = 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 } /* Perform FFT */ @@ -2177,7 +2186,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/fft_fx_evs.c b/lib_com/fft_fx_evs.c index 2e11c96c0b0cf1d588a0c5bff16763bf9f2f5eb8..b6ed50554002483c1ab0d0c71694b9e1898b65ef 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_com/gs_preech.c b/lib_com/gs_preech.c index 164cd022528f2f1e97b377914ed0aaaa46ddce0b..324c7562a7e1933201c56bfd96dade20ccb0b563 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 */ @@ -213,8 +217,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/interpol.c b/lib_com/interpol.c index ca33b80c3fd36ea9e37dc4ec7098baed5ccabef0..7969b8ab20fa9a95ad451e13eb6a166ae3076b83 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/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 8eb7dff6a5c30fbbc53be93513c0e8eff015102e..7d42b2689db710100f1a1b43791b31f9c4ce84a5 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 6874b790ca1b9c366f61d25b8037b9d9d8b92e12..3c01533c6d3bb72425d77211559022b69646236f 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; i= 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/tools_fx.c b/lib_com/tools_fx.c index 77ccfa4ab2fd83f084014671215bc8d767fce308..9aa17c37de3e5b97ffec51e24fec1a03842a776a 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -2032,8 +2032,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 ); @@ -3219,10 +3222,17 @@ void Acelp_dec_total_exc( FOR (i = 0; i < L_subfr; i++) { - L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i+i_subfr]), 1); /*Q16+Q_exc*/ - exc2_fx[i+i_subfr] = round_fx(L_tmp); /*Q_exc*/ - L_tmp = L_add(L_tmp, L_shl(L_mult(gain_code16, code_fx[i]), 6)); /*Q16+Q_exc*/ - exc_fx[i+i_subfr] = round_fx(L_tmp); /*Q_exc*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr] ), 1 ); /*Q16+Q_exc*/ + exc2_fx[i + i_subfr] = round_fx_sat( L_tmp ); /*Q_exc*/ + L_tmp = L_add_sat( L_tmp, L_shl_sat( L_mult( gain_code16, code_fx[i] ), 6 ) ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr] = round_fx_sat( L_tmp ); /*Q_exc*/ +#else + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr] ), 1 ); /*Q16+Q_exc*/ + exc2_fx[i + i_subfr] = round_fx( L_tmp ); /*Q_exc*/ + L_tmp = L_add( L_tmp, L_shl( L_mult( gain_code16, code_fx[i] ), 6 ) ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr] = round_fx( L_tmp ); /*Q_exc*/ +#endif } } diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index c006f6824ae2fe95ab73a1a5d15fff2c6a31e080..67fc70bfe032df382daa8cb4dfcfbd6d15c6971f 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/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index d1493f8b9fca170e4721b903d786092834251823..61620e003c2f862c6ae9a06d741038ad02bb11b4 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); diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 128d0db6ab807be18d5f298ff36a26d02e1fb6a5..08c2955f2c0bd2585a398ae4032837aa9adfc16d 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 df9c7c5b28a6222a93681a5053cda40ae76aca1c..0e45ca98d3efa345e7532e59bcf0ad6495ca0254 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/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index 59fef6a1f2be2a0fbf344ca8a78ba332cd36642e..e47fd61b8f999640152f3420b65aa94eaa4bb167 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -598,7 +598,11 @@ static void spectrum_mod_dct_fx( Ltmp = L_mult(gain, 32767); *pt_gbin = round_fx(L_mac(Ltmp, alpha, *pt_gbin)); /*Q14*/ /**pt++ *= *pt_gbin;*/ - *pt = round_fx(L_shl(L_mult(*pt, *pt_gbin),1)); +#ifdef BASOP_NOGLOB + *pt = round_fx_sat( L_shl_sat( L_mult( *pt, *pt_gbin ), 1 ) ); +#else + *pt = round_fx( L_shl( L_mult( *pt, *pt_gbin ), 1 ) ); +#endif pt++; pt_gbin++; } diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 295a8a4ab3afb341fb5d24bdf99bb47c735d2ed9..e8844a1da2209b12fb5e65d3f844737a378b7685 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -599,8 +599,11 @@ void CNG_dec_fx( exp = norm_l(hTdCngDec->Enew_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/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index be86427088d140d837ef373a52ef682805d485e6..2e444c7c9271b8dce2f75efc255b61eba239d2f0 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -254,7 +254,7 @@ void open_decoder_LPD( assert(0 == (st->hTcxCfg->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/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index 4bf6c098e1e110a2c2dd038c560143d1b0783415..ce1f1b908f857a5eab38d4f2656651d392169796 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/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index a8689594156b8c37457bc40bd2e18e23c4b31c25..d32daf5149074d4242d5309683a8d0b2de2a975e 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/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 39c2f98bbf871a799182397da288a93d31b90a2a..6a7f538c3ab3a7b72182afdc8e4844c52678af48 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 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_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 7ce5209c9db90a731228655d4e4c56d8a5def87a..360d05a87515cded5f8420d95a2308b4b00ba7f2 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -423,7 +423,11 @@ void gain_dec_mless_fx( /**gain_code = qua_table[index * 2 + 1] * gcode0;*/ L_tmp = L_mult(qua_table_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 move32(); /* Q10 -> Q16*/ } @@ -660,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/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 7acc5e8b1289448a287ffcd1ea09f4bb576ee1b7..d6e9eee5bc4c247a7e6a0e090f10e424338fe6d9 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/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 9f15cfba8f8be2ce8bd19c1a5591664570a089cf..f9a4faef76df448ced45e090dbe93f201f511b8d 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 1e0ffd4712ec79bf0567c4a35fc0bb8aa7fd55ce..ef505ae45f5ec4ab01e2822f18d0239e2b2d60fd 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/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 9338482cc862fe86d528a943f2cc742800bf206b..05a0fbe2ff4f8be2f541a290ab3dc11f86033b80 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) */ @@ -2868,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]);*/ @@ -2881,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]); diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index ec5cc6bcd6edd03e0c7853dd2a56bc096c53e8eb..e4299b6dda2d685304dc475931d0dcb56738852a 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 diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 373b8310880a2e7a7e4649a93dd2a4c533609083..18f61e15afbc6d55ae2d774ce47285df3287e1f0 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(); } diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 75152a28d9e655dba00785f50587ca479843ade7..e18b66d00dedf4afecce6a100151f6315d9a6d12 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1,1574 +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 *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) */ - L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ - - 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; -} +/*==================================================================================== + 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; +} diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index efa6af06f9f0f5d1601db3df60bfe6aad9ed872b..035e03000514164ba9d659ddf3098a3bfe972d99 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/cor_shif_fx.c b/lib_enc/cor_shif_fx.c index 94a1a58b7751b85f69ea27241f301c6520f6c8d7..7f2315512c15af5eaabbdbed2fbb5fcfd09076a3 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 af511b76d6a65f5cad34f8a7ee6bed1844c2d908..8cad74f964bf775fae4ff77a155202f484f658cf 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/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index 075b078ba3374ac79ba8e436683ad9c52cac7b3f..b7e8fbb21b7bc7a8871d0a8ee7299ae44fd55fa8 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/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index e74f2556b14a331d0213e39813eb870a65e0db40..1cf16e5d5d53e34b9ecb7580ae2a4d32925cf728 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 750a69b6610e9d2dc613552c233bfa4862b55654..6df5c076adfba790db56d347a5d9e3fc22bb2ebe 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 dedc4ff4b145ff4813da586e765d82d1915eab8c..f00b77b9f06d58d2943f1f65c7390283947d56b8 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; ivoicing_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,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 = -1; move16(); diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index dfdfda24e201c50d8f1c8cea12e7afff38168122..e18463c2e8178db531fe65b9538b4cc9243962b3 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/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index d37d3c2bcee01f06343a5ad62fc819efa345d622..5d6d2ed184e1b5d70d515a887138808694bf45f0 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -588,8 +588,11 @@ void gauss2v_fx( exp_num = sub(norm_s(enerw), 1); exp_den = norm_l(ener1); Num = shl(enerw, exp_num); - Den = round_fx(L_shl(ener1, exp_den)); - +#ifdef BASOP_NOGLOB + Den = round_fx_sat( L_shl_sat( ener1, exp_den ) ); +#else + Den = round_fx( L_shl( ener1, exp_den ) ); +#endif GainPortion2 = L_deposit_l(0); /* Unexpected division by zero. Eliminate this gain contribution */ IF (Den != 0) /* Protection against division by zero */ { diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index aec5d03eeebd1e14557e2066a1d87568a7dc58f9..6525f57f98a8ad5ffd0a372cc1138aeab161e40d 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/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 9c041f35c63eb7cc4ebcd9a3141e1732bff00772..4906be8fce2bc4977104f4950eba48d502515728 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -725,7 +725,11 @@ void hq_lr_enc_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); @@ -793,7 +797,11 @@ void hq_lr_enc_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); @@ -864,7 +872,11 @@ void hq_lr_enc_fx( move16(); FOR (i = 0; i < lowband; i++) { - tmp = extract_h(L_shl(Ep_avrgL_fx,1));/*Q0 */ +#ifdef BASOP_NOGLOB + tmp = extract_h( L_shl_sat( Ep_avrgL_fx, 1 ) ); /*Q0 */ +#else + tmp = extract_h( L_shl( Ep_avrgL_fx, 1 ) ); /*Q0 */ +#endif IF(tmp != 0) { exp = norm_s(tmp); diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 7e62c9b4a35fac78292e08204b52d2d93bbe41b2..7ff0116c407f9400d04fa9491f7b0e846b406cbc 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/ltd_stable_fx.c b/lib_enc/ltd_stable_fx.c index 5468becae3214fa870322c683ca260a30b95d71e..6f09f1089d085a5ef4e89e23ab8dcbd7a89d5c3d 100644 --- a/lib_enc/ltd_stable_fx.c +++ b/lib_enc/ltd_stable_fx.c @@ -195,7 +195,11 @@ void ltd_stable_fx( FOR(i=0; i<20; i++) { - tmp_mul = L_mult(tmp16[i],tmp16[i]); +#ifdef BASOP_NOGLOB + tmp_mul = L_mult_sat( tmp16[i], tmp16[i] ); +#else + tmp_mul = L_mult( tmp16[i], tmp16[i] ); +#endif tmp_mul = L_shr(tmp_mul,5); dif32 = L_add(dif32,tmp_mul); diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index 779fb8d158c63927ab7b10a56dd2f811252e6ece..1323bac5dc56c445d07bae75776e031a988959b4 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 } @@ -499,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++) @@ -617,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/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index 18224713ab7e280932943d16cabc24eab3018bae..34f8d257095abe3277ff330267041f572f366483 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -993,9 +993,13 @@ void norm_corr_fx( /* Normalize correlation = correlation * (1/sqrt(energy)) */ L_tmp = L_mult(corr, norm); - L_tmp = L_shl(L_tmp, add(add(exp_corr, exp_norm), scale)); - - ncorr[t] = round_fx(L_tmp); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, add( add( exp_corr, exp_norm ), scale ) ); + ncorr[t] = round_fx_sat( L_tmp ); +#else + L_tmp = L_shl( L_tmp, add( add( exp_corr, exp_norm ), scale ) ); + ncorr[t] = round_fx( L_tmp ); +#endif /* update the filtered excitation excf[] for the next iteration */ IF (NE_16(t, t_max)) diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index 4168016560fad7f814defa1bb5f9cbaea46e602a..91c6df713084d7d02a579f55fe6c4635a676dd09 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/q_gain2p_fx.c b/lib_enc/q_gain2p_fx.c index 61d5178e464be7ffe88f440e920ceb85555dbe4e..03fb36a8d1e69794fb7818b517ed7949173a3f4d 100644 --- a/lib_enc/q_gain2p_fx.c +++ b/lib_enc/q_gain2p_fx.c @@ -503,7 +503,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch index /* 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)); +#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); } ELSE diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index adbb356d5f9fb8eb62d0dbd22949eb9d08035a5e..ad603ae7e7d7a3ac820273b5f9b5554ac2234e01 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/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index edbfea956ac6ec798aaf4ba6fb805bdb58f52267..794d13bef662cb8172f5ba62c7008ae0f219e7d4 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/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index a79c6a58262ac009af14ade283ee055d327efa16..c3420d2e4c3708a054a98f562b9b76f0c1d90de0 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,12 +2706,20 @@ 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 */ } - 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 ee212a57bf4b710dfa11056e4948b5c7a5d52947..b53dc561049d889b94f439f52a21ab5517448f3e 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*/); @@ -1584,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 ); diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 4bc1335ac9a05b26631099c796fef623e862e2e1..c6bba4e12458e7b4bfbb73b8d5bf60d1459ac216 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 320b0e656a7ea2593145c06a2d6e943156fa7007..994ac19c3965e4f56c1b986ce873c902de93f251 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++); diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index d4013c0ace2e7447502ac04c8809518e108529a1..6b78ebc5846164901bee15ae32d4948e387012c7 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 9cab551c32b3ac24280146a4d48aad16f88dd9c3..bf1d685f71d492472d95af7179d8c59018120e4b 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); diff --git a/lib_enc/vlpc_1st_cod_fx.c b/lib_enc/vlpc_1st_cod_fx.c index cc54d3182c9dfd0a150ea01a93baf43076768478..7c633039bbf79f1ef0b470db6bc9213d7bf5e7b9 100644 --- a/lib_enc/vlpc_1st_cod_fx.c +++ b/lib_enc/vlpc_1st_cod_fx.c @@ -65,7 +65,11 @@ static void lsf_weight( w[i-1] = add(inv_di0,inv_di1); move16(); /*w[i-1] = inv_di0 + inv_di1;*/ inv_di0 = div_s(ISF_ONE, s_max(ISF_ONE, sub(FREQ_MAX,lsfq[i]))); /*inv_di0 = 1.0f / (FREQ_MAX - lsfq[i]);*/ - w[i] = add(inv_di1,inv_di0); +#ifdef BASOP_NOGLOB + w[i] = add_sat( inv_di1, inv_di0 ); +#else + w[i] = add( inv_di1, inv_di0 ); +#endif move16(); /*w[i] = inv_di1 + inv_di0;*/ BASOP_SATURATE_WARNING_ON_EVS