diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 5fd4b472ea59005fd821661a2d48d5aa0705c583..ee2bfd0fd4900e6a810754bf09bcbbeeb01542a2 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -29,7 +29,7 @@ Word32 expfp( /* o: Q31 */ xf = extract_l(L_tmp); BASOP_SATURATE_WARNING_OFF_EVS; - xf = negate(xf); + xf = negate( xf ); BASOP_SATURATE_WARNING_ON_EVS; /* Fractional part */ diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index bf25f1b0ccf25e4b89e4623688a507d3b9321328..37bf62d01c0420d44fcfbd21639c61fbf32fdbd4 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -370,7 +370,11 @@ static Word32 Sqrt32_common(Word32 m, if (m != 0) { BASOP_SATURATE_WARNING_OFF_EVS; - m = L_mac(SqrtTable[index], SqrtDiffTable[index], frac); +#ifdef BASOP_NOGLOB + m = L_mac_sat( SqrtTable[index], SqrtDiffTable[index], frac ); +#else + m = L_mac( SqrtTable[index], SqrtDiffTable[index], frac ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -654,8 +658,13 @@ void BASOP_Util_Sqrt_InvSqrt_MantExp(Word16 mantissa, /*!< mantissa */ /* interpolate */ BASOP_SATURATE_WARNING_OFF_EVS; - m = mac_r(SqrtTable[index], SqrtDiffTable[index], frac); +#ifdef BASOP_NOGLOB + m = mac_r_sat( SqrtTable[index], SqrtDiffTable[index], frac ); + mi = msu_r_sat(ISqrtTable[index], ISqrtDiffTable[index], frac); +#else + m = mac_r( SqrtTable[index], SqrtDiffTable[index], frac ); mi = msu_r(ISqrtTable[index], ISqrtDiffTable[index], frac); +#endif BASOP_SATURATE_WARNING_ON_EVS; /* handle even/odd exponents */ @@ -2035,7 +2044,11 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of compari } BASOP_SATURATE_WARNING_OFF_EVS - diff_m = L_sub(a_m, b_m); +#ifdef BASOP_NOGLOB + diff_m = L_sub_sat( a_m, b_m ); +#else + diff_m = L_sub( a_m, b_m ); +#endif BASOP_SATURATE_WARNING_ON_EVS diff_e = sub(a_e, b_e); diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index f276062739c8ae7a1818a2b6bcaa8e81374b1d82..8cb434f722c384725f33632457ca1226d1ebc6b8 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -371,8 +371,11 @@ Word16 BitAllocF_fx ( exp1 = sub(norm_l(L_tmp1), 1); exp2 = norm_s(n); tmp = div_s(extract_h(L_shl(L_tmp1, exp1)), shl(n, exp2));/*15 + 15 + exp1 - 16 - exp2*/ - m_fx = shl(tmp, sub(exp2, exp1));/*Q14*/ - +#ifdef BASOP_NOGLOB + m_fx = shl_sat( tmp, sub( exp2, exp1 ) ); /*Q14*/ +#else + m_fx = shl( tmp, sub( exp2, exp1 ) ); /*Q14*/ +#endif t_fx = L_deposit_l(0); n = 0; move16(); diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 63b3030fae3d9ed303e39c5602988a81f839ab58..d98c33b5bc7271e8d7a7cd566b1054d1b630cf9d 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -505,7 +505,11 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, /* move and scale filter states */ FOR (i=0; iFilterStates_eg); FOR (i=0; ino_channels; j++) { - rSubband16[i][j] = round_fx(L_shl(rSubband32[i][j], headRoom)); +#ifdef BASOP_NOGLOB + rSubband16[i][j] = round_fx_sat( L_shl_sat( rSubband32[i][j], headRoom ) ); + iSubband16[i][j] = round_fx_sat(L_shl_sat(iSubband32[i][j], headRoom)); +#else + rSubband16[i][j] = round_fx( L_shl( rSubband32[i][j], headRoom ) ); iSubband16[i][j] = round_fx(L_shl(iSubband32[i][j], headRoom)); +#endif } } @@ -1404,8 +1417,13 @@ GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | p sm = sub(s_min(s, 44), 1); BASOP_SATURATE_WARNING_OFF_EVS /* nrg + 6.1e-5f => value 0x40000000, scale 44 */ - *energyLookahead = L_add(L_shr(nrg, sub(s, sm)), +#ifdef BASOP_NOGLOB + *energyLookahead = L_add_sat( L_shr_sat( nrg, sub( s, sm ) ), + L_shr_sat(0x40000000, s_max(-31, s_min(31, sub(44, sm))))); +#else + *energyLookahead = L_add( L_shr( nrg, sub( s, sm ) ), L_shr(0x40000000, s_max(-31, s_min(31, sub(44, sm))))); +#endif move32(); BASOP_SATURATE_WARNING_ON_EVS *sf_energyLookahead = sm; diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 3873a8eb5255a3048505f7dc5949ea41a046511b..e396128cb1b6eca88c5a35735abe9e7d737419ac 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -199,7 +199,11 @@ void CNG_exc_fx( *------------------------------------------------------------*/ L_tmp = Mult_32_16(*lp_ener, Random(cng_ener_seed)); L_tmp = Mult_32_16(L_tmp, GAIN_VAR); - L_tmp = L_add(L_tmp, *lp_ener); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, *lp_ener ); +#else + L_tmp = L_add( L_tmp, *lp_ener ); +#endif L_tmp = L_max(L_tmp, 1); /* enr = dot_product( exc2, exc2, L_SUBFR ) + 0.01f */ @@ -327,7 +331,11 @@ void CNG_exc_fx( #endif L_tmp = L_shr(L_tmp,1);/* 2*Q_exc+6 */ tmp = add(Q_exc,Q_exc); - env[i] = L_shr(L_tmp,tmp); +#ifdef BASOP_NOGLOB + env[i] = L_shr_sat( L_tmp, tmp ); +#else + env[i] = L_shr( L_tmp, tmp ); +#endif move32();/* Q6 */ ptR++; ptI--; @@ -336,8 +344,13 @@ void CNG_exc_fx( FOR ( i=0; i Q25 */ L_tmp = L_msu(L_tmp, code[1], tmp); /* Q12 * Q15 -> Q28 */ - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); + pt_exc2[0] = msu_r_sat(L_tmp, -32768, pt_exc2[0]); +#else + L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); pt_exc2[0] = msu_r(L_tmp, -32768, pt_exc2[0]); +#endif move16();/* in Q_exc */ FOR (i = 1; i < L_SUBFR-1; i++) @@ -243,11 +248,13 @@ void enhancer_fx( /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */ L_tmp = L_msu(-32768, code[i], -32768); 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); #ifdef BASOP_NOGLOB + tmp16 = msu_r_sat( L_tmp, code[i - 1], tmp ); + L_tmp = L_shl_sat( L_mult( gain_code_hi, tmp16 ), sc ); pt_exc2[i] = msu_r_sat( L_tmp, -32768, pt_exc2[i] ); #else + 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] ); #endif move16(); /* in Q_exc */ @@ -257,7 +264,11 @@ void enhancer_fx( L_tmp = L_deposit_h(code[L_SUBFR - 1]);/*Q28 */ L_tmp = L_msu(L_tmp, code[L_SUBFR - 2], tmp);/*Q28 */ L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); - pt_exc2[L_SUBFR - 1] = msu_r(L_tmp, -32768, pt_exc2[L_SUBFR - 1]); +#ifdef BASOP_NOGLOB + pt_exc2[L_SUBFR - 1] = msu_r_sat( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); +#else + pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); +#endif move16();/* in Q_exc */ test(); test(); @@ -268,7 +279,11 @@ void enhancer_fx( FOR (i = 0; i < L_SUBFR; i++) { /* excp[i] += pt_exc2[i] */ - excp[i] = add(excp[i], pt_exc2[i]); +#ifdef BASOP_NOGLOB + excp[i] = add_sat( excp[i], pt_exc2[i] ); +#else + excp[i] = add( excp[i], pt_exc2[i] ); +#endif move16(); } agc2_fx(pt_exc2, excp, L_SUBFR); @@ -694,9 +709,17 @@ Word16 E_UTIL_enhancer( L_tmp = L_msu0(L_tmp,tmp,code[1]); if (gain) { - L_tmp = L_shl(L_tmp,gain); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, gain ); +#else + L_tmp = L_shl( L_tmp, gain ); +#endif } - exc2[0] = msu_r(L_tmp,-32768, exc2[0]); +#ifdef BASOP_NOGLOB + exc2[0] = msu_r_sat( L_tmp, -32768, exc2[0] ); +#else + exc2[0] = msu_r( L_tmp, -32768, exc2[0] ); +#endif move16(); FOR (i=1; i= 0) { ener = L_shr(ener,1); - tmp = L_shr(tmp, add(1,i)); +#ifdef BASOP_NOGLOB + tmp = L_shr_sat( tmp, add( 1, i ) ); +#else + tmp = L_shr( tmp, add( 1, i ) ); +#endif } ELSE { tmp = L_shr(tmp,1); BASOP_SATURATE_WARNING_OFF_EVS - ener = L_shr(ener, sub(1,i)); +#ifdef BASOP_NOGLOB + ener = L_shr_sat( ener, sub( 1, i ) ); +#else + ener = L_shr( ener, sub( 1, i ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS } diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index 9dec4315fa678832cad775d993a1d874600e8085..db7e290dcdbaff1b87c03cf22e77ad46996a96c8 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -1071,7 +1071,11 @@ static void fft5_shift4_16fx( move16(); T3 = zRe[i4]; move16(); - T4 = add(T2,T3); +#ifdef BASOP_NOGLOB + T4 = add_sat( T2, T3 ); +#else + T4 = add( T2, T3 ); +#endif T5 = zRe[i2]; move16(); T6 = zRe[i3]; @@ -1179,13 +1183,19 @@ static void fft5_shift4_16fx( /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ L_tmp = Mult_32_16(KP951056516_16FX,Ts); L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Tt); - T2 = round_fx(L_tmp); - +#ifdef BASOP_NOGLOB + T2 = round_fx_sat( L_tmp ); +#else + T2 = round_fx( L_tmp ); +#endif /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ L_tmp = Mult_32_16(KP951056516_16FX,Tt); L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Ts); - T3 = round_fx(L_tmp); - +#ifdef BASOP_NOGLOB + T3 = round_fx_sat( L_tmp ); +#else + T3 = round_fx( L_tmp ); +#endif #ifdef BASOP_NOGLOB T6 = sub_sat(To, shr(Tp, 2)); T4 = add_sat(Tn, T6); @@ -2779,7 +2789,11 @@ void fft3_fx(const Word16 X[], Word16 Y[], const Word16 n) /* special case: i = 0 */ acc = L_mult(*RZ0++, 0x4000); acc = L_mac(acc, *RZ1++, 0x4000); - *RY++ = mac_r(acc, *RZ2++, 0x4000); +#ifdef BASOP_NOGLOB + *RY++ = mac_r_sat( acc, *RZ2++, 0x4000 ); +#else + *RY++ = mac_r( acc, *RZ2++, 0x4000 ); +#endif move16(); /* first 3/12-- from 1 to (3*m/8)-1 */ diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index 49ae18103101735700607077270b7691047e145f..4a85f485d64657597a83e66ffdb691336ef0db0f 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -132,46 +132,84 @@ static void c_fft_fx( input_ptr1 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); - tmp1 = msu_r(L_tmp1, *input_ptr1, 16384); +#ifdef BASOP_NOGLOB + tmp1 = msu_r_sat( L_tmp1, *input_ptr1, 16384 ); + tmp3 = mac_r_sat(L_tmp1, *input_ptr1++, 16384); +#else + tmp1 = msu_r( L_tmp1, *input_ptr1, 16384 ); tmp3 = mac_r(L_tmp1, *input_ptr1++, 16384); - +#endif input_ptr2 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); input_ptr3 = in_ptr + (const Word16)((uintptr_t)(*table_ptr++) >> (uintptr_t)shift); L_tmp1 = L_mult(*input_ptr2++, 16384); - tmp2 = mac_r(L_tmp1, *input_ptr3, 16384); +#ifdef BASOP_NOGLOB + tmp2 = mac_r_sat( L_tmp1, *input_ptr3, 16384 ); + tmp4 = msu_r_sat(L_tmp1, *input_ptr3++, 16384); +#else + tmp2 = mac_r( L_tmp1, *input_ptr3, 16384 ); tmp4 = msu_r(L_tmp1, *input_ptr3++, 16384); - +#endif L_tmp1 = L_mult(tmp3, 16384); - out_ptr[k] = mac_r(L_tmp1, tmp2, 16384); +#ifdef BASOP_NOGLOB + out_ptr[k] = mac_r_sat( L_tmp1, tmp2, 16384 ); + move16(); + out_ptr[k+4] = msu_r_sat(L_tmp1, tmp2, 16384); + move16(); + + tmp2 = mac_r_sat(L_tmp2, *input_ptr1, 16384); + tmp3 = msu_r_sat(L_tmp2, *input_ptr1, 16384); +#else + out_ptr[k] = mac_r( L_tmp1, tmp2, 16384 ); move16(); out_ptr[k+4] = msu_r(L_tmp1, tmp2, 16384); move16(); tmp2 = mac_r(L_tmp2, *input_ptr1, 16384); tmp3 = msu_r(L_tmp2, *input_ptr1, 16384); - +#endif L_tmp2 = L_mult(*input_ptr2, 16384); L_tmp1 = L_mult(tmp1, 16384); - tmp1 = msu_r(L_tmp2, *input_ptr3, 16384); +#ifdef BASOP_NOGLOB + tmp1 = msu_r_sat( L_tmp2, *input_ptr3, 16384 ); + out_ptr[k + 2] = mac_r_sat( L_tmp1, tmp1, 16384 ); + move16(); + out_ptr[k + 6] = msu_r_sat( L_tmp1, tmp1, 16384 ); + move16(); +#else + tmp1 = msu_r( L_tmp2, *input_ptr3, 16384 ); out_ptr[k+2] = mac_r(L_tmp1, tmp1, 16384); move16(); out_ptr[k+6] = msu_r(L_tmp1, tmp1, 16384); move16(); - +#endif L_tmp1 = L_mult(tmp2, 16384); - tmp2 = mac_r(L_tmp2, *input_ptr3, 16384); +#ifdef BASOP_NOGLOB + tmp2 = mac_r_sat( L_tmp2, *input_ptr3, 16384 ); + out_ptr[k+1] = mac_r_sat(L_tmp1, tmp2, 16384); + move16(); + out_ptr[k+5] = msu_r_sat(L_tmp1, tmp2, 16384); + move16(); +#else + tmp2 = mac_r( L_tmp2, *input_ptr3, 16384 ); out_ptr[k+1] = mac_r(L_tmp1, tmp2, 16384); move16(); out_ptr[k+5] = msu_r(L_tmp1, tmp2, 16384); move16(); - +#endif L_tmp1 = L_mult(tmp3, 16384); - out_ptr[k+3] = msu_r(L_tmp1, tmp4, 16384); +#ifdef BASOP_NOGLOB + out_ptr[k + 3] = msu_r_sat( L_tmp1, tmp4, 16384 ); + move16(); + out_ptr[k+7] = mac_r_sat(L_tmp1, tmp4, 16384); + move16(); +#else + out_ptr[k + 3] = msu_r( L_tmp1, tmp4, 16384 ); move16(); out_ptr[k+7] = mac_r(L_tmp1, tmp4, 16384); move16(); +#endif } /* Remaining Stages */ @@ -378,8 +416,28 @@ void r_fft_fx_lc( FOR (i = 2; i <= SIZE2; i += 2) { Ltmp1_imag = L_mult(temp[i+1], 16384); - Ltmp1_imag = L_msu(Ltmp1_imag, *ptrDn, 16384); - tmp2_real = add(temp[i+1], *ptrDn--); +#ifdef BASOP_NOGLOB + Ltmp1_imag = L_msu_sat( Ltmp1_imag, *ptrDn, 16384 ); + tmp2_real = add_sat( temp[i + 1], *ptrDn-- ); + + Ltmp1_real = L_mult(temp[i], 16384); + Ltmp1_real = L_mac_sat( Ltmp1_real, *ptrDn, 16384 ); + tmp2_imag = sub(*ptrDn--, temp[i]); + + + *ptRealUp++ = msu_r_sat( L_mac_sat( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); + move16(); + *ptImaDn-- = mac_r_sat( L_mac_sat( Ltmp1_imag, tmp2_imag, phs_tbl[i] ), tmp2_real, phs_tbl[i + 1] ); + move16(); + Ltmp1 = L_mac_sat( L_negate( Ltmp1_imag ), tmp2_real, *phstbl_ptrDn ); + Ltmp1_real = L_mac_sat( Ltmp1_real, tmp2_imag, *phstbl_ptrDn-- ); + *ptImaUp++ = msu_r_sat( Ltmp1, tmp2_imag, *phstbl_ptrDn ); + move16(); + *ptRealDn-- = mac_r_sat( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); + move16(); +#else + Ltmp1_imag = L_msu( Ltmp1_imag, *ptrDn, 16384 ); + tmp2_real = add( temp[i + 1], *ptrDn-- ); Ltmp1_real = L_mult(temp[i], 16384); Ltmp1_real = L_mac(Ltmp1_real, *ptrDn, 16384); @@ -396,6 +454,7 @@ void r_fft_fx_lc( move16(); *ptRealDn-- = mac_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); move16(); +#endif } } ELSE /* The ifFT part */ @@ -423,15 +482,31 @@ void r_fft_fx_lc( /* Now, handle the remaining positive frequencies */ FOR (i = 2; i <= SIZE2; i += 2) { - Ltmp1_imag = L_mult(*ptImaDn, 16384); - Ltmp1_imag = L_msu(Ltmp1_imag, *ptImaUp, 16384); - tmp2_real = add(*ptImaDn--, *ptImaUp++); - Ltmp1_real = L_mult(*ptRealUp, 16384); - Ltmp1_real = L_mac(Ltmp1_real, *ptRealDn, 16384); - tmp2_imag = sub(*ptRealUp++, *ptRealDn--); - - - temp[i] = mac_r(L_msu(Ltmp1_real, tmp2_real, phs_tbl[i]), tmp2_imag, phs_tbl[i+1]); +#ifdef BASOP_NOGLOB + Ltmp1_imag = L_mult( *ptImaDn, 16384 ); + Ltmp1_imag = L_msu_sat( Ltmp1_imag, *ptImaUp, 16384 ); + tmp2_real = add_sat( *ptImaDn--, *ptImaUp++ ); + Ltmp1_real = L_mult( *ptRealUp, 16384 ); + Ltmp1_real = L_mac_sat( Ltmp1_real, *ptRealDn, 16384 ); + tmp2_imag = sub_sat( *ptRealUp++, *ptRealDn-- ); + temp[i] = mac_r_sat( L_msu_sat( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); + move16(); + temp[i + 1] = mac_r_sat( L_mac_sat( Ltmp1_imag, tmp2_imag, phs_tbl[i] ), tmp2_real, phs_tbl[i + 1] ); + move16(); + Ltmp1 = L_mac_sat( L_negate( Ltmp1_imag ), tmp2_real, *phstbl_ptrDn ); + Ltmp1_real = L_msu_sat( Ltmp1_real, tmp2_imag, *phstbl_ptrDn-- ); + *ptrDn-- = msu_r_sat( Ltmp1, tmp2_imag, *phstbl_ptrDn ); + move16(); + *ptrDn-- = msu_r_sat( Ltmp1_real, tmp2_real, *phstbl_ptrDn-- ); + move16(); +#else + Ltmp1_imag = L_mult( *ptImaDn, 16384 ); + Ltmp1_imag = L_msu( Ltmp1_imag, *ptImaUp, 16384 ); + tmp2_real = add( *ptImaDn--, *ptImaUp++ ); + Ltmp1_real = L_mult( *ptRealUp, 16384 ); + Ltmp1_real = L_mac( Ltmp1_real, *ptRealDn, 16384 ); + tmp2_imag = sub( *ptRealUp++, *ptRealDn-- ); + temp[i] = mac_r( L_msu( Ltmp1_real, tmp2_real, phs_tbl[i] ), tmp2_imag, phs_tbl[i + 1] ); move16(); temp[i+1] = mac_r(L_mac(Ltmp1_imag, tmp2_imag, phs_tbl[i]), tmp2_real, phs_tbl[i+1]); move16(); @@ -441,6 +516,7 @@ void r_fft_fx_lc( move16(); *ptrDn-- = msu_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); move16(); +#endif } /* Perform the complex ifFT */ diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 8a52a8efcbeb14180e45dc6f63afe612a127937b..888e1bc4527a3637ab52a1793fac8f093897e381 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -129,8 +129,13 @@ void Inac_swtch_ematch_fx( FOR (j = 0; j < 8; j ++) { L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ + *pt_exc = round_fx_sat(L_tmp); +#else + L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ *pt_exc = round_fx(L_tmp); +#endif pt_exc++; } } @@ -139,8 +144,13 @@ void Inac_swtch_ematch_fx( FOR (j = 0; j < 16; j ++) { L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ + *pt_exc = round_fx_sat(L_tmp); /*Q_exc*/ +#else + L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ *pt_exc = round_fx(L_tmp); /*Q_exc*/ +#endif pt_exc++; } } diff --git a/lib_com/hp50.c b/lib_com/hp50.c index 0f950af36356a8fc07ad19729659fc8779f1247d..eb96f2a40f8bf9de4ed3558a409b5eae19c3f67f 100644 --- a/lib_com/hp50.c +++ b/lib_com/hp50.c @@ -322,7 +322,11 @@ void hp20(Word16 signal[], /* i/o: signal to filter any * prescale = getScaleFactor16(signal, lg); prescaleOld = extract_l(mem[4]); - diff = norm_l(L_shl(mem[2], prescaleOld)); +#ifdef BASOP_NOGLOB + diff = norm_l( L_shl_sat( mem[2], prescaleOld ) ); +#else + diff = norm_l( L_shl( mem[2], prescaleOld ) ); +#endif if (mem[2] != 0) { prescale = s_min(prescale, diff); diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index f83584a06bd10dbfe840188847e4ceb88bb9d1c3..7cd26fa39e5cab47d30cb69e8eade77b5e824356 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -450,7 +450,11 @@ void hq2_noise_inject_fx( tmp = sub(Q_env_fx[k],Q_Ep_fx[k]); tmp = sub(tmp,Q_speech); tmp = add(tmp,25); - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ +#else + L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ +#endif tmp = extract_l(L_min(L_tmp,192));/* */ fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ } @@ -460,7 +464,11 @@ void hq2_noise_inject_fx( L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */ L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */ tmp = sub(Q_env_fx[k],23); - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */ +#else + L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ +#endif tmp = extract_l((L_min(L_tmp,192)));/* */ fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ } diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 88b4340a4b5ae1586a353991e9bc173047c54832..89d127c8a5747974e0782dd1d00cfa50aaf58cfc 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -88,7 +88,11 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { L_tmp = L_abs(L_SWB_signal[n_lag]); - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); +#ifdef BASOP_NOGLOB + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); +#else + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); +#endif move32(); } env_index = add(env_index, 1); @@ -105,7 +109,11 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { L_tmp = L_abs(L_SWB_signal[add(n_freq, n_lag)]); - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); +#ifdef BASOP_NOGLOB + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); +#else + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); +#endif move32(); } env_index = add(env_index, 1); @@ -122,7 +130,11 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) { L_tmp = L_abs(L_SWB_signal[add(n_freq, n_lag)]); - L_envelope[env_index] = L_add(L_envelope[env_index], L_tmp); +#ifdef BASOP_NOGLOB + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); +#else + L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); +#endif move32(); } env_index = add(env_index, 1); @@ -2336,7 +2348,11 @@ void hq_wb_nf_bwe_fx( #endif } - IF(GT_32(L_tmp2, L_shl(min_coef_fx, sub(exp, 13))))/*exp */ +#ifdef BASOP_NOGLOB + IF( GT_32( L_tmp2, L_shl_sat( min_coef_fx, sub( exp, 13 ) ) ) ) /*exp */ +#else + IF( GT_32( L_tmp2, L_shl( min_coef_fx, sub( exp, 13 ) ) ) ) /*exp */ +#endif { L_tmp2 = L_shr(min_coef_fx, 1); exp = 12; @@ -2353,7 +2369,11 @@ void hq_wb_nf_bwe_fx( /* smooth the noise magnitudes between inter-frame */ test(); test(); - IF(GT_32(prev_avrg_norm_fx, L_shr(avrg_norm_fx, 1)) && LT_32(prev_avrg_norm_fx, L_shl(avrg_norm_fx, 1)) && prev_is_transient == 0) +#ifdef BASOP_NOGLOB + IF( GT_32( prev_avrg_norm_fx, L_shr( avrg_norm_fx, 1 ) ) && LT_32( prev_avrg_norm_fx, L_shl_sat( avrg_norm_fx, 1 ) ) && prev_is_transient == 0 ) +#else + IF( GT_32( prev_avrg_norm_fx, L_shr( avrg_norm_fx, 1 ) ) && LT_32( prev_avrg_norm_fx, L_shl( avrg_norm_fx, 1 ) ) && prev_is_transient == 0 ) +#endif { exp1 = norm_l(prev_env_fx[sfm]); L_tmp1 = L_shl(prev_env_fx[sfm], exp1);/* prev_env_Q[sfm] +exp1 */ @@ -2411,8 +2431,13 @@ void hq_wb_nf_bwe_fx( test(); test(); test(); - IF(EQ_16(sfm, sub(SFM_N_WB, 1)) && prev_is_transient == 0 && GT_32(prev_normq_fx[sfm], L_shr(L_normq_v[sfm], 1)) +#ifdef BASOP_NOGLOB + IF( EQ_16( sfm, sub( SFM_N_WB, 1 ) ) && prev_is_transient == 0 && GT_32( prev_normq_fx[sfm], L_shr( L_normq_v[sfm], 1 ) ) + && LT_32(prev_normq_fx[sfm], L_shl_sat(L_normq_v[sfm], 1)) && LE_16(bitalloc_var_fx, 4915)) +#else + IF( EQ_16( sfm, sub( SFM_N_WB, 1 ) ) && prev_is_transient == 0 && GT_32( prev_normq_fx[sfm], L_shr( L_normq_v[sfm], 1 ) ) && LT_32(prev_normq_fx[sfm], L_shl(L_normq_v[sfm], 1)) && LE_16(bitalloc_var_fx, 4915)) +#endif { Word32 *p_prev_coeff_out = prev_coeff_out_fx; FOR(i = add(sfm_start[sfm], 12); i < sfm_end[sfm]; i++) @@ -2421,12 +2446,21 @@ void hq_wb_nf_bwe_fx( test(); test(); test(); - IF(GT_32(L_abs(L_coeff_out[i]), L_shl(L_abs(*p_prev_coeff_out), 2)) +#ifdef BASOP_NOGLOB + IF( GT_32( L_abs( L_coeff_out[i] ), L_shl_sat( L_abs( *p_prev_coeff_out ), 2 ) ) + || LT_32(L_abs(L_coeff_out[i]), L_shr(L_abs(*p_prev_coeff_out), 2)) + || ((R[sfm] == 0 || *prev_R == 0) && add_sat(R[sfm], *prev_R) != 0)) +#else + IF( GT_32( L_abs( L_coeff_out[i] ), L_shl( L_abs( *p_prev_coeff_out ), 2 ) ) || LT_32(L_abs(L_coeff_out[i]), L_shr(L_abs(*p_prev_coeff_out), 2)) || ((R[sfm] == 0 || *prev_R == 0) && add(R[sfm], *prev_R) != 0)) +#endif { - L_tmp = L_add(L_shr(L_abs(L_coeff_out[i]), 1), L_shr(L_abs(*p_prev_coeff_out), 1)); - +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); +#else + L_tmp = L_add( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); +#endif if (L_coeff_out[i] <= 0) { L_tmp = L_negate(L_tmp); diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index c10429a844af295aaafb1c68cc9ee7e9627feedd..14d21b7e9ee21c945b0542d4c45663946ba3e0d5 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -1116,7 +1116,11 @@ void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, FOR (i = sqrtBgn; i < sqrtEnd; i++) { - tmp = round_fx(L_shl(mdctSpec[i], s1)); +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); +#else + tmp = round_fx( L_shl( mdctSpec[i], s1 ) ); +#endif mdctSquareSpec[j++] = L_mult0(tmp, tmp); move32(); } diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index 1733137c744dc38fab9d76c2883bfd455a5c9832..162459de96573d9e2ae999849009c49592cd99cf 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -1404,8 +1404,13 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 * Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i])); Word16 ImBr = extract_h((L_negate(L_add(ImagFFT[i], ImagFFT[N/2-i])))); BASOP_SATURATE_WARNING_OFF_EVS - tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im); +#ifdef BASOP_NOGLOB + tmpw15.v.re = mac_r_sat( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); + tmpw15.v.im = msu_r_sat(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); +#else + tmpw15.v.re = mac_r( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); +#endif BASOP_SATURATE_WARNING_ON_EVS RealOut[i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); move16(); diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index 24586a23c9024ad4cfc53201585e21dbd62fd2f7..b2e8d8b0ccaba9753f27465daec1737b1782b571 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -159,7 +159,7 @@ static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift) BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - t0 = L_shl_o(t0, shift, &Overflow); /* Qx to Q30 with saturation */ + t0 = L_shl_o(t0, shift, &Overflow); /* Qx to Q30 with saturation */ cheb = round_fx_o(t0, &Overflow); /* Result in Q14 */ #else /* BASOP_NOGLOB */ t0 = L_shl(t0, shift); /* Qx to Q30 with saturation */ @@ -2534,7 +2534,11 @@ void lsf2lsp_fx( { offset = negate(offset); } - L_tmp = L_mult(sub(offset, lsf_tmp), round_fx(L_shl(L_and(L_tmp, 0xFFFF), 15))); +#ifdef BASOP_NOGLOB + L_tmp = L_mult( sub_sat( offset, lsf_tmp ), round_fx( L_shl( L_and( L_tmp, 0xFFFF ), 15 ) ) ); +#else + L_tmp = L_mult( sub( offset, lsf_tmp ), round_fx( L_shl( L_and( L_tmp, 0xFFFF ), 15 ) ) ); +#endif L_tmp = L_msu(L_tmp, lsf_tmp, -32768); lsp[i] = round_fx(L_tmp); } diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 7d42b2689db710100f1a1b43791b31f9c4ce84a5..2693a74cb52ba00a64e957d7a7f286d74ab5a92d 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -207,8 +207,13 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigPtr = signal_fx+lg+mem_len+i; move16(); /*+i*/ L_tmp = syn_kern_16(0, A_fx, sigPtr); - L_tmp = L_shl(L_tmp, 3); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 3 ); + *sigPtr = round_fx_sat(L_tmp); /* AZ ringing padding */ +#else + L_tmp = L_shl( L_tmp, 3 ); *sigPtr = round_fx(L_tmp); /* AZ ringing padding */ +#endif } mem_preemph_fx = signal_fx[mem_len+lg-LEN_WIN_SSS - 1]; move16(); @@ -232,8 +237,11 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR(i=0; ifilter_fx, frac, fac_num, filt_len_tmp )); - +#ifdef BASOP_NOGLOB + sigOut_fx[i] = round_fx_sat( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); +#else + sigOut_fx[i] = round_fx( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); +#endif frac = add(frac,fracstep); j = sub(fac_num, frac); @@ -747,7 +755,12 @@ void Decimate_allpass_steep_fx( mem[ 2*ALLPASSSECTIONS_STEEP-1 ] = extract_h( Lacc1 ); /* Qx */ sum = mult_r( out_fx[0], 16384 ); /* Qx */ - out_fx[0] = add( sum, mult_r(temp[ALLPASSSECTIONS_STEEP-1], 16384 )); /* Qx */ move16(); +#ifdef BASOP_NOGLOB + out_fx[0] = add_sat( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ +#else + out_fx[0] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ +#endif + move16(); FOR ( k = 1; k < N/2; k++) @@ -807,7 +820,11 @@ void Decimate_allpass_steep_fx( sum = mult_r( out_fx[k], 16384 ); /* Qx */ - out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP-1], 16384 ) ); +#ifdef BASOP_NOGLOB + out_fx[k] = add_sat( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); +#else + out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); +#endif move16(); /* Qx */ } @@ -1228,11 +1245,23 @@ void interpolate_3_over_1_allpass_fx( Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] ); mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] );*/ - Vu[0] = add(mem_fx[0], mult_r(filt_coeff_fx[0], sub(input_fx[i], mem_fx[1]))); +#ifdef BASOP_NOGLOB + Vu[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[0], sub_sat( input_fx[i], mem_fx[1] ) ) ); +#else + Vu[0] = add( mem_fx[0], mult_r( filt_coeff_fx[0], sub( input_fx[i], mem_fx[1] ) ) ); +#endif move16();/* all Vu's in : Q_current*/ - Vu[1] = add(mem_fx[1], mult_r(filt_coeff_fx[1], sub(Vu[0], mem_fx[2]))); +#ifdef BASOP_NOGLOB + Vu[1] = add_sat( mem_fx[1], mult_r( filt_coeff_fx[1], sub_sat( Vu[0], mem_fx[2] ) ) ); +#else + Vu[1] = add( mem_fx[1], mult_r( filt_coeff_fx[1], sub( Vu[0], mem_fx[2] ) ) ); +#endif move16(); - mem_fx[3] = add(mem_fx[2], mult_r(filt_coeff_fx[2], sub(Vu[1], mem_fx[3]))); +#ifdef BASOP_NOGLOB + mem_fx[3] = add_sat( mem_fx[2], mult_r( filt_coeff_fx[2], sub_sat( Vu[1], mem_fx[3] ) ) ); +#else + mem_fx[3] = add( mem_fx[2], mult_r( filt_coeff_fx[2], sub( Vu[1], mem_fx[3] ) ) ); +#endif move16(); @@ -1247,9 +1276,17 @@ void interpolate_3_over_1_allpass_fx( /* Vm[0] = mem[0] + filt_coeff[3] * (input[i]-mem[4]); Vm[1] = mem[4] + filt_coeff[4] * (Vm[0]-mem[5]); mem[6] = mem[5] + filt_coeff[5] * (Vm[1]-mem[6]); */ - Vm[0] = add(mem_fx[0], mult_r(filt_coeff_fx[3], sub(input_fx[i], mem_fx[4]))); +#ifdef BASOP_NOGLOB + Vm[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[3], sub_sat( input_fx[i], mem_fx[4] ) ) ); +#else + Vm[0] = add( mem_fx[0], mult_r( filt_coeff_fx[3], sub( input_fx[i], mem_fx[4] ) ) ); +#endif move16(); - Vm[1] = add(mem_fx[4], mult_r(filt_coeff_fx[4], sub(Vm[0], mem_fx[5]))); +#ifdef BASOP_NOGLOB + Vm[1] = add_sat( mem_fx[4], mult_r( filt_coeff_fx[4], sub_sat( Vm[0], mem_fx[5] ) ) ); +#else + Vm[1] = add( mem_fx[4], mult_r( filt_coeff_fx[4], sub( Vm[0], mem_fx[5] ) ) ); +#endif move16(); #ifdef BASOP_NOGLOB mem_fx[6] = add_sat( mem_fx[5], mult_r( filt_coeff_fx[5], sub_sat( Vm[1], mem_fx[6] ) ) ); @@ -1269,9 +1306,17 @@ void interpolate_3_over_1_allpass_fx( /* Vl[0] = mem[0] + filt_coeff[6] * (input[i]-mem[7]); Vl[1] = mem[7] + filt_coeff[7] * (Vl[0]-mem[8]); mem[9] = mem[8] + filt_coeff[8] * (Vl[1]-mem[9]); */ - Vl[0] = add(mem_fx[0], mult_r(filt_coeff_fx[6], sub(input_fx[i], mem_fx[7]))); +#ifdef BASOP_NOGLOB + Vl[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[6], sub_sat( input_fx[i], mem_fx[7] ) ) ); +#else + Vl[0] = add( mem_fx[0], mult_r( filt_coeff_fx[6], sub( input_fx[i], mem_fx[7] ) ) ); +#endif move16(); - Vl[1] = add(mem_fx[7], mult_r(filt_coeff_fx[7], sub(Vl[0], mem_fx[8]))); +#ifdef BASOP_NOGLOB + Vl[1] = add_sat( mem_fx[7], mult_r( filt_coeff_fx[7], sub_sat( Vl[0], mem_fx[8] ) ) ); +#else + Vl[1] = add( mem_fx[7], mult_r( filt_coeff_fx[7], sub( Vl[0], mem_fx[8] ) ) ); +#endif move16(); #ifdef BASOP_NOGLOB mem_fx[9] = add_sat( mem_fx[8], mult_r( filt_coeff_fx[8], sub_sat( Vl[1], mem_fx[9] ) ) ); @@ -1294,7 +1339,11 @@ void interpolate_3_over_1_allpass_fx( { mem_temp = out_fx[i]; move16(); - out_fx[i] = sub(mult_r(18768/*0.57276865021499168f Q15*/, add(mem_fx[12], mem_fx[11])), mult_r(2425/*0.074004974641176793f Q15*/,add(mem_temp,mem_fx[10]))); +#ifdef BASOP_NOGLOB + out_fx[i] = sub_sat( mult_r( 18768 /*0.57276865021499168f Q15*/, add_sat( mem_fx[12], mem_fx[11] ) ), mult_r( 2425 /*0.074004974641176793f Q15*/, add_sat( mem_temp, mem_fx[10] ) ) ); +#else + out_fx[i] = sub( mult_r( 18768 /*0.57276865021499168f Q15*/, add( mem_fx[12], mem_fx[11] ) ), mult_r( 2425 /*0.074004974641176793f Q15*/, add( mem_temp, mem_fx[10] ) ) ); +#endif mem_fx[10] = mem_fx[11]; move16(); mem_fx[11] = mem_fx[12]; diff --git a/lib_com/oper_32b.c b/lib_com/oper_32b.c index de85bc267e058523a64a78f9d61e36fbba89d7f9..821a4f82ddc7d0b6e72ba896b6b4ca081bb7e4c6 100644 --- a/lib_com/oper_32b.c +++ b/lib_com/oper_32b.c @@ -400,8 +400,11 @@ Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo) lo = L_Extract_lc (L_32, &hi); n_lo = L_Extract_lc (L_num, &n_hi); L_32 = Mpy_32 (n_hi, n_lo, hi, lo); - L_32 = L_shl (L_32, 2); - +#ifdef BASOP_NOGLOB + L_32 = L_shl_sat( L_32, 2 ); +#else + L_32 = L_shl( L_32, 2 ); +#endif return (L_32); } diff --git a/lib_com/re8_util_fx.c b/lib_com/re8_util_fx.c index 012441be69dba9f9496f634b0b030449990a2d15..8526ddc24d36f2ef0360eac2f93f26dc1174dd74 100644 --- a/lib_com/re8_util_fx.c +++ b/lib_com/re8_util_fx.c @@ -276,8 +276,11 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y i { Ls = L_mac( Ls, y[i], y[i]); } - s = extract_h(L_shl(Ls, 16-(3+1))); /* s can saturate here */ - +#ifdef BASOP_NOGLOB + s = extract_h( L_shl_sat( Ls, 16 - ( 3 + 1 ) ) ); /* s can saturate here */ +#else + s = extract_h( L_shl( Ls, 16 - ( 3 + 1 ) ) ); /* s can saturate here */ +#endif /*-----------------------------------------------------------------------* * compute the index 0 <= ka <= NB_LEADER+1 which identifies an absolute leader of Q0, Q2, Q3 or Q4 * diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 2c3624a5d88dea59ce90901cfac4df60c933d96e..4801ffbea4f9f5522c18b1ba6fcf1e8086e18b64 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -127,7 +127,11 @@ void Residu3_10_fx( s64 = W_mac_16_16(s64, x[i-j], a[j]); } s = W_shl_sat_l(s64, q); - 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_com/stab_est_fx.c b/lib_com/stab_est_fx.c index e6b55fe71cea7bbf2c2fbe1a727da3e3b00978cc..de997e5c4514d0e3dadca4d1bcc6bfeeaeaf1978 100644 --- a/lib_com/stab_est_fx.c +++ b/lib_com/stab_est_fx.c @@ -74,7 +74,11 @@ Word16 stab_est_fx( { /*fcorr += ftmp_c*ftmp_c;*/ tmp16 = sub(lt_diff_etot[i], mean_diff); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, tmp16, tmp16 ); +#else + L_tmp = L_mac0( L_tmp, tmp16, tmp16 ); +#endif } /*------------------------------------------------------------------------* * Update diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 32be8639419c92ea2000e013cf987099fbca6ff5..3b2edce7cbecad572930c8b2a446903b83c173ab 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -264,7 +264,11 @@ void stat_noise_uv_mod_fx( tmp_res = div_s(1<<14, tmp_den); /* 15+14-Q_local-tmp_shift-Q_ge+16 */ L_tmp_res = Mult_32_16(*ge_sm, tmp_res); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ L_tmp_res = Mult_32_16(L_tmp_res, sub(32767, beta)); /*30-Q_local-tmp_shift+15-15 */ - L_tmp_res = L_add(L_shl(L_tmp_res, sub(add(Q_local, tmp_shift), 15)), beta); /* Q15 */ +#ifdef BASOP_NOGLOB + L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ +#else + L_tmp_res = L_add( L_shl( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ +#endif #ifdef BASOP_NOGLOB tmp_res = extract_h(L_shl_o(L_tmp_res, 15, &Overflow)); /* 15+15-16=14 */ #else @@ -290,8 +294,11 @@ void stat_noise_uv_mod_fx( L_tmp = L_mult(Exc2_local[i], alpha); /* Q_local + 16 */ L_tmp = L_mac(L_tmp, randval, alpha_m1); /* Q_local + 16 */ L_tmp3 = Mult_32_16(L_tmp, Noimix_fract); /* Q_local+16+15-15 */ - L_tmp = L_add(L_tmp3, L_shl(Mult_32_16(L_tmp, tmp_res), 1)); /* Q_local+16+14-15+1 */ - +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ +#else + L_tmp = L_add( L_tmp3, L_shl( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ +#endif Exc2_local[i] = extract_h(L_tmp); /*Q_local */ } *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ @@ -376,11 +383,17 @@ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ { /* r0 = L_mac(r0,x[i],x[i]) */ /* r1 = L_mac(r1,x[i],x[i+1]) -> correlation loop can be optimized */ - r0 = L_mac(r0,xi,xi); - +#ifdef BASOP_NOGLOB + r0 = L_mac_sat( r0, xi, xi ); +#else + r0 = L_mac( r0, xi, xi ); +#endif xi_p1 = shr(x[i+1], Q_shift); - r1 = L_mac(r1, xi, xi_p1); - +#ifdef BASOP_NOGLOB + r1 = L_mac_sat( r1, xi, xi_p1 ); +#else + r1 = L_mac( r1, xi, xi_p1 ); +#endif xi = xi_p1; move16(); } diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index fc2bb1c34a1b653d8c41e59327940c8e9a7c201b..ea8dd1aa8135f78a5eceb05dfce8588f294ef31f 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -1,3118 +1,3187 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -#include -#include "options.h" -#include "prot_fx2.h" -#include "prot_fx1.h" -#include "basop_util.h" -#include "rom_com.h" - - - /*==========================================================================*/ - /* FUNCTION : Word16 WB_BWE_gain_pred_fx () */ - /*--------------------------------------------------------------------------*/ - /* PURPOSE : predict WB frequency envelopes for 0b WB BWE */ - /*--------------------------------------------------------------------------*/ - /* INPUT ARGUMENTS : */ - /* _Word16 *core_dec_freq i : Frequency domain core decoded signal */ - /* _Word16 coder_type i : coding type */ - /* _Word16 prev_coder_type i : coding type of last frame */ - /* _Word16 prev_WB_fenv i : envelope for last frame */ - /* _Word16 *voice_factors i : voicing factors //Q15 */ - /* _Word16 pitch_buf[] i : pitch buffer //Q6 */ - /* _Word16 last_core_brate i : previous frame core bitrate */ - /* _Word16 last_wb_bwe_ener i : previous frame wb bwe signal energy */ - /*--------------------------------------------------------------------------*/ - /* OUTPUT ARGUMENTS : */ - /* _Word16 *WB_fenv, o : WB frequency envelopes Q3 */ - /*--------------------------------------------------------------------------*/ - /* INPUT/OUTPUT ARGUMENTS : */ - /*--------------------------------------------------------------------------*/ - /* RETURN ARGUMENTS : */ - /* _Word16 mode */ - /*--------------------------------------------------------------------------*/ - /* CALLED FROM : */ - /*==========================================================================*/ - -Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors //Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ - Word16 Q_syn, /* i : synthesis scaling */ - Word16 last_extl_fx, /* i : extl. layer for last frame */ - Word16 tilt_wb_fx -) -{ - Word32 enerL; - Word16 n_freq, mode, pitch; - Word16 ener_var_flag = 0; - Word16 voice_factor, enerL_16, enerL_40, enerL_64; - Word16 env_var_flag = 0; - Word16 exp; - Word16 tmp, tmp1; - Word32 L_tmp; - Word32 L_WB_fenv0, L_WB_fenv1; - Word16 pitch_buf_tmp[4]; - Word16 alfa = 32767; - move16(); - - mode = NORMAL; - move16(); - - enerL = L_deposit_l(0); - FOR(n_freq = 128; n_freq < 192; n_freq++) - { -#ifdef BASOP_NOGLOB - enerL = L_mac0_sat(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */ -#else - enerL = L_mac0(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */ -#endif - } - - L_WB_fenv0 = L_deposit_l(0); - FOR(n_freq = 192; n_freq < 224; n_freq++) - { -#ifdef BASOP_NOGLOB - L_WB_fenv0 = L_mac0_sat(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ -#else - L_WB_fenv0 = L_mac0(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ -#endif - } - - L_WB_fenv1 = L_deposit_l(0); - FOR(n_freq = 224; n_freq < 256; n_freq++) - { -#ifdef BASOP_NOGLOB - L_WB_fenv1 = L_mac0_sat(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ -#else - L_WB_fenv1 = L_mac0(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ -#endif - } - - L_tmp = sum16_32_fx(voice_factors, 4); - voice_factor = extract_l(L_shr(L_tmp, 2));/*Q13 */ - Copy_Scale_sig(pitch_buf, pitch_buf_tmp, 4, -1); - pitch = sum16_fx(pitch_buf_tmp, 4); - move16(); /*Q5 */ - - L_tmp = L_shr(enerL, 4); - test(); - IF(GT_32(L_max(L_WB_fenv1, L_WB_fenv0), L_tmp) && GT_16(9856, pitch)) - { - ener_var_flag = 1; - move16(); - } - - test(); -#ifdef BASOP_NOGLOB - IF(GT_32(L_WB_fenv0, L_shl_sat(L_WB_fenv1, 1))) -#else - IF(GT_32(L_WB_fenv0, L_shl(L_WB_fenv1, 1))) -#endif - { - exp = norm_l(L_WB_fenv0); - tmp = extract_h(L_shl(L_WB_fenv0, exp)); - tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ - L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv1, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ - /*L_tmp Q15 */ - tmp = extract_l(L_tmp); - alfa = s_max(tmp, 3277);/*Q15 */ - L_WB_fenv0 = Mult_32_16(L_WB_fenv0, alfa);/*2*Q_syn+15-15->2*Q_syn */ - } -#ifdef BASOP_NOGLOB - ELSE IF(GT_32(L_WB_fenv1, L_shl_sat(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED)) -#else - ELSE IF(GT_32(L_WB_fenv1, L_shl(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED)) -#endif - { - exp = norm_l(L_WB_fenv1); - tmp = extract_h(L_shl(L_WB_fenv1, exp)); - tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ - L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv0, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ - /*L_tmp Q15 */ - tmp = extract_l(L_tmp); - alfa = s_max(tmp, 3277);/*Q15 */ - L_WB_fenv1 = Mult_32_16(L_WB_fenv1, alfa);/*2*Q_syn+15-15->2*Q_syn */ - } - - if (L_WB_fenv0 == 0) - { - L_WB_fenv0 = L_deposit_l(1); - } - - if (L_WB_fenv1 == 0) - { - L_WB_fenv1 = L_deposit_l(1); - } - - if (enerL == 0) - { - enerL = L_deposit_l(1); - } - -#ifdef BASOP_NOGLOB - L_tmp = L_add_sat(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */ -#else - L_tmp = L_add(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */ -#endif - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - /*exp = sub(exp, 30-(2*Q_syn+6)); //+6(/64) */ - exp = sub(exp, sub(30, add(shl(Q_syn, 1), 6))); /*+6(/64) */ - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - -#ifdef BASOP_NOGLOB - WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */ -#else - WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ -#endif - test(); - test(); - IF(NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && ener_var_flag == 0) - { -#ifdef BASOP_NOGLOB - WB_fenv[0] = add_sat(WB_fenv[0], mult_r_sat(WB_fenv[0], 16384)); -#else - WB_fenv[0] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); -#endif - move16(); - } - - exp = norm_l(enerL); - tmp = extract_h(L_shl(enerL, exp)); - exp = sub(exp, sub(30, shl(Q_syn, 1))); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); -#ifdef BASOP_NOGLOB - enerL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 15))); /* Q0 */ -#else - enerL_16 = round_fx(L_shl(L_tmp, sub(exp, 15))); /* Q0 */ -#endif - enerL_40 = mult_r(6554, enerL_16); /*1/40 in Q18 ->Q3 */ - - test(); - test(); - test(); - test(); - test(); - test(); - IF(NE_16(coder_type, TRANSITION) && NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && - GT_16(enerL_40, WB_fenv[0]) && GT_16(alfa, 29491) && !(EQ_16(coder_type, prev_coder_type) && - GT_16(WB_fenv[0], prev_WB_fenv))) - { - IF(WB_fenv[0] != 0) - { - exp = norm_s(WB_fenv[0]); - tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */ - L_tmp = L_mult(enerL_40, tmp); /*Q(30-exp) */ -#ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */ -#else - tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */ -#endif - tmp = s_min(tmp, 16384); - L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q15 */ - WB_fenv[0] = extract_l(L_tmp);/*Q3 */ - } - - IF(GT_16(WB_fenv[0], prev_WB_fenv)) - { - /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ - } - } - - L_tmp = L_mult0(voice_factor, 77); - tmp1 = extract_l(L_shr(L_tmp, 13)); - - exp = norm_s(pitch); - tmp = div_s(shl(1, sub(14, exp)), pitch); /*Q(29-exp-5) */ - L_tmp = L_mult0(tmp1, tmp); /*29-exp-5->24-exp */ -#ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_tmp, add(exp, 6))); /*14 */ -#else - tmp = round_fx(L_shl(L_tmp, add(exp, 6))); /*14 */ -#endif - tmp1 = s_max(tmp, 8192); - alfa = s_min(24576, tmp1);/*Q14 */ - - L_tmp = L_mult0(alfa, WB_fenv[0]);/*Q14+Q3->Q17 */ - L_tmp = L_shr(L_tmp, 14);/*Q3 */ - tmp = extract_l(L_tmp); - - enerL = L_deposit_l(enerL_16); - enerL = L_shl(enerL, 6); /*Q6 */ -#ifdef BASOP_NOGLOB - tmp1 = i_mult_sat(3, WB_fenv[0]);/*Q3 */ -#else - tmp1 = i_mult(3, WB_fenv[0]);/*Q3 */ -#endif - L_tmp = L_mult0(tmp1, WB_fenv[0]); /*Q6 */ - - test(); - test(); - test(); - IF(GT_16(shr(enerL_16, 3), tmp) && GT_32(enerL, L_tmp) && NE_16(prev_coder_type, UNVOICED) && WB_fenv[0] != 0) - { - env_var_flag = 1; - move16(); - enerL_64 = mult_r(4096, enerL_16);/* 1/64 in Q18 ->Q3 */ - - exp = norm_s(WB_fenv[0]); - tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */ - L_tmp = L_mult(enerL_64, tmp); /*Q(30-exp) */ -#ifdef BASOP_NOGLOB - tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */ -#else - tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */ -#endif - tmp = s_min(tmp, 16384); - L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q3 */ - WB_fenv[0] = extract_l(L_tmp);/*Q3 */ - - IF(GT_16(WB_fenv[0], prev_WB_fenv)) - { - /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ - } - } - - test(); - IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED)) - { - WB_fenv[0] = shr(WB_fenv[0], 1); - move16();/*Q3 */ - } - - IF(NE_16(coder_type, AUDIO)) - { - tmp = mult_r(voice_factor, 19661); /*Q12 */ - tmp = s_max(tmp, 4096); - exp = norm_s(tmp); - tmp = div_s(shl(1, sub(14, exp)), tmp); /*Q(29-exp-12) */ - L_tmp = L_mult(WB_fenv[0], tmp); /*Q(21-exp) */ - - WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q3 */ - tmp1 = mult_r(328, pitch);/*Q7 */ - tmp = s_min(s_max(tmp1, 16), 256);/*Q7 */ - L_tmp = L_shr(L_mult0(WB_fenv[0], tmp), 7);/*Q3 */ - /*WB_fenv[0] = saturate(L_tmp); //Q3 */ -#ifdef BASOP_NOGLOB - WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, 16)); /*Q3 */ -#else - WB_fenv[0] = round_fx(L_shl(L_tmp, 16)); /*Q3 */ -#endif - } - test(); - IF(GT_32(last_core_brate, ACELP_8k00) && GT_16(WB_fenv[0], last_wb_bwe_ener)) - { - /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(29491, last_wb_bwe_ener), 3277, WB_fenv[0]));/*Q3 */ - } - - IF(NE_16(last_extl_fx, WB_BWE) && LT_16(tilt_wb_fx, 128)) - { - WB_fenv[0] = mult_r(s_min(16384, shl(tilt_wb_fx, 8)), WB_fenv[0]); - } - - IF(env_var_flag == 1) - { - WB_fenv[1] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); - move16(); - WB_fenv[0] = mult_r(24576, WB_fenv[0]); - move16();/*Q3 */ - } - ELSE - { - WB_fenv[1] = WB_fenv[0]; - move16(); - } - - test(); - IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED)) - { - WB_fenv[1] = shr(WB_fenv[1], 1); - move16();/*Q3 */ - } - - return (mode); -} - -/*-------------------------------------------------------------------* -* calc_norm_envelop_lf_fx() -* -* calc_envelope of low frequency spectrum -*-------------------------------------------------------------------*/ -static -void calc_norm_envelop_lf_fx( - const Word32 SWB_signal[], /* i : SWB spectrum */ /* Q12 */ - Word32 *envelope, /* o : normalized envelope */ /* Q12 */ - Word16 *L_swb_norm, /* i/o : length of envelope */ - const Word16 HQ_mode, /* i : HQ mode */ /* Q0 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic */ /* Q0 */ - Word16 *sfreq, /* i : starting frequency index */ - Word16 *efreq /* i : ending frequency index */ -) -{ - Word16 lookback, env_index, n_freq, n_lag_now, n_lag; - - *sfreq = 2; - move16(); - IF(EQ_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - *efreq = 146; - move16(); - if (EQ_16(HQ_mode, HQ_GEN_FB)) - { - *efreq = 306; - move16(); - } - IF(LT_16(add(shl(sub(328, *efreq), 1), 1), *L_swb_norm)) - { - *L_swb_norm = add(shl(sub(328, *efreq), 1), 1); - } - } - ELSE - { - *efreq = 130; - move16(); - if (EQ_16(HQ_mode, HQ_GEN_FB)) - { - *efreq = 290; - move16(); - } - IF(LT_16(add(shl(sub(400,*efreq),1),1),*L_swb_norm)) - { - *L_swb_norm = add(shl(sub(400,*efreq),1),1); - } - } - lookback = shr(*L_swb_norm, 1); - env_index = 0; - move16(); - n_lag_now = *L_swb_norm; - move16(); - - FOR(n_freq = 0; n_freq < lookback; n_freq++) - { - Word16 tmp; - Word32 L_tmp; - - L_tmp = L_deposit_l(1); - tmp = add(lookback, n_freq); - FOR(n_lag = 0; n_lag < tmp; n_lag++) - { - L_tmp = L_add(L_tmp, L_abs(SWB_signal[n_lag])); - } - envelope[env_index] = L_tmp; - move32(); - env_index = add(env_index, 1); - } - - FOR(; n_freq < *efreq; n_freq++) - { - /* Apply MA filter */ - Word32 L_tmp = L_deposit_l(1); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_add(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)])); - } - - envelope[env_index] = L_tmp; - move32(); - env_index = add(env_index, 1); - } - - return; -} -/*-------------------------------------------------------------------* - * calc_normal_length() - * - *-------------------------------------------------------------------*/ - -void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : input signal */ - const Word16 mode, /* i : input mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - Word16 Q_syn -) -{ - Word16 i, n_freq, n_band, THRES; - const Word16 *pit; - Word16 peak, mag; - Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; - Word16 N; - Word32 L_mean, L_tmp, L_tmp1; - - THRES = 4; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) || EQ_16(extl, SWB_BWE) || EQ_16(extl, FB_BWE)) - { - THRES = 8; - move16(); - } - - N = 16; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) && (EQ_16(mode, HQ_HARMONIC) || EQ_16(mode, HQ_HVQ))) - { - N = 13; - move16(); - } - - n_band = 0; - move16(); - pit = sp; - move16();/*Q_syn */ - FOR(i = 0; i < N; i++) - { - peak = 0; - move16(); - L_mean = L_deposit_l(0); - - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - mag = abs_s(*pit); - - peak = s_max(peak, mag); - L_mean = L_add(L_mean, mag);/*Q_syn */ - pit++; - } - - L_tmp = L_mult0(peak, 15 + THRES);/*Q_syn */ - IF(EQ_16(THRES, 8)) - { - L_tmp1 = L_shl(Mult_32_16(L_mean, 32767), 3); - } - ELSE - { - L_tmp1 = L_shl(Mult_32_16(L_mean,32767), 2); - } - - test(); - if (GT_32(L_tmp, L_tmp1) && (GT_16(peak, shl(10, Q_syn)))) - { - n_band = add(1, n_band); - } - } - - IF(EQ_16(core, ACELP_CORE)) - { - L_swb_norm_trans = add(4, mult(n_band, 8192)); - L_swb_norm_norm = add(8, mult(n_band, 16384)); - - L_tmp = L_add(65536, L_mult0(n_band, 4096)); /*Q16 */ - L_swb_norm_harm = s_max(round_fx(L_shl(L_tmp, 5)), 24); /* Q0 */ - - IF(EQ_16(mode, HARMONIC)) - { - L_swb_norm_cur = L_swb_norm_harm; - move16(); - } - ELSE IF(EQ_16(mode, NORMAL)) - { - L_swb_norm_cur = L_swb_norm_norm; - move16(); - } - ELSE - { - L_swb_norm_cur = L_swb_norm_trans; - move16(); - } - *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1); - move16(); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - ELSE - { - test(); - IF(EQ_16(mode,HQ_HARMONIC) || EQ_16(mode,HQ_HVQ)) - { - L_tmp = L_add(65536, L_mult(n_band, 2560)); - L_swb_norm_cur = round_fx(L_shl(L_tmp, 5));/*Q0 */ - } - ELSE - { - L_tmp = L_add(65536, L_mult(n_band, 2048)); /*Q16 */ - L_swb_norm_cur = round_fx(L_shl(L_tmp, 3));/*Q0 */ - } - - /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */ - *L_swb_norm = round_fx(L_mac(L_mult(L_swb_norm_cur, 3277), *prev_L_swb_norm, 29491)); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - - return; -} -/*-------------------------------------------------------------------* - * calc_tilt_bwe() - * - * calculate tilt parameter - *-------------------------------------------------------------------*/ - -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ -) -{ - Word16 i, j; - Word32 L_ener, L_ener_tot, L_temp; - Word16 tmp1, tmp2; - const Word16 *ptr; - Word16 exp2; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif - - BASOP_SATURATE_WARNING_OFF_EVS - - /* this is required for adaptative precision energy summation loop, do not remove */ - Overflow = 0; - move16(); - exp2 = 0; - move16(); - - ptr = sp; - move16(); - L_ener_tot = L_deposit_l(1); - - /* Divide Frame Length by 32 */ - FOR(j = shr(N, 5); j > 0; j--) - { -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */ -#else - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ -#endif - L_ener = L_mult0(tmp1, tmp1); - /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ - FOR(i = 1; i < 32; i++) - { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */ - L_ener = L_mac0_o(L_ener, tmp1, tmp1, &Overflow); -#else - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ - L_ener = L_mac0(L_ener, tmp1, tmp1); -#endif - } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener = L_shr_o(L_ener, exp2, &Overflow); - L_temp = L_add_o(L_ener_tot, L_ener, &Overflow); -#else - L_ener = L_shr(L_ener, exp2); - L_temp = L_add(L_ener_tot, L_ener); -#endif - IF(Overflow != 0) - { - L_ener_tot = L_shr(L_ener_tot, 1); - L_ener = L_shr(L_ener, 1); - exp2 = add(exp2, 1); - /* this is required, do not remove */ - Overflow = 0; - move16(); - } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener_tot = L_add_o(L_ener_tot, L_ener, &Overflow); -#else - L_ener_tot = L_add(L_ener_tot, L_ener); -#endif - } -#ifdef BASOP_NOGLOB - L_ener = L_deposit_l(abs_s(sub_o(sp[1], sp[0], &Overflow))); -#else - L_ener = L_deposit_l(abs_s(sub(sp[1], sp[0]))); -#endif - FOR(i = 2; i < N; i++) - { - /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ -#ifdef BASOP_NOGLOB - tmp1 = sub_o(sp[i], sp[i - 1], &Overflow); - tmp2 = sub_o(sp[i - 1], sp[i - 2], &Overflow); -#else - tmp1 = sub(sp[i], sp[i - 1]); - tmp2 = sub(sp[i - 1], sp[i - 2]); -#endif - tmp2 = mult(tmp1, tmp2); - tmp1 = abs_s(tmp1); - /* to Get either 0 or -1 in 'tmp2' */ - tmp2 = shr(tmp2, 15); - /* this allows this code */ - L_ener = L_msu0(L_ener, tmp2, tmp1); - /* instead of this one */ - /* test(); */ - /* if (tmp2 < 0) */ - /* { */ - /* L_ener = L_mac0(L_ener, 1, tmp1); */ - /* } */ - /* it saves one op */ - } - - tmp1 = norm_l(L_ener_tot); - L_temp = L_shl(L_ener_tot, tmp1); - tmp1 = sub(add(31 + 4, exp2), add(tmp1, shl(exp_sp, 1))); - L_temp = Isqrt_lc(L_temp, &tmp1); - - /* *tilt_flt = (float)(r1/sqrt(r0)); */ - exp2 = norm_l(L_ener); - L_temp = Mult_32_16(L_temp, round_fx(L_shl(L_ener, exp2))); - exp2 = sub(exp2, tmp1); - exp2 = add(exp2, exp_sp); - - /* Put in Q24 */ - L_temp = L_shr(L_temp, sub(exp2, 24)); - - BASOP_SATURATE_WARNING_ON_EVS - - return L_temp; -} -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word32 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ -) -{ - Word16 i, j; - Word32 L_ener, L_ener_tot, L_temp; - Word32 tmp1, tmp2; - Word16 sign = 0; - const Word32 *ptr; - Word16 exp2, tmp_exp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif - - BASOP_SATURATE_WARNING_OFF_EVS - - /* this is required for adaptative precision energy summation loop, do not remove */ - Overflow = 0; - move16(); - exp2 = 0; - move16(); - - ptr = sp; - move16(); - L_ener_tot = L_deposit_l(1); - - /* Divide Frame Length by 32 */ - FOR(j = shr(N, 5); j > 0; j--) - { - Word32 tmp = *ptr++; /* Divide by 4 */ - L_ener = Mpy_32_32( tmp, tmp ); - /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ - FOR(i = 1; i < 32; i++) - { - tmp1 = *ptr++; /* Divide by 4 */ - L_ener = Madd_32_32(L_ener, tmp1, tmp1); - } - L_temp = L_add(L_ener_tot, L_ener); - - L_ener_tot = L_add(L_ener_tot, L_ener); - } - L_ener = L_abs(L_sub(sp[1], sp[0])); - - FOR(i = 2; i < N; i++) - { - /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ - tmp1 = L_sub(sp[i], sp[i - 1]); - tmp2 = L_sub(sp[i - 1], sp[i - 2]); - - tmp2 = Mpy_32_32(tmp1, tmp2); - tmp1 = L_abs(tmp1); - /* to Get either 0 or -1 in 'tmp2' */ - tmp2 = L_shr(tmp2, 31); - sign = extract_l(L_shl(tmp2, Q15)); - /* this allows this code */ - L_ener = Msub_32_16(L_ener, tmp1, sign); - /* instead of this one */ - /* test(); */ - /* if (tmp2 < 0) */ - /* { */ - /* L_ener = L_mac0(L_ener, 1, tmp1); */ - /* } */ - /* it saves one op */ - } - - L_temp = L_ener_tot; - tmp_exp = sub(Q31, sub(shl(exp_sp, 1), Q31)); - L_temp = Sqrt32(L_temp, &tmp_exp); - L_temp = L_shl(L_temp, sub(exp_sp, sub(Q31, tmp_exp))); - - /* *tilt_flt = (float)(r1/sqrt(r0)); */ - L_temp = L_deposit_l(BASOP_Util_Divide3232_Scale(L_ener, L_temp, &exp2)); - IF (GT_16(sub(exp2, 4) , norm_l(L_temp))) - { - L_temp = MAX_16; - } - ELSE - { - L_temp = L_shl(L_temp, sub(exp2, 4)); // Output is expected in Q11 - } - BASOP_SATURATE_WARNING_ON_EVS - - return extract_l(L_temp); -} -#endif - -/*-------------------------------------------------------------------* - * calc_norm_envelop() - * - * calculate normalized parameter - *-------------------------------------------------------------------*/ - -void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 st_offset /* i : offset */ -) -{ - Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; - - lookback = shr(L_swb_norm, 1); - move16(); - env_index = add(swb_bwe_subband[0], st_offset); - n_lag_now = L_swb_norm; - move16(); - tmp = sub(add(SWB_flength, st_offset), L_swb_norm); - FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++) - { - /* Apply MA filter */ - Word32 L_tmp = L_deposit_l(0); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag])); - } - envelope[env_index] = L_tmp; - move32(); - env_index++; - } - - i = 0; - move16(); - tmp = sub(add(SWB_flength, st_offset), lookback); - FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++) - { - Word32 L_tmp; - - n_lag_now = sub(L_swb_norm, i); - /* Apply MA filter */ - L_tmp = L_deposit_l(0); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag])); - } - envelope[env_index] = L_tmp; - move32(); - env_index++; - i++; - } - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void WB_BWE_decoding_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : WB BWE decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 *core_dec_freq i : Frequency domain core decoded signal Q_syn*/ -/* _Word16 *WB_fenv i : WB frequency envelopes Q3 */ -/* _Word16 WB_flength i : Length of input/output */ -/* _Word16 mode i : classification for WB signal */ -/* _Word16 prev_mode i : classification for last frame */ -/* _Word16 last_extl i : extl. layer for last frame */ -/* _Word16 extl i : extension layer */ -/* _Word16 coder_type i : coding type */ -/* _Word16 total_brate i : core layer bitrate */ -/* _Word16 prev_coder_type i : coding type of last frame */ -/* _Word16 Q_syn i : Q format */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *WB_signal, o : WB signal in MDCT domain Q_syn */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _Word32 *prev_Energy, i/o: energy for last frame Q_syn */ -/* _Word16 *prev_WB_fenv, i/o: envelope for last frame Q3 */ -/* _Word16 *prev_L_wb_norm, i/o: length for last frame wb norm Q0 */ -/* _Word16 *Seed, i/o: random generator seed Q15 */ -/* _Word16 *prev_flag, i/o: attenu flag of last frame Q0 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -void WB_BWE_decoding_fx( - const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ - Word16 *WB_fenv, /* i : WB frequency envelopes */ - Word32 *WB_signal_32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for WB signal */ - const Word16 last_extl, /* i : extl. layer for last frame */ - Word32 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word32 total_brate, /* i : core layer bitrate */ - Word16 *Seed, /* i/o: random generator seed */ - Word16 *prev_flag, /* i/o: attenu flag of last frame */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 Q_syn, - Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ -) -{ - Word16 n_freq, n_band; - Word16 i, L; - Word32 envelope[L_FRAME16k]; - Word32 energy, EnergyL; - Word32 *pit1; - Word16 WB_signal[L_FRAME16k]; - Word16 L_wb_norm, wfenv[2]; - Word16 alfa, beta; - Word16 flag = 0; - Word16 core_type = 1; - Word16 tmp, tmp1, exp, tmp2; - Word32 L_tmp, L_tmp1, L_tmp2; - Word32 prev_ener_alpha, prev_ener_beta; - Word16 signum[L_FRAME16k]; - Word16 inv_L_wb_norm, weight; - - calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_wb_norm, prev_L_wb_norm, Q_syn); - set32_fx(WB_signal_32, 0, L_FRAME16k); - set16_fx(WB_signal, 0, L_FRAME16k); - - /* copy excitation */ - test(); - if (NE_16(coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00)) - { - core_type = 0; - move16(); - } - - IF(core_type == 0) - { - Copy(&core_dec_freq[160], &WB_signal[240], 80); - } - ELSE - { - Copy(&core_dec_freq[80], &WB_signal[240], 80); - } - - /* calculate envelope */ - calc_norm_envelop_fx(WB_signal, envelope, L_wb_norm, WB_flength, 0); - test(); - IF(coder_type != UNVOICED && total_brate <= ACELP_8k00) - { - exp = norm_s(L_wb_norm); - inv_L_wb_norm = shl(div_s(shl(1, sub(14, exp)), L_wb_norm), sub(exp, 14)); /* Q(15) */ - IF(NE_16(mode, HARMONIC)) - { - tmp = add(shl(inv_L_wb_norm, 1), inv_L_wb_norm); - weight = s_max(s_min(tmp, 16384), 8192); - } - ELSE - { - weight = 8192; - move16(); - } - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - signum[n_freq] = 1; - IF(WB_signal[n_freq] < 0) - { - signum[n_freq] = -1; - move16(); - WB_signal[n_freq] = negate(WB_signal[n_freq]); - move16(); - } - L_tmp = Mult_32_16(envelope[n_freq], inv_L_wb_norm); /* Q_syn */ - L_tmp = Mult_32_16(L_tmp, 14746); /* Q_syn */ - L_tmp1 = L_deposit_l(WB_signal[n_freq]); /* Q_syn */ - L_tmp = L_sub(L_tmp1, L_tmp); /* Q_syn */ - WB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */ - IF(L_tmp > 0) - { - tmp = sub(18022, weight); /* Q15 */ - WB_signal[n_freq] = extract_l(Mult_32_16(L_tmp, tmp)); /* Q_syn */ - } - - IF(NE_16(signum[n_freq], 1)) - { - WB_signal[n_freq] = negate(WB_signal[n_freq]); - move16(); - } - } - } - - /* Normalize with envelope */ - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - IF(envelope[n_freq] != 0) - { - exp = norm_l(envelope[n_freq]); - tmp = extract_h(L_shl(envelope[n_freq], exp)); - exp = sub(sub(30, exp), Q_syn); - tmp = div_s(16384, tmp); - L_tmp = L_shr(L_mult0(WB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */ - WB_signal[n_freq] = extract_l(L_tmp); /*Q15 */ - } - ELSE - { - WB_signal[n_freq] = shl(WB_signal[n_freq],sub(15,Q_syn)); /*Q15 */ move16(); - } - } - - L = 1; - move16(); - if (EQ_16(mode, HARMONIC)) - { - L = 4; - move16(); - } - - IF(EQ_16(coder_type, UNVOICED)) - { - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - *Seed = extract_l(L_mac0(20101L, *Seed, 12345)); - L_tmp = L_shl(*Seed, add(Q_syn, 1)); - WB_signal_32[n_freq] = L_tmp; - move32(); - } - } - ELSE - { - FOR(n_band = 0; n_band < 4; n_band += L) - { - energy = L_deposit_l(0); - FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++) - { - L_tmp = L_mult(WB_signal[n_freq],WB_signal[n_freq]); /*Q31 */ - energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */ - } - - tmp = sub(swb_bwe_subband[n_band + L] , swb_bwe_subband[n_band]); - tmp = div_s(1,tmp);/*Q15 */ - energy = Mult_32_16(energy,tmp); /*Q(15+25-15)->Q(25) */ - - exp = norm_l(energy); - L_tmp1 = L_shl(energy, exp); - exp = 31 - exp - (25); - move16(); - L_tmp1 = Isqrt_lc(L_tmp1, &exp); /*Q(31-exp) */ - - FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++) - { - L_tmp2 = Mult_32_16(L_tmp1, WB_signal[n_freq]); - WB_signal_32[n_freq] = L_shl(L_tmp2, sub(add(exp, Q_syn), 15)); - move32(); - } - } - } - - EnergyL = L_deposit_l(0); - IF(core_type == 1) - { - test(); - IF(NE_16(prev_coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00)) - { - FOR(i = 160; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL); - } - } - ELSE - { - FOR(i = 80; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]),EnergyL); - } - } - - IF(LE_32(total_brate, ACELP_8k00)) - { - alfa = 26214; - move16(); /*0.8f in Q15; */ - beta = 10240; - move16();/*1.25f in Q13; */ - } - ELSE - { - alfa = 16384; - move16();/* 0.5f in Q15; */ - beta = 16384; - move16();/*2.0f in Q13 */ - } - } - ELSE - { - IF(EQ_16(prev_coder_type,AUDIO)) - { - FOR(i = 80; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL);/*Q_syn */ - } - } - ELSE - { - FOR(i = 160; i < 240; i++) - { - EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL); - } - } - - test(); - IF(EQ_16(prev_coder_type,coder_type) && GT_16(WB_fenv[0],prev_WB_fenv[0])) - { - alfa = 13107; - move16();/*.4 in Q15 */ - beta = 20480; - move16(); /*2.5 in Q13 */ - } - ELSE - { - alfa = 19661; - move16();/*.6 in Q15 */ - beta = 13681; - move16();/*1.67 in Q13 */ - } - - test(); - test(); - test(); - IF(EQ_16(coder_type,GENERIC) || (GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1)) && EQ_16(*prev_flag,1))) - { - WB_fenv[0] = shr(WB_fenv[0], 1); - move16(); - WB_fenv[1] = shr(WB_fenv[1], 1); - move16(); - flag = 1; - move16(); - } - } - L_tmp1 = Mult_32_16(EnergyL, prev_WB_fenv[0]);/*Qsyn+3-15 */ - L_tmp2 = Mult_32_16(*prev_Energy, WB_fenv[0]);/*Q_syn+3-15 */ - prev_ener_alpha = Mult_32_16(*prev_Energy, alfa);/*Q_syn+15-15->Q_syn */ - prev_ener_beta = L_shl(Mult_32_16(*prev_Energy, beta), 2); /*Q_syn+13-15+2 ->Q_syn */ - - test(); - test(); - IF((EQ_16(mode, HARMONIC) && GT_16(shr(WB_fenv[0], 2), WB_fenv[1])) || EQ_16(mode, NORMAL)) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF(EQ_16(last_extl, WB_BWE) && - ((EQ_16(prev_coder_type, AUDIO) && NE_16(coder_type, AUDIO)) || - (NE_16(prev_coder_type, AUDIO) && EQ_16(coder_type, AUDIO))) && LE_32(total_brate, ACELP_8k00)) - { - IF(GT_16(WB_fenv[0], prev_WB_fenv[0])) - { - /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */ - } - ELSE - { - /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(16384,WB_fenv[0]),16384,prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(13108,WB_fenv[1]),13108,prev_WB_fenv[1]));/*Q3 */ - } - } - ELSE IF(EQ_16(last_extl, WB_BWE) && LT_32(L_tmp1, L_tmp2) && GT_16(WB_fenv[0], prev_WB_fenv[0]) && - NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && LE_32(total_brate, ACELP_8k00)) - { - /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */ - } - ELSE IF(EQ_16(last_extl, WB_BWE) && GT_32(EnergyL, prev_ener_alpha) && GT_32(prev_ener_beta, EnergyL) && - NE_16(prev_coder_type, UNVOICED)) - { - /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(WB_fenv[0], 16384), prev_WB_fenv[0], 16384));/*Q3 */ - /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(WB_fenv[1], 16384), prev_WB_fenv[1], 16384));/*Q3 */ - } - ELSE - { - wfenv[0] = WB_fenv[0]; - move16(); - wfenv[1] = WB_fenv[1]; - move16(); - } - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[2]; n_freq++) - { - WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]); - move32();/* Q_syn+3+1 */ - } - - FOR(n_freq = swb_bwe_subband[2]; n_freq < swb_bwe_subband[4]; n_freq++) - { - WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[1]); - move32();/* Q_syn+3+1 */ - } - - prev_WB_fenv[0] = wfenv[0]; - move16(); - prev_WB_fenv[1] = wfenv[1]; - move16(); - } - ELSE - { - wfenv[0] = add(shr(WB_fenv[0],1), shr(WB_fenv[1],1));/*Q3 */ - - test(); - test(); - IF(EQ_16(last_extl,WB_BWE) && GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1))) - { - L_tmp1 = L_mac(L_mult(8192,wfenv[0]),12288, prev_WB_fenv[0]); - wfenv[0] = round_fx(L_mac(L_tmp1, 12288, prev_WB_fenv[1])); - } - FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) - { - WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]); - move32();/* Q_syn+3+1 */ - } - prev_WB_fenv[0] = wfenv[0]; - move16(); - prev_WB_fenv[1] = wfenv[0]; - move16(); - } - - *prev_flag = flag; - move16(); - *prev_Energy = EnergyL; - move32(); - pit1 = &WB_signal_32[240]; - - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - tmp1 = extract_l(L_mult0(n_freq, 1638));/*Q15 */ - tmp2 = add(6554, tmp1);/*Q15 */ - L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ - *(pit1++) = L_tmp1; - move32(); - } - - IF(EQ_16(core_type, 1)) - { - pit1 = &WB_signal_32[280]; - FOR(n_freq = 0; n_freq < 40; n_freq++) - { - tmp1 = extract_l(L_mult0(n_freq, 655));/*Q15 */ - tmp2 = sub(32767, tmp1); - L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ - *(pit1++) = L_tmp1; - move32(); - } - } - ELSE - { - pit1 = &WB_signal_32[300]; - FOR(n_freq = 0; n_freq < 20; n_freq++) - { - tmp1 = extract_l(L_mult0(n_freq, 1311));/*Q15 */ - tmp2 = sub(32767, tmp1); - L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ - *(pit1++) = L_tmp1; - move32(); - } - } - pit1 = &WB_signal_32[240]; - tmp = Find_Max_Norm32(pit1, 80); - FOR(i = 0; i < 80; i++) - { - L_tmp = *pit1; - *(pit1++) = L_shl(L_tmp, sub(tmp, 1)); - move32(); - } - *Q_syn_hb = add(Q_syn, add(tmp, 3)); - return; -} - - -/*==========================================================================*/ -/* FUNCTION : void SWB_BWE_decoding_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : SWB BWE decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS */ -/* _(Word16*) core_dec_freq :Frequency domain core decoded signal Q_syn */ -/* _(Word16) SWB_flength :Length of input/output Q0 */ -/* _(Word16) mode :classification for SWB signal */ -/* _(Word16) tilt_nb :tilt of synthesis wb signal Q11 */ -/* _(Word16) st_offset :offset value due to different core */ -/* _(Word16) Q_syn :Q format */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)SWB_fenv : SWB frequency envelopes Q1 */ -/* _(Word16*)prev_Energy : energy for last frame Q3 */ -/* _(Word16*)prev_SWB_fenv : envelope for last frame Q1 */ -/* _(Word16*)prev_L_swb_norm : length for last frame wb norm Q0 */ -/* _(Word16*)Seed : random generator seed Q0 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16*)SWB_signal : SWB signal in MDCT domain Q0 */ -/* _(Word16*)frica_flag : fricative signal flag Q0 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ - -void SWB_BWE_decoding_fx( - const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ - Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ - Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for SWB signal */ - Word16 *frica_flag, /* o : fricative signal flag */ - Word16 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ - const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ - Word16 *Seed, /* i/o: random generator seed */ - const Word16 st_offset, /* i : offset value due to different core */ - Word16 *prev_weight, /* i/o: excitation weight value of last frame */ - const Word16 extl, /* i : extension layer */ - Word16 Q_syn - , const Word16 last_extl /* i : extension layer of last frame */ -) -{ - Word16 n_freq, n_band, L, L_swb_norm; - Word32 *pit1_32; - Word16 *pit1; - Word32 envelope[L_FRAME32k]; - Word32 fenvL, EnergyL, Energy, energy, L_mean; - Word16 fenvL_16, EnergyL_16, Energy_16, tmp, exp, exp1; - Word16 SWB_signal[L_FRAME32k]; - Word16 mean, factor, factor1, tmp1, tmp2, tmp3, tmp_exp, tmp_ener, weight, wfenv; - Word32 L_tmp, L_tmp3, L_tmp4, Ltmp_ener, L_tmp1; - Word32 L_energy; - Word16 signum[L_FRAME32k]; - Word16 inv_L_swb_norm; - - fenvL = L_deposit_l(0); - EnergyL = L_deposit_l(0); - FOR(n_freq = 224 + st_offset; n_freq < swb_bwe_trans_subband[0] + st_offset; n_freq++) - { -#ifdef BASOP_NOGLOB - fenvL = L_mac0_sat(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ -#else - fenvL = L_mac0(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ -#endif - } - - FOR(n_freq = 16; n_freq < L_FRAME; n_freq++) - { -#ifdef BASOP_NOGLOB - EnergyL = L_mac0_sat(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ -#else - EnergyL = L_mac0(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ -#endif - } - - fenvL_16 = 0; - move16(); - IF(fenvL != 0) - { - exp = norm_l(fenvL); /* In 2*Q_syn */ - tmp = extract_h(L_shl(fenvL, exp)); - exp = sub(exp, sub(30, add(shl(Q_syn, 1), 4))); /*+4(/16) */ - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - -#ifdef BASOP_NOGLOB - fenvL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ -#else - fenvL_16 = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ -#endif - } -#ifdef BASOP_NOGLOB - IF( GT_16( fenvL_16, shl_sat( SWB_fenv[0], 5 ) ) ) -#else - IF( GT_16( fenvL_16, shl( SWB_fenv[0], 5 ) ) ) -#endif - { - fenvL_16 = shl(SWB_fenv[0], 2); - move16(); - } - EnergyL = Mult_32_16(EnergyL, 17476); /*2*Q_syn+3; 17476=(1/15) in Q18 */ - EnergyL_16 = 0; - move16(); - IF(EnergyL != 0) - { - exp = norm_l(EnergyL); /* In 2*Q_syn+3 */ - tmp = extract_h(L_shl(EnergyL, exp)); - exp = sub(exp, sub(30, add(shl(Q_syn, 1), 3 + 4))); /*+4(/16) */ - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - -#ifdef BASOP_NOGLOB - EnergyL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */ -#else - EnergyL_16 = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ -#endif - } - calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm, Q_syn); - - set16_fx(SWB_signal, 0, L_FRAME32k); - IF(EQ_16(mode, TRANSIENT)) - { - Energy = L_deposit_l(0); - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - Energy = L_mac(Energy, SWB_fenv[n_band], SWB_fenv[n_band]); /*Q(2*1+1)->Q3 */ - } - exp = norm_s(SWB_FENV_TRANS); - tmp = div_s(shl(1, sub(14, exp)), SWB_FENV_TRANS); /*Q(29-exp) */ - L_tmp = Mult_32_16(Energy, tmp); /*Q(3+29-exp+1-16)->Q(17-exp) */ - Energy_16 = round_fx(L_shl(L_tmp, add(exp, 2))); /*Q3 */ - - /* Reconstruct excitation from LF signal */ - Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128); - Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128); - Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64); - - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - - /* Normalize with envelope */ - tmp_exp = sub(15, Q_syn); - FOR(n_freq = swb_bwe_trans_subband[0] + st_offset; n_freq < swb_bwe_trans_subband[SWB_FENV_TRANS] + st_offset; n_freq++) - { - IF(envelope[n_freq] != 0) - { - exp = norm_l(envelope[n_freq]); - tmp = extract_h(L_shl(envelope[n_freq], exp)); - exp = sub(sub(30, exp), Q_syn); - tmp = div_s(16384, tmp); /*Q(15+exp) */ - L_tmp = L_shr(L_mult0(SWB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */ - SWB_signal[n_freq] = extract_l(L_tmp); /*Q15 */ - } - ELSE - { - SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp); - move16();/*Q15 */ - } - } - - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - energy = L_deposit_l(0); - tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset); - FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++) - { -#ifdef BASOP_NOGLOB - L_tmp = L_mult_sat(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */ - energy = L_add_sat(energy, L_shr(L_tmp, 6)); /*Q25 */ -#else - L_tmp = L_mult(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */ - energy = L_add(energy, L_shr(L_tmp, 6)); /*Q25 */ -#endif - } - - IF(energy == 0) - { - Ltmp_ener = L_mult(sqrt_swb_bwe_trans_subband_width_fx[n_band], SWB_fenv[n_band]);/*Q13 */ - tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset); - FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener, SWB_signal[n_freq]), 2 + Q_syn); - move32();/*15+Qsyn */ - } - } - ELSE - { - exp1 = norm_s(swb_bwe_trans_subband_width[n_band]); - tmp = div_s(shl(1,sub(14,exp1)),swb_bwe_trans_subband_width[n_band]); /*Q(29-exp1) */ - energy = Mult_32_16(energy,tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */ - - exp = norm_l(energy); - L_tmp = L_shl(energy,exp); - /*exp = 31-exp-(-exp1+39); */ - exp = sub(sub(exp1,exp),8); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - - Ltmp_ener = Mult_32_16(L_tmp,SWB_fenv[n_band]);/*Q(31-exp+1+1-16)->Q(17-exp) */ - tmp = add(swb_bwe_trans_subband[n_band + 1],st_offset); - tmp_exp = add(Q_syn,sub(exp,2)); - FOR(n_freq = add(swb_bwe_trans_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]), tmp_exp); - move32(); /*15+Qsyn */ - } - } - } - - FOR(n_band = 0; n_band < 8; n_band++) - { - L_tmp = L_mult(SWB_fenv[n_band / 4], SWB_fenv[n_band / 4]); /*Q3 */ - prev_SWB_fenv[n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */ - } - - FOR(n_band = 0; n_band < 6; n_band++) - { - L_tmp = L_mult(SWB_fenv[2 + n_band / 3], SWB_fenv[2 + n_band / 3]); /*Q3 */ - prev_SWB_fenv[8 + n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */ - } - - *prev_weight = 16384; - move16(); - } - ELSE - { - Energy_16 = 0; - move16(); - L_energy = L_deposit_l(0); - FOR(n_band = 0; n_band < SWB_FENV; n_band++) - { - L_energy = L_add(L_energy,SWB_fenv[n_band]); /*Q1 */ - } - exp = norm_s(SWB_FENV); - tmp = div_s(shl(1,sub(14,exp)),SWB_FENV); /*Q(29-exp) */ - L_tmp = Mult_32_16(L_energy,tmp); /*Q(1+29-exp+1)->Q(15-exp) */ -#ifdef EVS_FLOAT -#ifdef BASOP_NOGLOB - EnergyL_16 = round_fx_sat(L_shl_sat(L_tmp, add(exp, 4))); /* Q3 */ -#else - Energy_16 = round_fx(L_shl(L_tmp,add(exp,4))); /*Q3 */ -#endif -#else - Energy_16 = round_fx(L_shl(L_tmp, add(exp, 4))); /*Q3 */ -#endif // EVS_FLOAT - - IF(NE_16(last_extl, SWB_BWE) && NE_16(last_extl,FB_BWE)) - { - IF(Energy_16 < shr(EnergyL_16, 4) && EQ_16(extl, FB_BWE)) - { - FOR(n_band = 0; n_band < SWB_FENV; n_band++) - { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], 6554); - } - fenvL_16 = mult_r(fenvL_16, 6554); - } - Copy(SWB_fenv, prev_SWB_fenv, SWB_FENV); - } - - IF(mode == HARMONIC) - { - Copy(core_dec_freq, &SWB_signal[240 + st_offset], 240); - Copy(&core_dec_freq[128], &SWB_signal[480 + st_offset], 80); - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - } - ELSE - { - test(); - test(); - test(); - test(); - test(); - test(); - IF(EQ_16(mode, NOISE) || ((GT_16(Energy_16,EnergyL_16) || (GT_16(tilt_nb,14336) && GT_16(Energy_16,shr(EnergyL_16,1))) || - GT_16(tilt_nb,24576)) && GT_16(Energy_16,600) && GT_16(fenvL_16,200))) - { - tmp = add(swb_bwe_subband[SWB_FENV], st_offset); - FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp; n_freq++) - { - *Seed = extract_l(L_mac0(20101L, 12345,*Seed)); - SWB_signal[n_freq] = mult_r(*Seed, 32767); - move16();/*Q15 */ - } - if (NE_16(mode, NOISE)) - { - *frica_flag = 1; - move16(); - } - } - ELSE - { - /* modify SHB frequency envelopes when SHB spectrum is unflat */ - FOR(n_band = 0; n_band < 13; n_band++) - { - IF(GT_16(mult_r(SWB_fenv[n_band],29491), SWB_fenv[n_band + 1])) - { - tmp = extract_l(L_mac0(26214, n_band, 492)); /*Q15; 0.015 in Q15 = 492 */ - SWB_fenv[n_band + 1] = mult_r(SWB_fenv[n_band + 1], tmp); - move16();/*Q1 */ - } - - IF(GT_16(mult_r(SWB_fenv[n_band + 1],29491),SWB_fenv[n_band])) - { - tmp = extract_l(L_mac0(26214, n_band,492)); /*Q15; 0.015 in Q15 = 492 */ - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band],tmp); - move16();/*Q1 */ - } - } - Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128); - Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128); - Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64); - -#ifdef BASOP_NOGLOB - tmp1 = add_sat(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */ - tmp2 = add_sat(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */ -#else - tmp1 = add(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */ - tmp2 = add(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */ -#endif - pit1 = &SWB_signal[368 + st_offset]; - move16(); - - test(); - IF((tmp2 == 0) || (LT_16(tmp2, mult_r(tmp1, 9830)))) - { - tmp3 = 9830; - move16();/*0.3 in Q15 */ - WHILE(LT_16(tmp3,32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; -#ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3, 3277); /*Q15 */ -#else - tmp3 = add(tmp3, 3277); /*Q15 */ -#endif - } - } - ELSE IF(LT_16(tmp2, tmp1)) - { - exp = norm_s(tmp1); - tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ -#ifdef BASOP_NOGLOB - tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ -#else - tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ -#endif - WHILE(LT_16(tmp3, 32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; -#ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3,3277); /*Q15 */ -#else - tmp3 = add(tmp3,3277); /*Q15 */ -#endif - } - } - - pit1 = &SWB_signal[367 + st_offset]; - move16(); - IF(GT_16(mult_r(tmp1,6554),tmp2)) - { - /*20480 = 5 in Q12 */ - FOR(tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048) - { - *pit1 = round_fx(L_shl(L_mult(*pit1,tmp3),3)); /*Q_syn */ - pit1--; - } - } - -#ifdef BASOP_NOGLOB - tmp1 = add_sat(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */ - tmp2 = add_sat(add_sat(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add_sat(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset]))); -#else - tmp1 = add(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */ - tmp2 = add(add(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset]))); -#endif - pit1 = &SWB_signal[496 + st_offset]; - move16(); - - test(); - IF((tmp2 == 0) || (LT_16(tmp2,mult_r(tmp1,9830)))) - { - tmp3 = 9830; - move16(); /*0.3 in Q15 */ - WHILE(LT_16(tmp3,32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; -#ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3, 3277); /*Q15 */ -#else - tmp3 = add(tmp3, 3277); /*Q15 */ -#endif - } - } - ELSE IF(LT_16(tmp2,tmp1)) - { - exp = norm_s(tmp1); - tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ -#ifdef BASOP_NOGLOB - tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ -#else - tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ -#endif - WHILE(LT_16(tmp3,32767)) - { - *pit1 = mult_r(*pit1,tmp3); - move16();/*Q_syn */ - pit1++; -#ifdef BASOP_NOGLOB - tmp3 = add_sat(tmp3, 3277); /*Q15 */ -#else - tmp3 = add(tmp3, 3277); /*Q15 */ -#endif - } - } - pit1 = &SWB_signal[495 + st_offset]; - - L_tmp3 = L_deposit_h(tmp1); /*Q17 */ - L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q17 */ - exp = 14; - move16(); - IF(tmp2 != 0) - { - exp = norm_s(tmp2); - tmp = div_s(shl(1,sub(14,exp)),tmp2); /*Q(29-exp) */ - L_tmp3 = L_shr(L_mult(tmp1,tmp),1); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ - L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q(30-exp) */ - } - - L_tmp1 = L_shl(1L,sub(30,exp)); - WHILE(GT_32(L_tmp3,L_tmp1)) - { - L_tmp = Mult_32_16(L_tmp3,*pit1); /*Q(16-exp) */ - *pit1-- = round_fx(L_shl(L_tmp,exp)); /*Q_syn */ - L_tmp3 = L_sub(L_tmp3,L_tmp4); - } - - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - } - } - - /* Normalize with envelope */ - test(); - IF(*frica_flag == 0 && NE_16(mode, NOISE)) - { - L = add(swb_bwe_subband[0],st_offset); - exp = norm_s(L_swb_norm); - inv_L_swb_norm = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */ - - IF(NE_16(mode,HARMONIC)) - { - tmp = add(shl(inv_L_swb_norm,1), inv_L_swb_norm); - weight = s_max(s_min(tmp,16384), 6554); - } - ELSE - { - weight = 6554; - move16(); - } - - weight = mac_r(L_mult(13107,weight) , 19661,(*prev_weight)); - - FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++) - { - signum[n_freq] = 1; - IF(SWB_signal[n_freq] < 0) - { - signum[n_freq] = -1; - move16(); - SWB_signal[n_freq] = negate(SWB_signal[n_freq]); - move16(); - } - L_tmp = Mult_32_16(envelope[n_freq],inv_L_swb_norm); /* Q_syn */ - L_tmp1 = L_deposit_l(SWB_signal[n_freq]); /* Q_syn */ - L_tmp = L_sub(L_tmp1,L_tmp); /* Q_syn */ - IF(L_tmp > 0) - { - tmp = shr(weight,1); /* Q14 */ - tmp = sub(19661,tmp); /* Q14 */ - SWB_signal[n_freq] = extract_l(L_shl(Mult_32_16(L_tmp,tmp),1)); /* Q_syn */ - } - ELSE - { - SWB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */ - } - - IF(NE_16(signum[n_freq],1)) - { - SWB_signal[n_freq] = negate(SWB_signal[n_freq]); - move16(); - } - } - - tmp_exp = sub(15,Q_syn); - FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++) - { - IF(envelope[n_freq] != 0) - { - exp = norm_l(envelope[n_freq]); - tmp = extract_h(L_shl(envelope[n_freq], exp)); - exp = sub(sub(30,exp), Q_syn); - tmp = div_s(16384,tmp); /* Q(15+exp) */ - L_tmp = L_shr(L_mult0(SWB_signal[n_freq],tmp), add(exp,Q_syn)); /* Q15 */ - SWB_signal[n_freq] = extract_l(L_tmp); /* Q15 */ - } - ELSE - { - SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp); - move16(); /* Q15 */ - } - } - *prev_weight = weight; - } - ELSE - { - exp = norm_s(L_swb_norm); - tmp = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */ - tmp = add(shl(tmp,1),tmp); - *prev_weight = s_max(s_min(tmp,16384),6554); /* Q15 */ - } - - IF(EQ_16(mode,HARMONIC)) - { - pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset]; - move16(); - FOR(n_band = 0; n_band < 19; n_band++) - { - L_mean = L_deposit_l(0); - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - L_mean = L_add(L_mean,abs_s(*pit1)); /*Q15 */ - pit1++; - } - mean = extract_l(Mult_32_16(L_mean,2048)); /*Q15 */ - pit1 -= 16; - move16(); - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - if (LT_16(abs_s(*pit1),mean)) - { - *pit1 = mult_r(*pit1,6554); /*Q15*/ move16(); - } - pit1++; - } - } - } - - L = 1; - move16(); - if (EQ_16(mode,HARMONIC)) - { - L = 2; - move16(); - } - - FOR(n_band = 0; n_band < SWB_FENV; n_band += L) - { - energy = L_deposit_l(0); - tmp = add(swb_bwe_subband[n_band + L],st_offset); - FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - L_tmp = L_mult(SWB_signal[n_freq],SWB_signal[n_freq]); /*Q31 */ - energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */ - } - - IF(energy == 0) - { - tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band];/*Q12 */ move16(); - if (NE_16(L,1)) - { - tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr(n_band, 1)];/*Q12 */ move16(); - } - - tmp = add(swb_bwe_subband[n_band + L],st_offset); - tmp_exp = sub(Q_syn,12); - FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(L_mult(tmp_ener,SWB_signal[n_freq]),tmp_exp); /*Qsyn */ - } - } - ELSE - { - tmp = sub(swb_bwe_subband[n_band + L], swb_bwe_subband[n_band]); - exp1 = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp1)), tmp); /*Q(29-exp1) */ - energy = Mult_32_16(energy, tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */ - - exp = norm_l(energy); - L_tmp = L_shl(energy, exp); - /*exp = 31-exp-(-exp1+39);move16(); */ - exp = sub(sub(exp1,exp),8); - Ltmp_ener = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - - tmp = add(swb_bwe_subband[n_band + L],st_offset); - tmp_exp = add(Q_syn,sub(exp,15)); - FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) - { - SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]),tmp_exp); - move32();/*Qsyn+16 */ - } - } - } - - IF(GT_16(*prev_Energy,add(Energy_16,shr(Energy_16,2))) && Energy_16 > 0) - { - weight = shr(div_s(Energy_16,*prev_Energy),1); /*Q15 */ - } - ELSE - { - weight = 16384; - move16();/*Q15 */ - } - L_tmp = L_mult(weight, prev_SWB_fenv[0]); /*Q17 */ - L_tmp = L_mac(L_tmp, sub(32767, weight), SWB_fenv[0]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - - tmp = norm_s(wfenv); - IF(GT_16(tmp,4)) - { - tmp = 12; - move16(); - factor = fenvL_16; - move16();/*Q3 */ - factor1 = mult_r(sub(shl(wfenv,2),fenvL_16),4096); /*Q3 */ - } - ELSE - { - tmp = 14; - move16(); - factor = shr(fenvL_16,2);/*Q1 */ - factor1 = mult_r(sub(wfenv,factor), 4096); /*Q1 */ - } - - tmp2 = add(add(swb_bwe_subband[0],8),st_offset); - FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1); - move32();/*15+Qsyn */ - factor = add(factor, factor1); /*Q3 */ - } - - FOR(n_band = 0; n_band < 12; n_band++) - { - L_tmp = L_mult(weight, prev_SWB_fenv[n_band + 1]); /*Q17 */ - L_tmp = L_mac(L_tmp, sub(32767,weight), SWB_fenv[n_band + 1]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - factor = SWB_fenv[n_band]; - move16(); /*Q1 */ - factor1 = mult_r(sub(wfenv,SWB_fenv[n_band]), smooth_factor_fx[n_band]); /*Q1 */ - tmp = norm_s(factor); - IF(GT_16(tmp,4)) - { - tmp = 12; - move16(); - factor = shl(factor, 2); - factor1 = shl(factor1, 2); - } - ELSE - { - tmp = 14; - move16(); - } - - tmp2 = add(swb_bwe_sm_subband[n_band + 1],st_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1); - move32(); /*15+Qsyn */ - factor = add(factor, factor1); /*Q1 */ - } - } - L_tmp = L_mult(weight, prev_SWB_fenv[13]); /*Q17 */ - L_tmp = L_mac(L_tmp,sub(32767,weight), SWB_fenv[13]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - factor = SWB_fenv[12]; - move16();/*Q1 */ - factor1 = mult_r(sub(wfenv, SWB_fenv[12]), smooth_factor_fx[12]); /*Q1 */ - tmp2 = add(swb_bwe_sm_subband[13],st_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1,13); - move32();/*15+Qsyn */ - factor = add(factor,factor1); /*Q1 */ - } - - FOR(n_band = 13; n_band < SWB_FENV; n_band++) - { - L_tmp = L_mult(weight, prev_SWB_fenv[n_band]); /*Q17 */ - L_tmp = L_mac(L_tmp,sub(32767, weight), SWB_fenv[n_band]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - tmp2 = add(swb_bwe_subband[n_band + 1],st_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1,13); - move32(); /*15+Qsyn */ - } - } - FOR(n_band = 0; n_band < SWB_FENV; n_band++) - { - prev_SWB_fenv[n_band] = SWB_fenv[n_band]; - move16();/*Q1 */ - } - } - pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */ - FOR(n_freq = 0; n_freq < 4; n_freq++) - { - L_tmp1 = Mult_32_16(*pit1_32, 16384); /*15+Qsyn */ - *(pit1_32++) = L_tmp1; - move32(); - } - *prev_Energy = Energy_16; - move16(); - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void time_envelop_shaping_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Time shaping of SHB signal */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS */ -/* _(Word16) L :length */ -/* _(Word16) Q_syn :Q format */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16[])werr : SHB synthesis */ -/* _(Word16[])SWB_tenv : frequency envelope */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -void time_envelop_shaping_fx( - Word16 werr[], /* i/o: SHB synthesis Q_synth*/ - Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ - const Word16 L, /* i : frame length */ - Word16 *Q_synth -) -{ - Word16 *pit; - Word32 Energy; - Word16 i, j; - Word16 tmp_ener, Energy_16; - Word16 exp_L, exp, frac, tmp, inv_L; - Word32 L_tmp; - - pit = werr; - move16(); - exp_L = norm_s(L); - inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */ - FOR(i = 0; i < SWB_TENV; i++) - { - Energy = L_deposit_l(0); - FOR(j = 0; j < L / 4; j++) - { -#ifdef BASOP_NOGLOB - Energy = L_mac0_sat(Energy, *pit, *pit); /*(2*Q_synth) */ -#else - Energy = L_mac0(Energy, *pit, *pit); /*(2*Q_synth) */ -#endif - pit++; - } - Energy = Mult_32_16(Energy, inv_L); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth) */ - Energy_16 = 0; - move16(); - /*exp = 31-(-exp_L+14 +(2*(*Q_synth))); */ - exp = sub(17, sub(shl((*Q_synth), 1), exp_L)); - - IF(Energy != 0) - { - exp = norm_l(Energy); - frac = extract_h(L_shl(Energy, exp)); - /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)))); */ - exp = sub(exp, sub(30, add(sub(shl((*Q_synth), 1), exp_L), 14 - 2))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - Energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - Energy_16 = round_fx(L_shl(Energy, sub(exp, 15))); /*Q0 */ - } - - test(); -#ifdef BASOP_NOGLOB - IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl_sat(SWB_tenv[i], sub(16, exp)))) -#else - IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl(SWB_tenv[i], sub(16, exp)))) -#endif - { - *Q_synth = add(*Q_synth, 3); - move16(); - } - ELSE - { - pit -= L / 4; - move16(); - tmp_ener = 0; - move16(); - exp = 0; - move16(); - - IF(Energy_16 != 0) - { - exp = norm_s(Energy_16); - tmp_ener = div_s(shl(1,sub(14,exp)), Energy_16); /*Q(29-exp) */ - } - - L_tmp = Mult_32_16(SWB_tenv[i], tmp_ener); /*Q(29-exp) */ - tmp = round_fx(L_tmp); /*Q(13-exp) */ - - FOR(j = 0; j < L / 4; j++) - { -#ifdef BASOP_NOGLOB - *pit = round_fx_sat(L_shl_sat(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ -#else - *pit = round_fx(L_shl(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ -#endif - pit++; - } - } - } - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void time_reduce_pre_echo_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Windowing and time-domain aliasing */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS */ -/* _(Word16*) synth :ACELP core synthesis Q_syn */ -/* _(Word16) L :subframe length */ -/* _(Word16) Q_syn :Q format */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)error : SHB BWE synthesis Q_syn */ -/* _(Word16)prev_td_energy : last td energy Q_syn */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ - Word16 *error, /* i/o: SHB BWE synthesis Q0*/ - Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ - Word16 Q_syn, - Word16 Q_synth -) -{ - Word16 i, j, pos = 0, Len; - Word32 energy; - Word16 energy_16; - Word32 energyL[4]; - Word16 tmp_ener; - Word16 *pit; - Word16 tmpi, tmp_exp; - Word16 exp_L, exp, frac, inv_L, exp_j, tmp; - Word32 L_tmp, L_tmp1, Ltmp_ener; - - exp_L = norm_s(L); - inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */ - FOR(i = 0; i < 4; i++) - { - Len = i_mult(L, i); - - L_tmp = L_deposit_l(0); - FOR(j = 0; j < L; j++) - { - L_tmp = L_mac0(L_tmp, synth[Len + j], synth[Len + j]); /*2*Q_syn */ - } - energyL[i] = Mult_32_16(L_shr(L_tmp, sub(14, exp_L)), inv_L); - move32(); /*Q(2*Q_syn +29-exp_L-15 - (14-exp_L) ) -> Q(2*Q_syn) */ - - IF(energyL[i] != 0) - { - exp = norm_l(energyL[i]); - frac = extract_h(L_shl(energyL[i], exp)); - exp = sub(exp, sub(30, shl(Q_syn, 1))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - energyL[i] = L_shl(L_tmp, sub(exp, 16)); - move32();/* Q15 */ - } - } - - FOR(i = 0; i < 3; i++) - { - L_tmp = Mult_32_16(energyL[i], 29491); /*Q14 */ - test(); - IF(GT_32(L_shr(energyL[i + 1], 1), L_tmp) && GT_32(energyL[i + 1], 1638400)) - { - pos = add(i, 1); - move16(); - BREAK; - } - } - - IF(pos > 0) - { - if (LT_16(pos, 3)) - { - pos = add(pos, 1); - } - energy = L_deposit_l(0); - j = i_mult(L, pos); - move16(); - FOR(i = 0; i < j; i++) - { -#ifdef BASOP_NOGLOB - energy = L_mac0_sat(energy, error[i], error[i]); /*Q(2*Q_synth) */ -#else - energy = L_mac0(energy, error[i], error[i]); /*Q(2*Q_synth) */ -#endif - } - - exp_j = norm_s(j); - tmp = div_s(shl(1, sub(14, exp_j)), j); /*Q(29-exp_j) */ - energy = Mult_32_16(energy, tmp); /*Q(29-exp_j+1-16) -> Q(-exp_j+14 +2*Q_synth) */ - energy_16 = 0; - move16(); - - IF(energy != 0) - { - exp = norm_l(energy); - frac = extract_h(L_shl(energy, exp)); - /*exp = sub(exp, 30-(-exp_j+14 +2*Q_synth)); */ - exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_j))); - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */ - } - - tmp = mult_r(energy_16, 6554); /*Q0 */ - if (LT_16(prev_td_energy, tmp)) - { - prev_td_energy = tmp; - move16(); - } - - tmp_ener = 0; - move16(); - exp = 0; - move16(); - IF(energy_16 != 0) - { - exp = norm_s(energy_16); - tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */ - } - L_tmp = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ - tmp_exp = add(1, exp); - FOR(i = 0; i < j; i++) - { -#ifdef BASOP_NOGLOB - error[i] = round_fx_sat(L_shl_sat(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ -#else - error[i] = round_fx(L_shl(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ -#endif - } - - energy = L_deposit_l(0); - FOR(i = j; i < (j + L); i++) - { -#ifdef BASOP_NOGLOB - energy = L_mac0_sat(energy, error[i], error[i]); /*(2*Q_synth) */ -#else - energy = L_mac0(energy, error[i], error[i]); /*(2*Q_synth) */ -#endif - } - - energy = Mult_32_16(energy, inv_L); /*Q(29-exp_L+1-16) -> Q(-exp_L+14) */ - energy_16 = 0; - move16(); - IF(energy != 0) - { - exp = norm_l(energy); - frac = extract_h(L_shl(energy, exp)); - /*exp = sub(exp, 30-(-exp_L+14+2*Q_synth)); */ - exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_L))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */ - } - - tmp_ener = 0; - move16(); - exp = 0; - move16(); - IF(energy_16 != 0) - { - exp = norm_s(energy_16); - tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */ - } - Ltmp_ener = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ - L_tmp1 = L_shl(1, sub(30, exp)); - - pit = &error[j]; - move16(); - FOR(i = 0; i < L; i++) - { - tmpi = round_fx(L_shl(L_mult(i, inv_L), add(1, exp_L))); /*Q15 */ - L_tmp = L_sub(L_tmp1, Ltmp_ener); /*Q(30-exp) */ - L_tmp = Mult_32_16(L_tmp, tmpi); /*Q(30-exp) */ - L_tmp = L_add(Ltmp_ener, L_tmp); /*Q(30-exp) */ - tmp = round_fx(L_shl(Mult_32_16(L_tmp, *pit), add(1, exp))); /*Q0 */ - *pit++ = tmp; - } - } - - return; -} - -/*-------------------------------------------------------------------* - * calc_normal_length_fx_32() - * - *-------------------------------------------------------------------*/ -void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : input signal : Q12 */ - const Word16 mode, /* i : input mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ -) -{ - Word16 i, n_freq, n_band, THRES; - Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; - Word16 N; - - const Word32 *pit; - Word32 peak, mean, mag; - Word32 L_tmp1, L_tmp2; - - THRES = 4; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) || EQ_16(extl, SWB_BWE) || EQ_16(extl, FB_BWE)) - { - THRES = 8; - move16(); - } - - N = 16; - move16(); - test(); - test(); - if (EQ_16(core, HQ_CORE) && (EQ_16(mode, HQ_HARMONIC) || EQ_16(mode, HQ_HVQ))) - { - N = 13; - move16(); - } - - n_band = 0; - move16(); - pit = sp; - move16(); - FOR(i = 0; i < N; i++) - { - peak = 0; - move16(); - mean = 0; - move16(); - - FOR(n_freq = 0; n_freq < 16; n_freq++) - { - mag = L_abs(*pit); - if (GT_32(mag, peak)) - { - peak = mag; - move16(); - } - mean = L_add(mean, mag); - pit++; - } - - L_tmp1 = Mult_32_16(peak, shl(15 + THRES, 10)); - L_tmp2 = Mult_32_16(mean, shl(THRES, 10)); - test(); - if (GT_32(L_tmp1, L_tmp2) && GT_32(peak, 40960)) - { - n_band = add(n_band, 1); - } - } - - IF(EQ_16(core, ACELP_CORE)) - { - L_swb_norm_trans = add(4, shr(n_band, 2)); - L_swb_norm_norm = add(8, shr(n_band, 1)); - L_swb_norm_harm = s_max(add(32, shl(n_band, 1)), 24); - - IF(mode == HARMONIC) - { - L_swb_norm_cur = L_swb_norm_harm; - move16(); - } - ELSE IF(mode == NORMAL) - { - L_swb_norm_cur = L_swb_norm_norm; - move16(); - } - ELSE - { - L_swb_norm_cur = L_swb_norm_trans; - move16(); - } - - *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1); - move16(); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - ELSE - { - test(); - IF(mode == HQ_HARMONIC || mode == HQ_HVQ) - { - L_swb_norm_cur = add(32, add(shl(n_band, 1), shr(n_band, 1))); - } - ELSE - { - L_swb_norm_cur = add(8, shr(n_band, 1)); - } - - *L_swb_norm = extract_h(L_add(L_mac(L_mult(L_swb_norm_cur, 3276), *prev_L_swb_norm, 29491),32768)); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - - return; -} - - -/*-------------------------------------------------------------------* - * calc_norm_envelop_fx_32() - * - *-------------------------------------------------------------------*/ -void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of input/output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ -) -{ - Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; - - lookback = L_swb_norm / 2; - move16(); - env_index = swb_bwe_subband[0] + st_offset; - move16(); - n_lag_now = L_swb_norm; - move16(); - tmp = sub(add(SWB_flength, st_offset), L_swb_norm); - FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++) - { - /* Apply MA filter */ - envelope_fx[env_index] = 0; - move16(); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - envelope_fx[env_index] = L_add(envelope_fx[env_index], L_abs(SWB_signal_fx[add(n_freq, n_lag)])); - move32(); - } - env_index++; - } - i = 0; - move16(); - tmp = sub(add(SWB_flength, st_offset), lookback); - FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++) - { - Word32 L_tmp; - - n_lag_now = L_swb_norm - i; - move16(); - /* Apply MA filter */ - L_tmp = L_deposit_l(0); - FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) - { - L_tmp = L_add(L_tmp, L_abs(SWB_signal_fx[n_freq + n_lag])); - } - envelope_fx[env_index] = L_tmp; - move32(); - env_index = add(env_index, 1); - i++; - } - - return; -} - -/*-------------------------------------------------------------------* - * hq_generic_decoding_fx() - * - *-------------------------------------------------------------------*/ -void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode : Q0 */ - Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ - const Word16 *R -) -{ - Word16 i, n_freq, n_band, L_swb_norm; - Word16 k; - Word16 nenv; - Word16 tenv; - - Word16 exp, exp1, exp2, frac, tmp, tmp2, cs; - Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx; - Word16 fenvL_fx, wfenv_fx, factor_fx; - Word32* pit1_fx; - Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx; - Word32 energy_fx; - - Word32 envelope_fx[L_FRAME16k]; - Word32 mean_vector_fx[20]; - Word16 rn_weight0_fx; - Word16 s; - Word16 blen, nband_lf, sfidx, efidx; - Word16 bwe_seed; - Word16 signum[L_FRAME16k]; - - nenv = sub(SWB_FENV, 2); - if (LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - nenv = SWB_FENV; - move16(); - } - - tenv = nenv; - move16(); - if (EQ_16(HQ_mode, HQ_GEN_FB)) - { - tenv = add(nenv, DIM_FB); - } - - max_coeff_fx = 0; - move16(); - tmp = add(swb_bwe_subband[0], hq_generic_offset); - FOR(n_freq = add(HQ_GENERIC_ST_FREQ, hq_generic_offset); n_freq < tmp; n_freq++) - { - max_coeff_fx = L_max(max_coeff_fx, L_abs(coeff_out1_fx[n_freq])); - } - cs = norm_l(max_coeff_fx); - - L_tmp = 0; - move16(); - tmp2 = add(swb_bwe_subband[0], hq_generic_offset); - FOR(n_freq = add(HQ_GENERIC_ST_FREQ, hq_generic_offset); n_freq < tmp2; n_freq++) - { - tmp = extract_h(L_shl(coeff_out1_fx[n_freq], cs));/*12 + cs - 16 */ - L_tmp1 = L_mult0(tmp, tmp);/*2*(cs-2) */ - L_tmp = L_add(L_tmp, L_shr(L_tmp1, 5));/*2*(cs-2) - 5 */ - } - cs = sub(shl(cs, 1), 9); - fenvL_fx = 0; - move16(); - IF(L_tmp != 0) - { - exp = norm_l(L_tmp); -#ifdef EVS_FUNC_MODIFIED - frac = round_fx_sat(L_shl(L_tmp, exp));/*cs+exp-16 */ -#else - frac = round_fx(L_shl(L_tmp, exp));/*cs+exp-16 */ -#endif - tmp = div_s(16384, frac);/*15 + 14 - (cs+exp-16) */ - exp = sub(add(cs, exp), 30); - L_tmp = Isqrt_lc(L_deposit_h(tmp), &exp);/*Q31 - exp */ - fenvL_fx = round_fx(L_shl(L_tmp, sub(exp, 14)));/*Q1 */ - } - - calc_normal_length_fx_32(HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm); - - calc_norm_envelop_lf_fx(coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx); - - blen = 16; - move16(); - - IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC0)) - { - rn_weight0_fx = 819; - move16();/* 0.8 Q10 */ - } - ELSE IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC1)) - { - rn_weight0_fx = 51; - move16();/* 0.05 Q10*/ - } - ELSE - { - rn_weight0_fx = 205; - move16();/* 0.02 Q10 */ - } - - tmp = sub(efidx, sfidx); - IF(EQ_16(tmp, 0)) - { - nband_lf = 0; - } - ELSE - { - exp = norm_s(tmp); - nband_lf = shl(tmp,sub(exp,1)); - exp1 = norm_s(blen); - tmp = shl(blen,exp1); - nband_lf = shr(div_s(nband_lf,tmp), add(sub(14,exp1),exp));/* 15 + exp-1 - exp1, Q0*/ - } - - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - IF(coeff_out1_fx[n_freq] < 0) - { - signum[n_freq] = -1; - move16(); - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - ELSE - { - signum[n_freq] = 1; - move16(); - } - } - - /* applying whitening */ - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - exp = norm_l(coeff_out1_fx[n_freq]) - 1; - exp1 = norm_l(envelope_fx[n_freq]); - - L_tmp = L_shl(coeff_out1_fx[n_freq], exp); - L_tmp1 = L_shl(envelope_fx[n_freq], exp1); - - logic16(); - coeff_out1_fx[n_freq] = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - move32();/*31 + exp1 - exp2*/ - - exp = add(31, sub(exp, exp1)); - coeff_out1_fx[n_freq] = L_shl(coeff_out1_fx[n_freq], sub(20, exp)); - move32();/*Q12->Q20*/ - } - - /* mean vector generation for controlling dynamic range */ - FOR(k = 0; k < nband_lf; ++k) - { - energy_fx = 1; - move16(); - - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add(i_mult2(k, blen), sfidx); i < tmp; ++i) - { - energy_fx = L_add(energy_fx, coeff_out1_fx[i]); - } - exp = sub(norm_l(energy_fx), 1); - L_tmp = L_shl(energy_fx, exp); - exp1 = norm_l(L_and(blen, 0x00007fff)); - L_tmp1 = L_shl(blen, exp1); - logic16(); - mean_vector_fx[k] = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - move32();/*31 + 20 + exp1 - exp2*/ - exp = add(51, sub(exp, exp1)); - mean_vector_fx[k] = L_shl(mean_vector_fx[k], sub(20, exp)); - move32();/*Q12->Q20*/ - } - - /* dynamics control */ - FOR(k = 0; k < nband_lf; ++k) - { - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add(i_mult2(k, blen), sfidx); i < tmp; ++i) - { - L_tmp = L_sub(coeff_out1_fx[i], mean_vector_fx[k]); - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /* exp+12*/ - exp1 = norm_l(rn_weight0_fx); - L_tmp1 = L_shl(rn_weight0_fx, exp1); /* exp1+10*/ - L_tmp = L_mult(extract_h(L_tmp), extract_h(L_tmp1)); - L_tmp = L_shr(L_tmp, add(exp, sub(exp1, 21))); /* Q20*/ - coeff_out1_fx[i] = L_sub(coeff_out1_fx[i], L_tmp); - move32(); - } - } - - IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC0)) - { - bwe_seed = add(add(shl(R[0], 3), shl(R[1], 2)), add(shl(R[2], 1), R[3])); - - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - IF(signum[n_freq] < 0) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - - IF(Random(&bwe_seed) < 0) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - } - } - ELSE - { - FOR(n_freq = sfidx; n_freq < efidx; n_freq++) - { - IF(signum[n_freq] < 0) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - } - } - - /* normalizing modified low frequency spectrum */ - FOR(k = 0; k < nband_lf; ++k) - { - energy_fx = 1; - move16(); - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add((i_mult2(k, blen)), sfidx); i < tmp; ++i) - { - exp = norm_l(coeff_out1_fx[i]); - L_tmp1 = L_shl(coeff_out1_fx[i], exp);/* exp + 12*/ - - L_tmp = Mult_32_32(L_tmp1, L_tmp1); - L_tmp = L_shr(L_tmp, sub(i_mult2(2, exp), 11));/*Q20 */ - energy_fx = L_add(energy_fx, L_tmp); - } - - exp = norm_l(energy_fx); - L_tmp = L_shl(energy_fx, sub(exp, 1)); - exp1 = norm_s(blen); - L_tmp1 = L_shl((Word32)blen, add(exp1, 16)); - - L_tmp = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - exp = sub(add(34, exp), exp1); - L_tmp = L_shr(L_tmp, sub(exp, 31)); - exp = 31; - move16(); - - exp = sub(31, exp); - IF(exp & 0x1) - { - L_tmp = L_shr(L_tmp, 1); - exp = add(exp, 1); - } - L_tmp = Sqrt_l(L_tmp, &exp1); - exp = add(31, sub(shr(exp1, 1), shr(exp, 1))); - energy_fx = L_shl(L_tmp, sub(31, exp)); /*Q31*/ - - tmp = add(i_mult2(add(k, 1), blen), sfidx); - FOR(i = add((i_mult2(k, blen)), sfidx); i < tmp; ++i) - { - IF(NE_32(L_abs(coeff_out1_fx[i]), coeff_out1_fx[i])) - { - s = -1; - move16(); - coeff_out1_fx[i] = L_abs(coeff_out1_fx[i]); - move32(); - } - ELSE - { - s = 0; - move16(); - } - exp = norm_l(coeff_out1_fx[i]); - L_tmp = L_shl(coeff_out1_fx[i], sub(exp, 1)); - exp1 = norm_l(energy_fx); - L_tmp1 = L_shl((Word32)energy_fx, exp1); - logic16(); - L_tmp = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); - exp = add(sub(19, exp1), exp); - coeff_out1_fx[i] = L_shl(L_tmp, add(sub(12, exp), 15)); - move32(); /* Q12 -> Q27 */ - IF(s) - { - coeff_out1_fx[i] = L_negate(coeff_out1_fx[i]); - move32(); - } - } - } - - Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH0, hq_generic_offset)], HQ_GENERIC_LEN0); - Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH1, hq_generic_offset)], HQ_GENERIC_LEN0); - - IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - Copy32(&coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)], sub(HQ_GENERIC_END_FREQ, HQ_GENERIC_HIGH2)); - } - - IF(EQ_16(HQ_mode, HQ_GEN_FB)) - { - IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - Copy32(&coeff_out1_fx[sub(add(HQ_GENERIC_LOW0, HQ_GENERIC_END_FREQ), HQ_GENERIC_HIGH2)], &coeff_out_fx[fb_bwe_subband[0]], 160); - } - ELSE - { - Copy32(&coeff_out1_fx[add(HQ_GENERIC_OFFSET , HQ_GENERIC_LEN0)], &coeff_out_fx[fb_bwe_subband[0]], 160); - } - } - - - L_tmp1 = L_deposit_l(0); - L_tmp2 = L_deposit_l(0); - FOR(i = 0; i < 5; ++i) - { - L_tmp1 = L_add(L_tmp1, L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH1, hq_generic_offset), i)])); - L_tmp2 = L_add(L_tmp2, L_abs(coeff_out_fx[sub(add(sub(HQ_GENERIC_HIGH1, 2), hq_generic_offset), i)])); - } - - pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH1, hq_generic_offset)]; - L_tmp1 = L_max(L_tmp1, 1); - L_tmp2 = L_max(L_tmp2, 1); - exp1 = norm_l(L_tmp1); - exp2 = sub(norm_l(L_tmp2), 1); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ - - if (LT_16(tmp3_fx, 307)) - { - tmp3_fx = 307; - move16(); - } - FOR(; tmp3_fx < 1024; tmp3_fx += 102) - { - *pit1_fx = Mult_32_16(*pit1_fx, shl(tmp3_fx, 5)); - move32();/*15 + 5 + 10 -15 */ - pit1_fx++; - } - - pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH1, 1), hq_generic_offset)]; - - exp1 = sub(norm_l(L_tmp1), 1); - exp2 = norm_l(L_tmp2); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ - - IF(GT_16(tmp3_fx, 5120)) - { - FOR(tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512) - { - L_tmp1 = Mult_32_16(L_shl(*pit1_fx, 5), tmp3_fx); /*15 + 5 + 10 -15 */ - *pit1_fx-- = L_tmp1; - move32(); - } - } - - IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) - { - L_tmp1 = L_add(L_abs(coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)]), L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH2, 1), hq_generic_offset)])); - L_tmp2 = L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 4), hq_generic_offset)]), L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 3), hq_generic_offset)]), - L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 2), hq_generic_offset)]), L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 1), hq_generic_offset)])))); - - pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)]; - - L_tmp1 = L_max(L_tmp1, 1); - L_tmp2 = L_max(L_tmp2, 1); - exp1 = norm_l(L_tmp1); - exp2 = sub(norm_l(L_tmp2), 1); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ - - if (LT_16(tmp3_fx, 307)) - { - tmp3_fx = 307; - move16(); - } - FOR(; tmp3_fx < 1024; tmp3_fx += 102) - { - L_tmp = L_shl(Mult_32_16(*pit1_fx, tmp3_fx), 5); /*15 + 5 + 10 -15 */ - *pit1_fx++ = L_tmp; - move32(); - } - - pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 1), hq_generic_offset)]; - - exp1 = sub(norm_l(L_tmp1), 1); - exp2 = norm_l(L_tmp2); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ - tmp3_fx = shr(tmp3_fx, 1); - tmp4_fx = mult_r(tmp3_fx, 1638); - WHILE(tmp3_fx > 1024) - { -#ifdef EVS_FUNC_MODIFIED - L_tmp1 = L_shl(Mult_32_16(*pit1_fx , tmp3_fx), 5); /*15 + 5 + 10 -15 */ -#else - L_tmp1 = Mult_32_16(L_shl(*pit1_fx, 5), tmp3_fx); /*15 + 5 + 10 -15 */ -#endif - *pit1_fx-- = L_tmp1; - move32(); - tmp3_fx = sub(tmp3_fx, tmp4_fx); - } - } - - - wfenv_fx = hq_generic_fenv_fx[0]; - move16();/*1 */ - i = 0; - move16(); - tmp2 = add(add(swb_bwe_subband[0], hq_generic_offset), 8); - FOR(n_freq = add(swb_bwe_subband[0], hq_generic_offset); n_freq < tmp2; n_freq++) - { - factor_fx = shl(i, 12);/*15 */ - L_tmp1 = L_mult(sub(32767, factor_fx), fenvL_fx);/*17 */ - L_tmp2 = L_mult(factor_fx, wfenv_fx);/*17 */ - L_tmp1 = L_add(L_tmp1, L_tmp2);/*17 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*17 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 17 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, add(1, cs)); - move32();/*12 */ - i++; - move16(); - } - - k = sub(nenv, 2); - FOR(n_band = 0; n_band < k; n_band++) - { - wfenv_fx = hq_generic_fenv_fx[add(n_band, 1)]; - move16();/*1 */ - - tmp2 = swb_bwe_sm_subband[add(n_band, 1)] + hq_generic_offset; - FOR(i = 0; n_freq < tmp2; i++) - { - L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[n_band]), smooth_factor_fx[n_band]);/*17 */ - L_tmp1 = Mult_32_16(L_tmp1, shl(i, 10));/*17 + 10 - 15 */ - L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[n_band], 11));/*12 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*12 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 12 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl(L_tmp, sub(4, cs)); - move32();/*12 */ - n_freq++; - } - } - - wfenv_fx = hq_generic_fenv_fx[sub(nenv, 1)]; - move16();/*1 */ - tmp2 = add(swb_bwe_sm_subband[sub(nenv, 1)], hq_generic_offset); - FOR(i = 0; n_freq < tmp2; i++) - { - L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[sub(nenv, 2)]), smooth_factor_fx[sub(nenv, 2)]);/*17 */ - L_tmp1 = Mult_32_16(L_tmp1, shl(i, 10));/*17 + 10 - 15 */ - L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[sub(nenv, 2)], 11));/*12 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*12 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 12 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl(L_tmp, sub(4, cs)); - move32();/*12 */ - n_freq++; - } - - IF(EQ_16(HQ_mode, HQ_GEN_SWB)) - { - FOR(n_band = sub(nenv, 1); n_band < nenv; ++n_band) - { - wfenv_fx = hq_generic_fenv_fx[n_band]; - move16();/*1 */ - tmp2 = add(swb_bwe_subband[add(n_band, 1)], hq_generic_offset); - FOR(; n_freq < tmp2; n_freq++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - } - } - } - ELSE - { - test(); - IF(hq_generic_fenv_fx[sub(nenv,1)] - hq_generic_fenv_fx[nenv] > 30 || hq_generic_fenv_fx[nenv] < 10) - { - wfenv_fx = hq_generic_fenv_fx[sub(nenv,1)]; - move16();/*1 */ - FOR(i = 0; n_freq < fb_bwe_subband[0]; i++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - n_freq++; - } - - FOR(n_band = 0; n_band < DIM_FB; n_band++) - { - wfenv_fx = hq_generic_fenv_fx[add(n_band , nenv)]; - move16();/*1 */ - tmp2 = fb_bwe_subband[add(n_band,1)]; - FOR(i = 0; n_freq < tmp2; i++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - n_freq++; - } - } - } - ELSE - { - FOR(n_band = 0; n_band < DIM_FB; n_band++) - { - wfenv_fx = hq_generic_fenv_fx[sub(add(n_band,nenv),1)]; - move16();/*1 */ - - FOR(i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++) - { - L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[add(n_band,nenv)]), fb_smooth_factor_fx[n_band]);/*17 */ - L_tmp1 = Mult_32_16(L_tmp1, shl(i, 9));/*17 + 9 - 15 */ - L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[add(n_band,nenv)], 10));/*11 */ - - cs = norm_l(L_tmp1); - tmp = extract_h(L_shl(L_tmp1, cs));/*11 + cs - 16 */ - L_tmp = Mult_32_16(coeff_out_fx[n_freq] , tmp);/*12 + 15 + 11 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl(L_tmp, sub(5, cs)); - move32();/*12 */ - n_freq++; - } - } - - wfenv_fx = hq_generic_fenv_fx[sub(tenv,1)]; - move16();/*1 */ - - FOR(; n_freq < fb_bwe_subband[DIM_FB]; n_freq++) - { - L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr(L_tmp, 1); - move32();/*12 */ - } - } - } - - return; -} - - - -/*-------------------------------------------------------------------* - * save_old_syn() - * - * Save and delay the ACELP core synthesis signal by - * DELAY_FD_BWE_ENC_xxkx to be used by SWB BWE - *-------------------------------------------------------------------*/ - -void save_old_syn_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 syn[], /* i : ACELP synthesis */ - Word16 old_syn[], /* o : old synthesis buffer */ - Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ - const Word16 preemph_fac, /* i : preemphasis factor */ - Word16 *mem_deemph /* i/o: deemphasis filter memory */ -) -{ - Word16 tmps; - - tmps = NS2SA(16000, DELAY_FD_BWE_ENC_16k_NS); - move16(); - if (EQ_16(L_frame, L_FRAME)) - { - tmps = NS2SA(12800, DELAY_FD_BWE_ENC_12k8_NS); - move16(); - } - Copy(old_syn_mem, old_syn, tmps); - Copy(syn, old_syn + tmps, L_frame - tmps); - Copy(syn + L_frame - tmps, old_syn_mem, tmps); - - deemph_fx(old_syn, preemph_fac, L_frame, mem_deemph); - - return; -} +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include "options.h" +#include "prot_fx2.h" +#include "prot_fx1.h" +#include "basop_util.h" +#include "rom_com.h" + + + /*==========================================================================*/ + /* FUNCTION : Word16 WB_BWE_gain_pred_fx () */ + /*--------------------------------------------------------------------------*/ + /* PURPOSE : predict WB frequency envelopes for 0b WB BWE */ + /*--------------------------------------------------------------------------*/ + /* INPUT ARGUMENTS : */ + /* _Word16 *core_dec_freq i : Frequency domain core decoded signal */ + /* _Word16 coder_type i : coding type */ + /* _Word16 prev_coder_type i : coding type of last frame */ + /* _Word16 prev_WB_fenv i : envelope for last frame */ + /* _Word16 *voice_factors i : voicing factors //Q15 */ + /* _Word16 pitch_buf[] i : pitch buffer //Q6 */ + /* _Word16 last_core_brate i : previous frame core bitrate */ + /* _Word16 last_wb_bwe_ener i : previous frame wb bwe signal energy */ + /*--------------------------------------------------------------------------*/ + /* OUTPUT ARGUMENTS : */ + /* _Word16 *WB_fenv, o : WB frequency envelopes Q3 */ + /*--------------------------------------------------------------------------*/ + /* INPUT/OUTPUT ARGUMENTS : */ + /*--------------------------------------------------------------------------*/ + /* RETURN ARGUMENTS : */ + /* _Word16 mode */ + /*--------------------------------------------------------------------------*/ + /* CALLED FROM : */ + /*==========================================================================*/ + +Word16 WB_BWE_gain_pred_fx( + Word16 *WB_fenv, /* o : WB frequency envelopes */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + const Word16 coder_type, /* i : coding type */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 prev_WB_fenv, /* i : envelope for last frame */ + Word16 *voice_factors, /* i : voicing factors //Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ + Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ + Word16 Q_syn, /* i : synthesis scaling */ + Word16 last_extl_fx, /* i : extl. layer for last frame */ + Word16 tilt_wb_fx +) +{ + Word32 enerL; + Word16 n_freq, mode, pitch; + Word16 ener_var_flag = 0; + Word16 voice_factor, enerL_16, enerL_40, enerL_64; + Word16 env_var_flag = 0; + Word16 exp; + Word16 tmp, tmp1; + Word32 L_tmp; + Word32 L_WB_fenv0, L_WB_fenv1; + Word16 pitch_buf_tmp[4]; + Word16 alfa = 32767; + move16(); + + mode = NORMAL; + move16(); + + enerL = L_deposit_l(0); + FOR(n_freq = 128; n_freq < 192; n_freq++) + { +#ifdef BASOP_NOGLOB + enerL = L_mac0_sat(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */ +#else + enerL = L_mac0(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */ +#endif + } + + L_WB_fenv0 = L_deposit_l(0); + FOR(n_freq = 192; n_freq < 224; n_freq++) + { +#ifdef BASOP_NOGLOB + L_WB_fenv0 = L_mac0_sat(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ +#else + L_WB_fenv0 = L_mac0(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ +#endif + } + + L_WB_fenv1 = L_deposit_l(0); + FOR(n_freq = 224; n_freq < 256; n_freq++) + { +#ifdef BASOP_NOGLOB + L_WB_fenv1 = L_mac0_sat(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ +#else + L_WB_fenv1 = L_mac0(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */ +#endif + } + + L_tmp = sum16_32_fx(voice_factors, 4); + voice_factor = extract_l(L_shr(L_tmp, 2));/*Q13 */ + Copy_Scale_sig(pitch_buf, pitch_buf_tmp, 4, -1); + pitch = sum16_fx(pitch_buf_tmp, 4); + move16(); /*Q5 */ + + L_tmp = L_shr(enerL, 4); + test(); + IF(GT_32(L_max(L_WB_fenv1, L_WB_fenv0), L_tmp) && GT_16(9856, pitch)) + { + ener_var_flag = 1; + move16(); + } + + test(); +#ifdef BASOP_NOGLOB + IF(GT_32(L_WB_fenv0, L_shl_sat(L_WB_fenv1, 1))) +#else + IF(GT_32(L_WB_fenv0, L_shl(L_WB_fenv1, 1))) +#endif + { + exp = norm_l(L_WB_fenv0); + tmp = extract_h(L_shl(L_WB_fenv0, exp)); + tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ + L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv1, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ + /*L_tmp Q15 */ + tmp = extract_l(L_tmp); + alfa = s_max(tmp, 3277);/*Q15 */ + L_WB_fenv0 = Mult_32_16(L_WB_fenv0, alfa);/*2*Q_syn+15-15->2*Q_syn */ + } +#ifdef BASOP_NOGLOB + ELSE IF(GT_32(L_WB_fenv1, L_shl_sat(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED)) +#else + ELSE IF(GT_32(L_WB_fenv1, L_shl(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED)) +#endif + { + exp = norm_l(L_WB_fenv1); + tmp = extract_h(L_shl(L_WB_fenv1, exp)); + tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ + L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv0, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ + /*L_tmp Q15 */ + tmp = extract_l(L_tmp); + alfa = s_max(tmp, 3277);/*Q15 */ + L_WB_fenv1 = Mult_32_16(L_WB_fenv1, alfa);/*2*Q_syn+15-15->2*Q_syn */ + } + + if (L_WB_fenv0 == 0) + { + L_WB_fenv0 = L_deposit_l(1); + } + + if (L_WB_fenv1 == 0) + { + L_WB_fenv1 = L_deposit_l(1); + } + + if (enerL == 0) + { + enerL = L_deposit_l(1); + } + +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */ +#else + L_tmp = L_add(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */ +#endif + exp = norm_l(L_tmp); + tmp = extract_h(L_shl(L_tmp, exp)); + /*exp = sub(exp, 30-(2*Q_syn+6)); //+6(/64) */ + exp = sub(exp, sub(30, add(shl(Q_syn, 1), 6))); /*+6(/64) */ + + tmp = div_s(16384, tmp); + L_tmp = L_deposit_h(tmp); + L_tmp = Isqrt_lc(L_tmp, &exp); + +#ifdef BASOP_NOGLOB + WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */ +#else + WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ +#endif + test(); + test(); + IF(NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && ener_var_flag == 0) + { +#ifdef BASOP_NOGLOB + WB_fenv[0] = add_sat(WB_fenv[0], mult_r_sat(WB_fenv[0], 16384)); +#else + WB_fenv[0] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); +#endif + move16(); + } + + exp = norm_l(enerL); + tmp = extract_h(L_shl(enerL, exp)); + exp = sub(exp, sub(30, shl(Q_syn, 1))); + + tmp = div_s(16384, tmp); + L_tmp = L_deposit_h(tmp); + L_tmp = Isqrt_lc(L_tmp, &exp); +#ifdef BASOP_NOGLOB + enerL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 15))); /* Q0 */ +#else + enerL_16 = round_fx(L_shl(L_tmp, sub(exp, 15))); /* Q0 */ +#endif + enerL_40 = mult_r(6554, enerL_16); /*1/40 in Q18 ->Q3 */ + + test(); + test(); + test(); + test(); + test(); + test(); + IF(NE_16(coder_type, TRANSITION) && NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && + GT_16(enerL_40, WB_fenv[0]) && GT_16(alfa, 29491) && !(EQ_16(coder_type, prev_coder_type) && + GT_16(WB_fenv[0], prev_WB_fenv))) + { + IF(WB_fenv[0] != 0) + { + exp = norm_s(WB_fenv[0]); + tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */ + L_tmp = L_mult(enerL_40, tmp); /*Q(30-exp) */ +#ifdef BASOP_NOGLOB + tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */ +#else + tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */ +#endif + tmp = s_min(tmp, 16384); + L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q15 */ + WB_fenv[0] = extract_l(L_tmp);/*Q3 */ + } + + IF(GT_16(WB_fenv[0], prev_WB_fenv)) + { + /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ + WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ + } + } + + L_tmp = L_mult0(voice_factor, 77); + tmp1 = extract_l(L_shr(L_tmp, 13)); + + exp = norm_s(pitch); + tmp = div_s(shl(1, sub(14, exp)), pitch); /*Q(29-exp-5) */ + L_tmp = L_mult0(tmp1, tmp); /*29-exp-5->24-exp */ +#ifdef BASOP_NOGLOB + tmp = round_fx_sat(L_shl_sat(L_tmp, add(exp, 6))); /*14 */ +#else + tmp = round_fx(L_shl(L_tmp, add(exp, 6))); /*14 */ +#endif + tmp1 = s_max(tmp, 8192); + alfa = s_min(24576, tmp1);/*Q14 */ + + L_tmp = L_mult0(alfa, WB_fenv[0]);/*Q14+Q3->Q17 */ + L_tmp = L_shr(L_tmp, 14);/*Q3 */ + tmp = extract_l(L_tmp); + + enerL = L_deposit_l(enerL_16); + enerL = L_shl(enerL, 6); /*Q6 */ +#ifdef BASOP_NOGLOB + tmp1 = i_mult_sat(3, WB_fenv[0]);/*Q3 */ +#else + tmp1 = i_mult(3, WB_fenv[0]);/*Q3 */ +#endif + L_tmp = L_mult0(tmp1, WB_fenv[0]); /*Q6 */ + + test(); + test(); + test(); + IF(GT_16(shr(enerL_16, 3), tmp) && GT_32(enerL, L_tmp) && NE_16(prev_coder_type, UNVOICED) && WB_fenv[0] != 0) + { + env_var_flag = 1; + move16(); + enerL_64 = mult_r(4096, enerL_16);/* 1/64 in Q18 ->Q3 */ + + exp = norm_s(WB_fenv[0]); + tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */ + L_tmp = L_mult(enerL_64, tmp); /*Q(30-exp) */ +#ifdef BASOP_NOGLOB + tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */ +#else + tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */ +#endif + tmp = s_min(tmp, 16384); + L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q3 */ + WB_fenv[0] = extract_l(L_tmp);/*Q3 */ + + IF(GT_16(WB_fenv[0], prev_WB_fenv)) + { + /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ + WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ + } + } + + test(); + IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED)) + { + WB_fenv[0] = shr(WB_fenv[0], 1); + move16();/*Q3 */ + } + + IF(NE_16(coder_type, AUDIO)) + { + tmp = mult_r(voice_factor, 19661); /*Q12 */ + tmp = s_max(tmp, 4096); + exp = norm_s(tmp); + tmp = div_s(shl(1, sub(14, exp)), tmp); /*Q(29-exp-12) */ + L_tmp = L_mult(WB_fenv[0], tmp); /*Q(21-exp) */ + + WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q3 */ + tmp1 = mult_r(328, pitch);/*Q7 */ + tmp = s_min(s_max(tmp1, 16), 256);/*Q7 */ + L_tmp = L_shr(L_mult0(WB_fenv[0], tmp), 7);/*Q3 */ + /*WB_fenv[0] = saturate(L_tmp); //Q3 */ +#ifdef BASOP_NOGLOB + WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, 16)); /*Q3 */ +#else + WB_fenv[0] = round_fx(L_shl(L_tmp, 16)); /*Q3 */ +#endif + } + test(); + IF(GT_32(last_core_brate, ACELP_8k00) && GT_16(WB_fenv[0], last_wb_bwe_ener)) + { + /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ + WB_fenv[0] = round_fx(L_mac(L_mult(29491, last_wb_bwe_ener), 3277, WB_fenv[0]));/*Q3 */ + } + + IF(NE_16(last_extl_fx, WB_BWE) && LT_16(tilt_wb_fx, 128)) + { + WB_fenv[0] = mult_r(s_min(16384, shl(tilt_wb_fx, 8)), WB_fenv[0]); + } + + IF(env_var_flag == 1) + { + WB_fenv[1] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); + move16(); + WB_fenv[0] = mult_r(24576, WB_fenv[0]); + move16();/*Q3 */ + } + ELSE + { + WB_fenv[1] = WB_fenv[0]; + move16(); + } + + test(); + IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED)) + { + WB_fenv[1] = shr(WB_fenv[1], 1); + move16();/*Q3 */ + } + + return (mode); +} + +/*-------------------------------------------------------------------* +* calc_norm_envelop_lf_fx() +* +* calc_envelope of low frequency spectrum +*-------------------------------------------------------------------*/ +static +void calc_norm_envelop_lf_fx( + const Word32 SWB_signal[], /* i : SWB spectrum */ /* Q12 */ + Word32 *envelope, /* o : normalized envelope */ /* Q12 */ + Word16 *L_swb_norm, /* i/o : length of envelope */ + const Word16 HQ_mode, /* i : HQ mode */ /* Q0 */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic */ /* Q0 */ + Word16 *sfreq, /* i : starting frequency index */ + Word16 *efreq /* i : ending frequency index */ +) +{ + Word16 lookback, env_index, n_freq, n_lag_now, n_lag; + + *sfreq = 2; + move16(); + IF(EQ_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) + { + *efreq = 146; + move16(); + if (EQ_16(HQ_mode, HQ_GEN_FB)) + { + *efreq = 306; + move16(); + } + IF(LT_16(add(shl(sub(328, *efreq), 1), 1), *L_swb_norm)) + { + *L_swb_norm = add(shl(sub(328, *efreq), 1), 1); + } + } + ELSE + { + *efreq = 130; + move16(); + if (EQ_16(HQ_mode, HQ_GEN_FB)) + { + *efreq = 290; + move16(); + } + IF(LT_16(add(shl(sub(400,*efreq),1),1),*L_swb_norm)) + { + *L_swb_norm = add(shl(sub(400,*efreq),1),1); + } + } + lookback = shr(*L_swb_norm, 1); + env_index = 0; + move16(); + n_lag_now = *L_swb_norm; + move16(); + + FOR(n_freq = 0; n_freq < lookback; n_freq++) + { + Word16 tmp; + Word32 L_tmp; + + L_tmp = L_deposit_l(1); + tmp = add(lookback, n_freq); + FOR(n_lag = 0; n_lag < tmp; n_lag++) + { +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[n_lag] ) ); +#else + L_tmp = L_add( L_tmp, L_abs( SWB_signal[n_lag] ) ); +#endif + } + envelope[env_index] = L_tmp; + move32(); + env_index = add(env_index, 1); + } + + FOR(; n_freq < *efreq; n_freq++) + { + /* Apply MA filter */ + Word32 L_tmp = L_deposit_l(1); + FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) + { +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)])); +#else + L_tmp = L_add(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)])); +#endif + } + + envelope[env_index] = L_tmp; + move32(); + env_index = add(env_index, 1); + } + + return; +} +/*-------------------------------------------------------------------* + * calc_normal_length() + * + *-------------------------------------------------------------------*/ + +void calc_normal_length_fx( + const Word16 core, /* i : core */ + const Word16 *sp, /* i : input signal */ + const Word16 mode, /* i : input mode */ + const Word16 extl, /* i : extension layer */ + Word16 *L_swb_norm, /* o : normalize length */ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + Word16 Q_syn +) +{ + Word16 i, n_freq, n_band, THRES; + const Word16 *pit; + Word16 peak, mag; + Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; + Word16 N; + Word32 L_mean, L_tmp, L_tmp1; + + THRES = 4; + move16(); + test(); + test(); + if (EQ_16(core, HQ_CORE) || EQ_16(extl, SWB_BWE) || EQ_16(extl, FB_BWE)) + { + THRES = 8; + move16(); + } + + N = 16; + move16(); + test(); + test(); + if (EQ_16(core, HQ_CORE) && (EQ_16(mode, HQ_HARMONIC) || EQ_16(mode, HQ_HVQ))) + { + N = 13; + move16(); + } + + n_band = 0; + move16(); + pit = sp; + move16();/*Q_syn */ + FOR(i = 0; i < N; i++) + { + peak = 0; + move16(); + L_mean = L_deposit_l(0); + + FOR(n_freq = 0; n_freq < 16; n_freq++) + { + mag = abs_s(*pit); + + peak = s_max(peak, mag); + L_mean = L_add(L_mean, mag);/*Q_syn */ + pit++; + } + + L_tmp = L_mult0(peak, 15 + THRES);/*Q_syn */ + IF(EQ_16(THRES, 8)) + { + L_tmp1 = L_shl(Mult_32_16(L_mean, 32767), 3); + } + ELSE + { + L_tmp1 = L_shl(Mult_32_16(L_mean,32767), 2); + } + + test(); + if (GT_32(L_tmp, L_tmp1) && (GT_16(peak, shl(10, Q_syn)))) + { + n_band = add(1, n_band); + } + } + + IF(EQ_16(core, ACELP_CORE)) + { + L_swb_norm_trans = add(4, mult(n_band, 8192)); + L_swb_norm_norm = add(8, mult(n_band, 16384)); + + L_tmp = L_add(65536, L_mult0(n_band, 4096)); /*Q16 */ + L_swb_norm_harm = s_max(round_fx(L_shl(L_tmp, 5)), 24); /* Q0 */ + + IF(EQ_16(mode, HARMONIC)) + { + L_swb_norm_cur = L_swb_norm_harm; + move16(); + } + ELSE IF(EQ_16(mode, NORMAL)) + { + L_swb_norm_cur = L_swb_norm_norm; + move16(); + } + ELSE + { + L_swb_norm_cur = L_swb_norm_trans; + move16(); + } + *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1); + move16(); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + ELSE + { + test(); + IF(EQ_16(mode,HQ_HARMONIC) || EQ_16(mode,HQ_HVQ)) + { + L_tmp = L_add(65536, L_mult(n_band, 2560)); + L_swb_norm_cur = round_fx(L_shl(L_tmp, 5));/*Q0 */ + } + ELSE + { + L_tmp = L_add(65536, L_mult(n_band, 2048)); /*Q16 */ + L_swb_norm_cur = round_fx(L_shl(L_tmp, 3));/*Q0 */ + } + + /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */ + *L_swb_norm = round_fx(L_mac(L_mult(L_swb_norm_cur, 3277), *prev_L_swb_norm, 29491)); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + + return; +} +/*-------------------------------------------------------------------* + * calc_tilt_bwe() + * + * calculate tilt parameter + *-------------------------------------------------------------------*/ + +Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word16 *sp, /* i : input signal */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ +) +{ + Word16 i, j; + Word32 L_ener, L_ener_tot, L_temp; + Word16 tmp1, tmp2; + const Word16 *ptr; + Word16 exp2; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + BASOP_SATURATE_WARNING_OFF_EVS + + /* this is required for adaptative precision energy summation loop, do not remove */ + Overflow = 0; + move16(); + exp2 = 0; + move16(); + + ptr = sp; + move16(); + L_ener_tot = L_deposit_l(1); + + /* Divide Frame Length by 32 */ + FOR(j = shr(N, 5); j > 0; j--) + { +#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ + tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */ +#else + tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ +#endif + L_ener = L_mult0(tmp1, tmp1); + /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ + FOR(i = 1; i < 32; i++) + { +#ifdef BASOP_NOGLOB /* Critical Overflow */ + tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */ + L_ener = L_mac0_o(L_ener, tmp1, tmp1, &Overflow); +#else + tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ + L_ener = L_mac0(L_ener, tmp1, tmp1); +#endif + } +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_ener = L_shr_o(L_ener, exp2, &Overflow); + L_temp = L_add_o(L_ener_tot, L_ener, &Overflow); +#else + L_ener = L_shr(L_ener, exp2); + L_temp = L_add(L_ener_tot, L_ener); +#endif + IF(Overflow != 0) + { + L_ener_tot = L_shr(L_ener_tot, 1); + L_ener = L_shr(L_ener, 1); + exp2 = add(exp2, 1); + /* this is required, do not remove */ + Overflow = 0; + move16(); + } +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_ener_tot = L_add_o(L_ener_tot, L_ener, &Overflow); +#else + L_ener_tot = L_add(L_ener_tot, L_ener); +#endif + } +#ifdef BASOP_NOGLOB + L_ener = L_deposit_l(abs_s(sub_o(sp[1], sp[0], &Overflow))); +#else + L_ener = L_deposit_l(abs_s(sub(sp[1], sp[0]))); +#endif + FOR(i = 2; i < N; i++) + { + /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ +#ifdef BASOP_NOGLOB + tmp1 = sub_o(sp[i], sp[i - 1], &Overflow); + tmp2 = sub_o(sp[i - 1], sp[i - 2], &Overflow); +#else + tmp1 = sub(sp[i], sp[i - 1]); + tmp2 = sub(sp[i - 1], sp[i - 2]); +#endif + tmp2 = mult(tmp1, tmp2); + tmp1 = abs_s(tmp1); + /* to Get either 0 or -1 in 'tmp2' */ + tmp2 = shr(tmp2, 15); + /* this allows this code */ + L_ener = L_msu0(L_ener, tmp2, tmp1); + /* instead of this one */ + /* test(); */ + /* if (tmp2 < 0) */ + /* { */ + /* L_ener = L_mac0(L_ener, 1, tmp1); */ + /* } */ + /* it saves one op */ + } + + tmp1 = norm_l(L_ener_tot); + L_temp = L_shl(L_ener_tot, tmp1); + tmp1 = sub(add(31 + 4, exp2), add(tmp1, shl(exp_sp, 1))); + L_temp = Isqrt_lc(L_temp, &tmp1); + + /* *tilt_flt = (float)(r1/sqrt(r0)); */ + exp2 = norm_l(L_ener); +#ifdef BASOP_NOGLOB + L_temp = Mult_32_16( L_temp, round_fx_sat( L_shl_sat( L_ener, exp2 ) ) ); +#else + L_temp = Mult_32_16( L_temp, round_fx( L_shl( L_ener, exp2 ) ) ); +#endif + exp2 = sub(exp2, tmp1); + exp2 = add(exp2, exp_sp); + + /* Put in Q24 */ +#ifdef BASOP_NOGLOB + L_temp = L_shr_sat( L_temp, sub( exp2, 24 ) ); +#else + L_temp = L_shr( L_temp, sub( exp2, 24 ) ); +#endif + BASOP_SATURATE_WARNING_ON_EVS + + return L_temp; +} +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word32 *sp, /* i : input signal */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ +) +{ + Word16 i, j; + Word32 L_ener, L_ener_tot, L_temp; + Word32 tmp1, tmp2; + Word16 sign = 0; + const Word32 *ptr; + Word16 exp2, tmp_exp; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + BASOP_SATURATE_WARNING_OFF_EVS + + /* this is required for adaptative precision energy summation loop, do not remove */ + Overflow = 0; + move16(); + exp2 = 0; + move16(); + + ptr = sp; + move16(); + L_ener_tot = L_deposit_l(1); + + /* Divide Frame Length by 32 */ + FOR(j = shr(N, 5); j > 0; j--) + { + Word32 tmp = *ptr++; /* Divide by 4 */ + L_ener = Mpy_32_32( tmp, tmp ); + /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ + FOR(i = 1; i < 32; i++) + { + tmp1 = *ptr++; /* Divide by 4 */ + L_ener = Madd_32_32(L_ener, tmp1, tmp1); + } + L_temp = L_add(L_ener_tot, L_ener); + + L_ener_tot = L_add(L_ener_tot, L_ener); + } + L_ener = L_abs(L_sub(sp[1], sp[0])); + + FOR(i = 2; i < N; i++) + { + /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ + tmp1 = L_sub(sp[i], sp[i - 1]); + tmp2 = L_sub(sp[i - 1], sp[i - 2]); + + tmp2 = Mpy_32_32(tmp1, tmp2); + tmp1 = L_abs(tmp1); + /* to Get either 0 or -1 in 'tmp2' */ + tmp2 = L_shr(tmp2, 31); + sign = extract_l(L_shl(tmp2, Q15)); + /* this allows this code */ + L_ener = Msub_32_16(L_ener, tmp1, sign); + /* instead of this one */ + /* test(); */ + /* if (tmp2 < 0) */ + /* { */ + /* L_ener = L_mac0(L_ener, 1, tmp1); */ + /* } */ + /* it saves one op */ + } + + L_temp = L_ener_tot; + tmp_exp = sub(Q31, sub(shl(exp_sp, 1), Q31)); + L_temp = Sqrt32(L_temp, &tmp_exp); + L_temp = L_shl(L_temp, sub(exp_sp, sub(Q31, tmp_exp))); + + /* *tilt_flt = (float)(r1/sqrt(r0)); */ + L_temp = L_deposit_l(BASOP_Util_Divide3232_Scale(L_ener, L_temp, &exp2)); + IF (GT_16(sub(exp2, 4) , norm_l(L_temp))) + { + L_temp = MAX_16; + } + ELSE + { + L_temp = L_shl(L_temp, sub(exp2, 4)); // Output is expected in Q11 + } + BASOP_SATURATE_WARNING_ON_EVS + + return extract_l(L_temp); +} +#endif + +/*-------------------------------------------------------------------* + * calc_norm_envelop() + * + * calculate normalized parameter + *-------------------------------------------------------------------*/ + +void calc_norm_envelop_fx( + const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ + Word32 *envelope, /* o : normalized envelope Q_syn*/ + const Word16 L_swb_norm, /* i : length of envelope Q0 */ + const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 st_offset /* i : offset */ +) +{ + Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; + + lookback = shr(L_swb_norm, 1); + move16(); + env_index = add(swb_bwe_subband[0], st_offset); + n_lag_now = L_swb_norm; + move16(); + tmp = sub(add(SWB_flength, st_offset), L_swb_norm); + FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++) + { + /* Apply MA filter */ + Word32 L_tmp = L_deposit_l(0); + FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) + { + L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag])); + } + envelope[env_index] = L_tmp; + move32(); + env_index++; + } + + i = 0; + move16(); + tmp = sub(add(SWB_flength, st_offset), lookback); + FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++) + { + Word32 L_tmp; + + n_lag_now = sub(L_swb_norm, i); + /* Apply MA filter */ + L_tmp = L_deposit_l(0); + FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) + { + L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag])); + } + envelope[env_index] = L_tmp; + move32(); + env_index++; + i++; + } + + return; +} + +/*==========================================================================*/ +/* FUNCTION : void WB_BWE_decoding_fx () */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : WB BWE decoder */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _Word16 *core_dec_freq i : Frequency domain core decoded signal Q_syn*/ +/* _Word16 *WB_fenv i : WB frequency envelopes Q3 */ +/* _Word16 WB_flength i : Length of input/output */ +/* _Word16 mode i : classification for WB signal */ +/* _Word16 prev_mode i : classification for last frame */ +/* _Word16 last_extl i : extl. layer for last frame */ +/* _Word16 extl i : extension layer */ +/* _Word16 coder_type i : coding type */ +/* _Word16 total_brate i : core layer bitrate */ +/* _Word16 prev_coder_type i : coding type of last frame */ +/* _Word16 Q_syn i : Q format */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _Word16 *WB_signal, o : WB signal in MDCT domain Q_syn */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _Word32 *prev_Energy, i/o: energy for last frame Q_syn */ +/* _Word16 *prev_WB_fenv, i/o: envelope for last frame Q3 */ +/* _Word16 *prev_L_wb_norm, i/o: length for last frame wb norm Q0 */ +/* _Word16 *Seed, i/o: random generator seed Q15 */ +/* _Word16 *prev_flag, i/o: attenu flag of last frame Q0 */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------*/ +/* CALLED FROM : */ +/*==========================================================================*/ +void WB_BWE_decoding_fx( + const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ + Word16 *WB_fenv, /* i : WB frequency envelopes */ + Word32 *WB_signal_32, /* o : WB signal in MDCT domain */ + const Word16 WB_flength, /* i : Length of input/output */ + const Word16 mode, /* i : classification for WB signal */ + const Word16 last_extl, /* i : extl. layer for last frame */ + Word32 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ + const Word16 extl, /* i : extension layer */ + const Word16 coder_type, /* i : coding type */ + const Word32 total_brate, /* i : core layer bitrate */ + Word16 *Seed, /* i/o: random generator seed */ + Word16 *prev_flag, /* i/o: attenu flag of last frame */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 Q_syn, + Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ +) +{ + Word16 n_freq, n_band; + Word16 i, L; + Word32 envelope[L_FRAME16k]; + Word32 energy, EnergyL; + Word32 *pit1; + Word16 WB_signal[L_FRAME16k]; + Word16 L_wb_norm, wfenv[2]; + Word16 alfa, beta; + Word16 flag = 0; + Word16 core_type = 1; + Word16 tmp, tmp1, exp, tmp2; + Word32 L_tmp, L_tmp1, L_tmp2; + Word32 prev_ener_alpha, prev_ener_beta; + Word16 signum[L_FRAME16k]; + Word16 inv_L_wb_norm, weight; + + calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_wb_norm, prev_L_wb_norm, Q_syn); + set32_fx(WB_signal_32, 0, L_FRAME16k); + set16_fx(WB_signal, 0, L_FRAME16k); + + /* copy excitation */ + test(); + if (NE_16(coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00)) + { + core_type = 0; + move16(); + } + + IF(core_type == 0) + { + Copy(&core_dec_freq[160], &WB_signal[240], 80); + } + ELSE + { + Copy(&core_dec_freq[80], &WB_signal[240], 80); + } + + /* calculate envelope */ + calc_norm_envelop_fx(WB_signal, envelope, L_wb_norm, WB_flength, 0); + test(); + IF(coder_type != UNVOICED && total_brate <= ACELP_8k00) + { + exp = norm_s(L_wb_norm); + inv_L_wb_norm = shl(div_s(shl(1, sub(14, exp)), L_wb_norm), sub(exp, 14)); /* Q(15) */ + IF(NE_16(mode, HARMONIC)) + { + tmp = add(shl(inv_L_wb_norm, 1), inv_L_wb_norm); + weight = s_max(s_min(tmp, 16384), 8192); + } + ELSE + { + weight = 8192; + move16(); + } + FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) + { + signum[n_freq] = 1; + IF(WB_signal[n_freq] < 0) + { + signum[n_freq] = -1; + move16(); + WB_signal[n_freq] = negate(WB_signal[n_freq]); + move16(); + } + L_tmp = Mult_32_16(envelope[n_freq], inv_L_wb_norm); /* Q_syn */ + L_tmp = Mult_32_16(L_tmp, 14746); /* Q_syn */ + L_tmp1 = L_deposit_l(WB_signal[n_freq]); /* Q_syn */ + L_tmp = L_sub(L_tmp1, L_tmp); /* Q_syn */ + WB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */ + IF(L_tmp > 0) + { + tmp = sub(18022, weight); /* Q15 */ + WB_signal[n_freq] = extract_l(Mult_32_16(L_tmp, tmp)); /* Q_syn */ + } + + IF(NE_16(signum[n_freq], 1)) + { + WB_signal[n_freq] = negate(WB_signal[n_freq]); + move16(); + } + } + } + + /* Normalize with envelope */ + FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) + { + IF(envelope[n_freq] != 0) + { + exp = norm_l(envelope[n_freq]); + tmp = extract_h(L_shl(envelope[n_freq], exp)); + exp = sub(sub(30, exp), Q_syn); + tmp = div_s(16384, tmp); + L_tmp = L_shr(L_mult0(WB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */ + WB_signal[n_freq] = extract_l(L_tmp); /*Q15 */ + } + ELSE + { + WB_signal[n_freq] = shl(WB_signal[n_freq],sub(15,Q_syn)); /*Q15 */ move16(); + } + } + + L = 1; + move16(); + if (EQ_16(mode, HARMONIC)) + { + L = 4; + move16(); + } + + IF(EQ_16(coder_type, UNVOICED)) + { + FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) + { + *Seed = extract_l(L_mac0(20101L, *Seed, 12345)); + L_tmp = L_shl(*Seed, add(Q_syn, 1)); + WB_signal_32[n_freq] = L_tmp; + move32(); + } + } + ELSE + { + FOR(n_band = 0; n_band < 4; n_band += L) + { + energy = L_deposit_l(0); + FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++) + { + L_tmp = L_mult(WB_signal[n_freq],WB_signal[n_freq]); /*Q31 */ + energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */ + } + + tmp = sub(swb_bwe_subband[n_band + L] , swb_bwe_subband[n_band]); + tmp = div_s(1,tmp);/*Q15 */ + energy = Mult_32_16(energy,tmp); /*Q(15+25-15)->Q(25) */ + + exp = norm_l(energy); + L_tmp1 = L_shl(energy, exp); + exp = 31 - exp - (25); + move16(); + L_tmp1 = Isqrt_lc(L_tmp1, &exp); /*Q(31-exp) */ + + FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++) + { + L_tmp2 = Mult_32_16(L_tmp1, WB_signal[n_freq]); + WB_signal_32[n_freq] = L_shl(L_tmp2, sub(add(exp, Q_syn), 15)); + move32(); + } + } + } + + EnergyL = L_deposit_l(0); + IF(core_type == 1) + { + test(); + IF(NE_16(prev_coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00)) + { + FOR(i = 160; i < 240; i++) + { + EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL); + } + } + ELSE + { + FOR(i = 80; i < 240; i++) + { + EnergyL = L_add(abs_s(core_dec_freq[i]),EnergyL); + } + } + + IF(LE_32(total_brate, ACELP_8k00)) + { + alfa = 26214; + move16(); /*0.8f in Q15; */ + beta = 10240; + move16();/*1.25f in Q13; */ + } + ELSE + { + alfa = 16384; + move16();/* 0.5f in Q15; */ + beta = 16384; + move16();/*2.0f in Q13 */ + } + } + ELSE + { + IF(EQ_16(prev_coder_type,AUDIO)) + { + FOR(i = 80; i < 240; i++) + { + EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL);/*Q_syn */ + } + } + ELSE + { + FOR(i = 160; i < 240; i++) + { + EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL); + } + } + + test(); + IF(EQ_16(prev_coder_type,coder_type) && GT_16(WB_fenv[0],prev_WB_fenv[0])) + { + alfa = 13107; + move16();/*.4 in Q15 */ + beta = 20480; + move16(); /*2.5 in Q13 */ + } + ELSE + { + alfa = 19661; + move16();/*.6 in Q15 */ + beta = 13681; + move16();/*1.67 in Q13 */ + } + + test(); + test(); + test(); + IF(EQ_16(coder_type,GENERIC) || (GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1)) && EQ_16(*prev_flag,1))) + { + WB_fenv[0] = shr(WB_fenv[0], 1); + move16(); + WB_fenv[1] = shr(WB_fenv[1], 1); + move16(); + flag = 1; + move16(); + } + } + L_tmp1 = Mult_32_16(EnergyL, prev_WB_fenv[0]);/*Qsyn+3-15 */ + L_tmp2 = Mult_32_16(*prev_Energy, WB_fenv[0]);/*Q_syn+3-15 */ + prev_ener_alpha = Mult_32_16(*prev_Energy, alfa);/*Q_syn+15-15->Q_syn */ + prev_ener_beta = L_shl(Mult_32_16(*prev_Energy, beta), 2); /*Q_syn+13-15+2 ->Q_syn */ + + test(); + test(); + IF((EQ_16(mode, HARMONIC) && GT_16(shr(WB_fenv[0], 2), WB_fenv[1])) || EQ_16(mode, NORMAL)) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF(EQ_16(last_extl, WB_BWE) && + ((EQ_16(prev_coder_type, AUDIO) && NE_16(coder_type, AUDIO)) || + (NE_16(prev_coder_type, AUDIO) && EQ_16(coder_type, AUDIO))) && LE_32(total_brate, ACELP_8k00)) + { + IF(GT_16(WB_fenv[0], prev_WB_fenv[0])) + { + /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */ + wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */ + /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */ + wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */ + } + ELSE + { + /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */ + wfenv[0] = round_fx(L_mac(L_mult(16384,WB_fenv[0]),16384,prev_WB_fenv[0]));/*Q3 */ + /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */ + wfenv[1] = round_fx(L_mac(L_mult(13108,WB_fenv[1]),13108,prev_WB_fenv[1]));/*Q3 */ + } + } + ELSE IF(EQ_16(last_extl, WB_BWE) && LT_32(L_tmp1, L_tmp2) && GT_16(WB_fenv[0], prev_WB_fenv[0]) && + NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && LE_32(total_brate, ACELP_8k00)) + { + /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */ + wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */ + /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */ + wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */ + } + ELSE IF(EQ_16(last_extl, WB_BWE) && GT_32(EnergyL, prev_ener_alpha) && GT_32(prev_ener_beta, EnergyL) && + NE_16(prev_coder_type, UNVOICED)) + { + /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */ + wfenv[0] = round_fx(L_mac(L_mult(WB_fenv[0], 16384), prev_WB_fenv[0], 16384));/*Q3 */ + /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */ + wfenv[1] = round_fx(L_mac(L_mult(WB_fenv[1], 16384), prev_WB_fenv[1], 16384));/*Q3 */ + } + ELSE + { + wfenv[0] = WB_fenv[0]; + move16(); + wfenv[1] = WB_fenv[1]; + move16(); + } + FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[2]; n_freq++) + { + WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]); + move32();/* Q_syn+3+1 */ + } + + FOR(n_freq = swb_bwe_subband[2]; n_freq < swb_bwe_subband[4]; n_freq++) + { + WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[1]); + move32();/* Q_syn+3+1 */ + } + + prev_WB_fenv[0] = wfenv[0]; + move16(); + prev_WB_fenv[1] = wfenv[1]; + move16(); + } + ELSE + { + wfenv[0] = add(shr(WB_fenv[0],1), shr(WB_fenv[1],1));/*Q3 */ + + test(); + test(); + IF(EQ_16(last_extl,WB_BWE) && GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1))) + { + L_tmp1 = L_mac(L_mult(8192,wfenv[0]),12288, prev_WB_fenv[0]); + wfenv[0] = round_fx(L_mac(L_tmp1, 12288, prev_WB_fenv[1])); + } + FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++) + { + WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]); + move32();/* Q_syn+3+1 */ + } + prev_WB_fenv[0] = wfenv[0]; + move16(); + prev_WB_fenv[1] = wfenv[0]; + move16(); + } + + *prev_flag = flag; + move16(); + *prev_Energy = EnergyL; + move32(); + pit1 = &WB_signal_32[240]; + + FOR(n_freq = 0; n_freq < 16; n_freq++) + { + tmp1 = extract_l(L_mult0(n_freq, 1638));/*Q15 */ + tmp2 = add(6554, tmp1);/*Q15 */ + L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ + *(pit1++) = L_tmp1; + move32(); + } + + IF(EQ_16(core_type, 1)) + { + pit1 = &WB_signal_32[280]; + FOR(n_freq = 0; n_freq < 40; n_freq++) + { + tmp1 = extract_l(L_mult0(n_freq, 655));/*Q15 */ + tmp2 = sub(32767, tmp1); + L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ + *(pit1++) = L_tmp1; + move32(); + } + } + ELSE + { + pit1 = &WB_signal_32[300]; + FOR(n_freq = 0; n_freq < 20; n_freq++) + { + tmp1 = extract_l(L_mult0(n_freq, 1311));/*Q15 */ + tmp2 = sub(32767, tmp1); + L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */ + *(pit1++) = L_tmp1; + move32(); + } + } + pit1 = &WB_signal_32[240]; + tmp = Find_Max_Norm32(pit1, 80); + FOR(i = 0; i < 80; i++) + { + L_tmp = *pit1; + *(pit1++) = L_shl(L_tmp, sub(tmp, 1)); + move32(); + } + *Q_syn_hb = add(Q_syn, add(tmp, 3)); + return; +} + + +/*==========================================================================*/ +/* FUNCTION : void SWB_BWE_decoding_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : SWB BWE decoder */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS */ +/* _(Word16*) core_dec_freq :Frequency domain core decoded signal Q_syn */ +/* _(Word16) SWB_flength :Length of input/output Q0 */ +/* _(Word16) mode :classification for SWB signal */ +/* _(Word16) tilt_nb :tilt of synthesis wb signal Q11 */ +/* _(Word16) st_offset :offset value due to different core */ +/* _(Word16) Q_syn :Q format */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _(Word16*)SWB_fenv : SWB frequency envelopes Q1 */ +/* _(Word16*)prev_Energy : energy for last frame Q3 */ +/* _(Word16*)prev_SWB_fenv : envelope for last frame Q1 */ +/* _(Word16*)prev_L_swb_norm : length for last frame wb norm Q0 */ +/* _(Word16*)Seed : random generator seed Q0 */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _(Word16*)SWB_signal : SWB signal in MDCT domain Q0 */ +/* _(Word16*)frica_flag : fricative signal flag Q0 */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------*/ + +void SWB_BWE_decoding_fx( + const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ + Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ + Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */ + const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 mode, /* i : classification for SWB signal */ + Word16 *frica_flag, /* o : fricative signal flag */ + Word16 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ + const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ + Word16 *Seed, /* i/o: random generator seed */ + const Word16 st_offset, /* i : offset value due to different core */ + Word16 *prev_weight, /* i/o: excitation weight value of last frame */ + const Word16 extl, /* i : extension layer */ + Word16 Q_syn + , const Word16 last_extl /* i : extension layer of last frame */ +) +{ + Word16 n_freq, n_band, L, L_swb_norm; + Word32 *pit1_32; + Word16 *pit1; + Word32 envelope[L_FRAME32k]; + Word32 fenvL, EnergyL, Energy, energy, L_mean; + Word16 fenvL_16, EnergyL_16, Energy_16, tmp, exp, exp1; + Word16 SWB_signal[L_FRAME32k]; + Word16 mean, factor, factor1, tmp1, tmp2, tmp3, tmp_exp, tmp_ener, weight, wfenv; + Word32 L_tmp, L_tmp3, L_tmp4, Ltmp_ener, L_tmp1; + Word32 L_energy; + Word16 signum[L_FRAME32k]; + Word16 inv_L_swb_norm; + + fenvL = L_deposit_l(0); + EnergyL = L_deposit_l(0); + FOR(n_freq = 224 + st_offset; n_freq < swb_bwe_trans_subband[0] + st_offset; n_freq++) + { +#ifdef BASOP_NOGLOB + fenvL = L_mac0_sat(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ +#else + fenvL = L_mac0(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ +#endif + } + + FOR(n_freq = 16; n_freq < L_FRAME; n_freq++) + { +#ifdef BASOP_NOGLOB + EnergyL = L_mac0_sat(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ +#else + EnergyL = L_mac0(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */ +#endif + } + + fenvL_16 = 0; + move16(); + IF(fenvL != 0) + { + exp = norm_l(fenvL); /* In 2*Q_syn */ + tmp = extract_h(L_shl(fenvL, exp)); + exp = sub(exp, sub(30, add(shl(Q_syn, 1), 4))); /*+4(/16) */ + + tmp = div_s(16384, tmp); + L_tmp = L_deposit_h(tmp); + L_tmp = Isqrt_lc(L_tmp, &exp); + +#ifdef BASOP_NOGLOB + fenvL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ +#else + fenvL_16 = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ +#endif + } +#ifdef BASOP_NOGLOB + IF( GT_16( fenvL_16, shl_sat( SWB_fenv[0], 5 ) ) ) +#else + IF( GT_16( fenvL_16, shl( SWB_fenv[0], 5 ) ) ) +#endif + { + fenvL_16 = shl(SWB_fenv[0], 2); + move16(); + } + EnergyL = Mult_32_16(EnergyL, 17476); /*2*Q_syn+3; 17476=(1/15) in Q18 */ + EnergyL_16 = 0; + move16(); + IF(EnergyL != 0) + { + exp = norm_l(EnergyL); /* In 2*Q_syn+3 */ + tmp = extract_h(L_shl(EnergyL, exp)); + exp = sub(exp, sub(30, add(shl(Q_syn, 1), 3 + 4))); /*+4(/16) */ + + tmp = div_s(16384, tmp); + L_tmp = L_deposit_h(tmp); + L_tmp = Isqrt_lc(L_tmp, &exp); + +#ifdef BASOP_NOGLOB + EnergyL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */ +#else + EnergyL_16 = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ +#endif + } + calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm, Q_syn); + + set16_fx(SWB_signal, 0, L_FRAME32k); + IF(EQ_16(mode, TRANSIENT)) + { + Energy = L_deposit_l(0); + FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + Energy = L_mac(Energy, SWB_fenv[n_band], SWB_fenv[n_band]); /*Q(2*1+1)->Q3 */ + } + exp = norm_s(SWB_FENV_TRANS); + tmp = div_s(shl(1, sub(14, exp)), SWB_FENV_TRANS); /*Q(29-exp) */ + L_tmp = Mult_32_16(Energy, tmp); /*Q(3+29-exp+1-16)->Q(17-exp) */ + Energy_16 = round_fx(L_shl(L_tmp, add(exp, 2))); /*Q3 */ + + /* Reconstruct excitation from LF signal */ + Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128); + Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128); + Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64); + + /* calculate envelope */ + calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); + + /* Normalize with envelope */ + tmp_exp = sub(15, Q_syn); + FOR(n_freq = swb_bwe_trans_subband[0] + st_offset; n_freq < swb_bwe_trans_subband[SWB_FENV_TRANS] + st_offset; n_freq++) + { + IF(envelope[n_freq] != 0) + { + exp = norm_l(envelope[n_freq]); + tmp = extract_h(L_shl(envelope[n_freq], exp)); + exp = sub(sub(30, exp), Q_syn); + tmp = div_s(16384, tmp); /*Q(15+exp) */ + L_tmp = L_shr(L_mult0(SWB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */ + SWB_signal[n_freq] = extract_l(L_tmp); /*Q15 */ + } + ELSE + { + SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp); + move16();/*Q15 */ + } + } + + FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + energy = L_deposit_l(0); + tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset); + FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */ + energy = L_add_sat(energy, L_shr(L_tmp, 6)); /*Q25 */ +#else + L_tmp = L_mult(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */ + energy = L_add(energy, L_shr(L_tmp, 6)); /*Q25 */ +#endif + } + + IF(energy == 0) + { + Ltmp_ener = L_mult(sqrt_swb_bwe_trans_subband_width_fx[n_band], SWB_fenv[n_band]);/*Q13 */ + tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset); + FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++) + { + SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener, SWB_signal[n_freq]), 2 + Q_syn); + move32();/*15+Qsyn */ + } + } + ELSE + { + exp1 = norm_s(swb_bwe_trans_subband_width[n_band]); + tmp = div_s(shl(1,sub(14,exp1)),swb_bwe_trans_subband_width[n_band]); /*Q(29-exp1) */ + energy = Mult_32_16(energy,tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */ + + exp = norm_l(energy); + L_tmp = L_shl(energy,exp); + /*exp = 31-exp-(-exp1+39); */ + exp = sub(sub(exp1,exp),8); + L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ + + Ltmp_ener = Mult_32_16(L_tmp,SWB_fenv[n_band]);/*Q(31-exp+1+1-16)->Q(17-exp) */ + tmp = add(swb_bwe_trans_subband[n_band + 1],st_offset); + tmp_exp = add(Q_syn,sub(exp,2)); + FOR(n_freq = add(swb_bwe_trans_subband[n_band],st_offset); n_freq < tmp; n_freq++) + { + SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]), tmp_exp); + move32(); /*15+Qsyn */ + } + } + } + + FOR(n_band = 0; n_band < 8; n_band++) + { + L_tmp = L_mult(SWB_fenv[n_band / 4], SWB_fenv[n_band / 4]); /*Q3 */ + prev_SWB_fenv[n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */ + } + + FOR(n_band = 0; n_band < 6; n_band++) + { + L_tmp = L_mult(SWB_fenv[2 + n_band / 3], SWB_fenv[2 + n_band / 3]); /*Q3 */ + prev_SWB_fenv[8 + n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */ + } + + *prev_weight = 16384; + move16(); + } + ELSE + { + Energy_16 = 0; + move16(); + L_energy = L_deposit_l(0); + FOR(n_band = 0; n_band < SWB_FENV; n_band++) + { + L_energy = L_add(L_energy,SWB_fenv[n_band]); /*Q1 */ + } + exp = norm_s(SWB_FENV); + tmp = div_s(shl(1,sub(14,exp)),SWB_FENV); /*Q(29-exp) */ + L_tmp = Mult_32_16(L_energy,tmp); /*Q(1+29-exp+1)->Q(15-exp) */ +#ifdef EVS_FLOAT +#ifdef BASOP_NOGLOB + EnergyL_16 = round_fx_sat( L_shl_sat( L_tmp, add( exp, 4 ) ) ); /* Q3 */ +#else + EnergyL_16 = round_fx( L_shl( L_tmp, add( exp, 4 ) ) ); /*Q3 */ +#endif +#else +#ifdef BASOP_NOGLOB + EnergyL_16 = round_fx_sat( L_shl_sat( L_tmp, add( exp, 4 ) ) ); /* Q3 */ +#else + EnergyL_16 = round_fx( L_shl( L_tmp, add( exp, 4 ) ) ); /*Q3 */ +#endif +#endif // EVS_FLOAT + IF(NE_16(last_extl, SWB_BWE) && NE_16(last_extl,FB_BWE)) + { + IF(Energy_16 < shr(EnergyL_16, 4) && EQ_16(extl, FB_BWE)) + { + FOR(n_band = 0; n_band < SWB_FENV; n_band++) + { + SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], 6554); + } + fenvL_16 = mult_r(fenvL_16, 6554); + } + Copy(SWB_fenv, prev_SWB_fenv, SWB_FENV); + } + + IF(mode == HARMONIC) + { + Copy(core_dec_freq, &SWB_signal[240 + st_offset], 240); + Copy(&core_dec_freq[128], &SWB_signal[480 + st_offset], 80); + /* calculate envelope */ + calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); + } + ELSE + { + test(); + test(); + test(); + test(); + test(); + test(); + IF(EQ_16(mode, NOISE) || ((GT_16(Energy_16,EnergyL_16) || (GT_16(tilt_nb,14336) && GT_16(Energy_16,shr(EnergyL_16,1))) || + GT_16(tilt_nb,24576)) && GT_16(Energy_16,600) && GT_16(fenvL_16,200))) + { + tmp = add(swb_bwe_subband[SWB_FENV], st_offset); + FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp; n_freq++) + { + *Seed = extract_l(L_mac0(20101L, 12345,*Seed)); + SWB_signal[n_freq] = mult_r(*Seed, 32767); + move16();/*Q15 */ + } + if (NE_16(mode, NOISE)) + { + *frica_flag = 1; + move16(); + } + } + ELSE + { + /* modify SHB frequency envelopes when SHB spectrum is unflat */ + FOR(n_band = 0; n_band < 13; n_band++) + { + IF(GT_16(mult_r(SWB_fenv[n_band],29491), SWB_fenv[n_band + 1])) + { + tmp = extract_l(L_mac0(26214, n_band, 492)); /*Q15; 0.015 in Q15 = 492 */ + SWB_fenv[n_band + 1] = mult_r(SWB_fenv[n_band + 1], tmp); + move16();/*Q1 */ + } + + IF(GT_16(mult_r(SWB_fenv[n_band + 1],29491),SWB_fenv[n_band])) + { + tmp = extract_l(L_mac0(26214, n_band,492)); /*Q15; 0.015 in Q15 = 492 */ + SWB_fenv[n_band] = mult_r(SWB_fenv[n_band],tmp); + move16();/*Q1 */ + } + } + Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128); + Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128); + Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64); + +#ifdef BASOP_NOGLOB + tmp1 = add_sat(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */ + tmp2 = add_sat(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */ +#else + tmp1 = add(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */ + tmp2 = add(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */ +#endif + pit1 = &SWB_signal[368 + st_offset]; + move16(); + + test(); + IF((tmp2 == 0) || (LT_16(tmp2, mult_r(tmp1, 9830)))) + { + tmp3 = 9830; + move16();/*0.3 in Q15 */ + WHILE(LT_16(tmp3,32767)) + { + *pit1 = mult_r(*pit1,tmp3); + move16(); /*Q_syn */ + pit1++; +#ifdef BASOP_NOGLOB + tmp3 = add_sat(tmp3, 3277); /*Q15 */ +#else + tmp3 = add(tmp3, 3277); /*Q15 */ +#endif + } + } + ELSE IF(LT_16(tmp2, tmp1)) + { + exp = norm_s(tmp1); + tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ +#ifdef BASOP_NOGLOB + tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ +#else + tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ +#endif + WHILE(LT_16(tmp3, 32767)) + { + *pit1 = mult_r(*pit1,tmp3); + move16(); /*Q_syn */ + pit1++; +#ifdef BASOP_NOGLOB + tmp3 = add_sat(tmp3,3277); /*Q15 */ +#else + tmp3 = add(tmp3,3277); /*Q15 */ +#endif + } + } + + pit1 = &SWB_signal[367 + st_offset]; + move16(); + IF(GT_16(mult_r(tmp1,6554),tmp2)) + { + /*20480 = 5 in Q12 */ + FOR(tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048) + { +#ifdef BASOP_NOGLOB + *pit1 = round_fx_sat( L_shl_sat( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */ +#else + *pit1 = round_fx( L_shl( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */ +#endif + pit1--; + } + } + +#ifdef BASOP_NOGLOB + tmp1 = add_sat(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */ + tmp2 = add_sat(add_sat(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add_sat(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset]))); +#else + tmp1 = add(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */ + tmp2 = add(add(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset]))); +#endif + pit1 = &SWB_signal[496 + st_offset]; + move16(); + + test(); + IF((tmp2 == 0) || (LT_16(tmp2,mult_r(tmp1,9830)))) + { + tmp3 = 9830; + move16(); /*0.3 in Q15 */ + WHILE(LT_16(tmp3,32767)) + { + *pit1 = mult_r(*pit1,tmp3); + move16(); /*Q_syn */ + pit1++; +#ifdef BASOP_NOGLOB + tmp3 = add_sat(tmp3, 3277); /*Q15 */ +#else + tmp3 = add(tmp3, 3277); /*Q15 */ +#endif + } + } + ELSE IF(LT_16(tmp2,tmp1)) + { + exp = norm_s(tmp1); + tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ +#ifdef BASOP_NOGLOB + tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ +#else + tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ +#endif + WHILE(LT_16(tmp3,32767)) + { + *pit1 = mult_r(*pit1,tmp3); + move16();/*Q_syn */ + pit1++; +#ifdef BASOP_NOGLOB + tmp3 = add_sat(tmp3, 3277); /*Q15 */ +#else + tmp3 = add(tmp3, 3277); /*Q15 */ +#endif + } + } + pit1 = &SWB_signal[495 + st_offset]; + + L_tmp3 = L_deposit_h(tmp1); /*Q17 */ + L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q17 */ + exp = 14; + move16(); + IF(tmp2 != 0) + { + exp = norm_s(tmp2); + tmp = div_s(shl(1,sub(14,exp)),tmp2); /*Q(29-exp) */ + L_tmp3 = L_shr(L_mult(tmp1,tmp),1); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ + L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q(30-exp) */ + } + + L_tmp1 = L_shl(1L,sub(30,exp)); + WHILE(GT_32(L_tmp3,L_tmp1)) + { + L_tmp = Mult_32_16(L_tmp3,*pit1); /*Q(16-exp) */ + *pit1-- = round_fx(L_shl(L_tmp,exp)); /*Q_syn */ + L_tmp3 = L_sub(L_tmp3,L_tmp4); + } + + /* calculate envelope */ + calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); + } + } + + /* Normalize with envelope */ + test(); + IF(*frica_flag == 0 && NE_16(mode, NOISE)) + { + L = add(swb_bwe_subband[0],st_offset); + exp = norm_s(L_swb_norm); + inv_L_swb_norm = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */ + + IF(NE_16(mode,HARMONIC)) + { + tmp = add(shl(inv_L_swb_norm,1), inv_L_swb_norm); + weight = s_max(s_min(tmp,16384), 6554); + } + ELSE + { + weight = 6554; + move16(); + } + + weight = mac_r(L_mult(13107,weight) , 19661,(*prev_weight)); + + FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++) + { + signum[n_freq] = 1; + IF(SWB_signal[n_freq] < 0) + { + signum[n_freq] = -1; + move16(); + SWB_signal[n_freq] = negate(SWB_signal[n_freq]); + move16(); + } + L_tmp = Mult_32_16(envelope[n_freq],inv_L_swb_norm); /* Q_syn */ + L_tmp1 = L_deposit_l(SWB_signal[n_freq]); /* Q_syn */ + L_tmp = L_sub(L_tmp1,L_tmp); /* Q_syn */ + IF(L_tmp > 0) + { + tmp = shr(weight,1); /* Q14 */ + tmp = sub(19661,tmp); /* Q14 */ + SWB_signal[n_freq] = extract_l(L_shl(Mult_32_16(L_tmp,tmp),1)); /* Q_syn */ + } + ELSE + { + SWB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */ + } + + IF(NE_16(signum[n_freq],1)) + { + SWB_signal[n_freq] = negate(SWB_signal[n_freq]); + move16(); + } + } + + tmp_exp = sub(15,Q_syn); + FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++) + { + IF(envelope[n_freq] != 0) + { + exp = norm_l(envelope[n_freq]); + tmp = extract_h(L_shl(envelope[n_freq], exp)); + exp = sub(sub(30,exp), Q_syn); + tmp = div_s(16384,tmp); /* Q(15+exp) */ + L_tmp = L_shr(L_mult0(SWB_signal[n_freq],tmp), add(exp,Q_syn)); /* Q15 */ + SWB_signal[n_freq] = extract_l(L_tmp); /* Q15 */ + } + ELSE + { + SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp); + move16(); /* Q15 */ + } + } + *prev_weight = weight; + } + ELSE + { + exp = norm_s(L_swb_norm); + tmp = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */ + tmp = add(shl(tmp,1),tmp); + *prev_weight = s_max(s_min(tmp,16384),6554); /* Q15 */ + } + + IF(EQ_16(mode,HARMONIC)) + { + pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset]; + move16(); + FOR(n_band = 0; n_band < 19; n_band++) + { + L_mean = L_deposit_l(0); + FOR(n_freq = 0; n_freq < 16; n_freq++) + { + L_mean = L_add(L_mean,abs_s(*pit1)); /*Q15 */ + pit1++; + } + mean = extract_l(Mult_32_16(L_mean,2048)); /*Q15 */ + pit1 -= 16; + move16(); + FOR(n_freq = 0; n_freq < 16; n_freq++) + { + if (LT_16(abs_s(*pit1),mean)) + { + *pit1 = mult_r(*pit1,6554); /*Q15*/ move16(); + } + pit1++; + } + } + } + + L = 1; + move16(); + if (EQ_16(mode,HARMONIC)) + { + L = 2; + move16(); + } + + FOR(n_band = 0; n_band < SWB_FENV; n_band += L) + { + energy = L_deposit_l(0); + tmp = add(swb_bwe_subband[n_band + L],st_offset); + FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) + { + L_tmp = L_mult(SWB_signal[n_freq],SWB_signal[n_freq]); /*Q31 */ + energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */ + } + + IF(energy == 0) + { + tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band];/*Q12 */ move16(); + if (NE_16(L,1)) + { + tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr(n_band, 1)];/*Q12 */ move16(); + } + + tmp = add(swb_bwe_subband[n_band + L],st_offset); + tmp_exp = sub(Q_syn,12); + FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) + { + SWB_signal_32[n_freq] = L_shl(L_mult(tmp_ener,SWB_signal[n_freq]),tmp_exp); /*Qsyn */ + } + } + ELSE + { + tmp = sub(swb_bwe_subband[n_band + L], swb_bwe_subband[n_band]); + exp1 = norm_s(tmp); + tmp = div_s(shl(1,sub(14,exp1)), tmp); /*Q(29-exp1) */ + energy = Mult_32_16(energy, tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */ + + exp = norm_l(energy); + L_tmp = L_shl(energy, exp); + /*exp = 31-exp-(-exp1+39);move16(); */ + exp = sub(sub(exp1,exp),8); + Ltmp_ener = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ + + tmp = add(swb_bwe_subband[n_band + L],st_offset); + tmp_exp = add(Q_syn,sub(exp,15)); + FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++) + { + SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]),tmp_exp); + move32();/*Qsyn+16 */ + } + } + } + +#ifdef BASOP_NOGLOB + IF(GT_16(*prev_Energy,add_sat(Energy_16,shr(Energy_16,2))) && Energy_16 > 0) +#else + IF(GT_16(*prev_Energy,add(Energy_16,shr(Energy_16,2))) && Energy_16 > 0) +#endif + { + weight = shr(div_s(Energy_16,*prev_Energy),1); /*Q15 */ + } + ELSE + { + weight = 16384; + move16();/*Q15 */ + } + L_tmp = L_mult(weight, prev_SWB_fenv[0]); /*Q17 */ + L_tmp = L_mac(L_tmp, sub(32767, weight), SWB_fenv[0]);/*Q17 */ + wfenv = round_fx(L_tmp); /*Q1 */ + + tmp = norm_s(wfenv); + IF(GT_16(tmp,4)) + { + tmp = 12; + move16(); + factor = fenvL_16; + move16();/*Q3 */ + factor1 = mult_r(sub(shl(wfenv,2),fenvL_16),4096); /*Q3 */ + } + ELSE + { + tmp = 14; + move16(); + factor = shr(fenvL_16,2);/*Q1 */ + factor1 = mult_r(sub(wfenv,factor), 4096); /*Q1 */ + } + + tmp2 = add(add(swb_bwe_subband[0],8),st_offset); + FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp2; n_freq++) + { + L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, tmp - 1 ); +#endif + move32();/*15+Qsyn */ + factor = add(factor, factor1); /*Q3 */ + } + + FOR(n_band = 0; n_band < 12; n_band++) + { + L_tmp = L_mult(weight, prev_SWB_fenv[n_band + 1]); /*Q17 */ + L_tmp = L_mac(L_tmp, sub(32767,weight), SWB_fenv[n_band + 1]);/*Q17 */ + wfenv = round_fx(L_tmp); /*Q1 */ + factor = SWB_fenv[n_band]; + move16(); /*Q1 */ + factor1 = mult_r(sub(wfenv,SWB_fenv[n_band]), smooth_factor_fx[n_band]); /*Q1 */ + tmp = norm_s(factor); + IF(GT_16(tmp,4)) + { + tmp = 12; + move16(); + factor = shl(factor, 2); + factor1 = shl(factor1, 2); + } + ELSE + { + tmp = 14; + move16(); + } + + tmp2 = add(swb_bwe_sm_subband[n_band + 1],st_offset); + FOR(; n_freq < tmp2; n_freq++) + { + L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, tmp - 1 ); +#endif + move32(); /*15+Qsyn */ +#ifdef BASOP_NOGLOB + factor = add_sat( factor, factor1 ); /*Q1 */ +#else + factor = add( factor, factor1 ); /*Q1 */ +#endif + } + } + L_tmp = L_mult(weight, prev_SWB_fenv[13]); /*Q17 */ + L_tmp = L_mac(L_tmp,sub(32767,weight), SWB_fenv[13]);/*Q17 */ + wfenv = round_fx(L_tmp); /*Q1 */ + factor = SWB_fenv[12]; + move16();/*Q1 */ + factor1 = mult_r(sub(wfenv, SWB_fenv[12]), smooth_factor_fx[12]); /*Q1 */ + tmp2 = add(swb_bwe_sm_subband[13],st_offset); + FOR(; n_freq < tmp2; n_freq++) + { + L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, 13 ); +#endif + move32();/*15+Qsyn */ + factor = add(factor,factor1); /*Q1 */ + } + + FOR(n_band = 13; n_band < SWB_FENV; n_band++) + { + L_tmp = L_mult(weight, prev_SWB_fenv[n_band]); /*Q17 */ + L_tmp = L_mac(L_tmp,sub(32767, weight), SWB_fenv[n_band]);/*Q17 */ + wfenv = round_fx(L_tmp); /*Q1 */ + tmp2 = add(swb_bwe_subband[n_band + 1],st_offset); + FOR(; n_freq < tmp2; n_freq++) + { + L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); +#ifdef BASOP_NOGLOB + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); +#else + SWB_signal_32[n_freq] = L_shl( L_tmp1, 13 ); +#endif + move32(); /*15+Qsyn */ + } + } + FOR(n_band = 0; n_band < SWB_FENV; n_band++) + { + prev_SWB_fenv[n_band] = SWB_fenv[n_band]; + move16();/*Q1 */ + } + } + pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */ + FOR(n_freq = 0; n_freq < 4; n_freq++) + { + L_tmp1 = Mult_32_16(*pit1_32, 16384); /*15+Qsyn */ + *(pit1_32++) = L_tmp1; + move32(); + } + *prev_Energy = Energy_16; + move16(); + + return; +} + +/*==========================================================================*/ +/* FUNCTION : void time_envelop_shaping_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Time shaping of SHB signal */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS */ +/* _(Word16) L :length */ +/* _(Word16) Q_syn :Q format */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _None */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _(Word16[])werr : SHB synthesis */ +/* _(Word16[])SWB_tenv : frequency envelope */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------*/ +void time_envelop_shaping_fx( + Word16 werr[], /* i/o: SHB synthesis Q_synth*/ + Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ + const Word16 L, /* i : frame length */ + Word16 *Q_synth +) +{ + Word16 *pit; + Word32 Energy; + Word16 i, j; + Word16 tmp_ener, Energy_16; + Word16 exp_L, exp, frac, tmp, inv_L; + Word32 L_tmp; + + pit = werr; + move16(); + exp_L = norm_s(L); + inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */ + FOR(i = 0; i < SWB_TENV; i++) + { + Energy = L_deposit_l(0); + FOR(j = 0; j < L / 4; j++) + { +#ifdef BASOP_NOGLOB + Energy = L_mac0_sat(Energy, *pit, *pit); /*(2*Q_synth) */ +#else + Energy = L_mac0(Energy, *pit, *pit); /*(2*Q_synth) */ +#endif + pit++; + } + Energy = Mult_32_16(Energy, inv_L); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth) */ + Energy_16 = 0; + move16(); + /*exp = 31-(-exp_L+14 +(2*(*Q_synth))); */ + exp = sub(17, sub(shl((*Q_synth), 1), exp_L)); + + IF(Energy != 0) + { + exp = norm_l(Energy); + frac = extract_h(L_shl(Energy, exp)); + /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)))); */ + exp = sub(exp, sub(30, add(sub(shl((*Q_synth), 1), exp_L), 14 - 2))); + + tmp = div_s(16384, frac); + L_tmp = L_deposit_h(tmp); + Energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ + Energy_16 = round_fx(L_shl(Energy, sub(exp, 15))); /*Q0 */ + } + + test(); +#ifdef BASOP_NOGLOB + IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl_sat(SWB_tenv[i], sub(16, exp)))) +#else + IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl(SWB_tenv[i], sub(16, exp)))) +#endif + { + *Q_synth = add(*Q_synth, 3); + move16(); + } + ELSE + { + pit -= L / 4; + move16(); + tmp_ener = 0; + move16(); + exp = 0; + move16(); + + IF(Energy_16 != 0) + { + exp = norm_s(Energy_16); + tmp_ener = div_s(shl(1,sub(14,exp)), Energy_16); /*Q(29-exp) */ + } + + L_tmp = Mult_32_16(SWB_tenv[i], tmp_ener); /*Q(29-exp) */ + tmp = round_fx(L_tmp); /*Q(13-exp) */ + + FOR(j = 0; j < L / 4; j++) + { +#ifdef BASOP_NOGLOB + *pit = round_fx_sat(L_shl_sat(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ +#else + *pit = round_fx(L_shl(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ +#endif + pit++; + } + } + } + + return; +} + +/*==========================================================================*/ +/* FUNCTION : void time_reduce_pre_echo_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Windowing and time-domain aliasing */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS */ +/* _(Word16*) synth :ACELP core synthesis Q_syn */ +/* _(Word16) L :subframe length */ +/* _(Word16) Q_syn :Q format */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _(Word16*)error : SHB BWE synthesis Q_syn */ +/* _(Word16)prev_td_energy : last td energy Q_syn */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------*/ +void time_reduce_pre_echo_fx( + const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ + Word16 *error, /* i/o: SHB BWE synthesis Q0*/ + Word16 prev_td_energy, /* o : last td energy Q0*/ + const Word16 L, /* i : subframe length */ + Word16 Q_syn, + Word16 Q_synth +) +{ + Word16 i, j, pos = 0, Len; + Word32 energy; + Word16 energy_16; + Word32 energyL[4]; + Word16 tmp_ener; + Word16 *pit; + Word16 tmpi, tmp_exp; + Word16 exp_L, exp, frac, inv_L, exp_j, tmp; + Word32 L_tmp, L_tmp1, Ltmp_ener; + + exp_L = norm_s(L); + inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */ + FOR(i = 0; i < 4; i++) + { + Len = i_mult(L, i); + + L_tmp = L_deposit_l(0); + FOR(j = 0; j < L; j++) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */ +#else + L_tmp = L_mac0( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */ +#endif + } + energyL[i] = Mult_32_16(L_shr(L_tmp, sub(14, exp_L)), inv_L); + move32(); /*Q(2*Q_syn +29-exp_L-15 - (14-exp_L) ) -> Q(2*Q_syn) */ + + IF(energyL[i] != 0) + { + exp = norm_l(energyL[i]); + frac = extract_h(L_shl(energyL[i], exp)); + exp = sub(exp, sub(30, shl(Q_syn, 1))); + + tmp = div_s(16384, frac); + L_tmp = L_deposit_h(tmp); + L_tmp = Isqrt_lc(L_tmp, &exp); + energyL[i] = L_shl(L_tmp, sub(exp, 16)); + move32();/* Q15 */ + } + } + + FOR(i = 0; i < 3; i++) + { + L_tmp = Mult_32_16(energyL[i], 29491); /*Q14 */ + test(); + IF(GT_32(L_shr(energyL[i + 1], 1), L_tmp) && GT_32(energyL[i + 1], 1638400)) + { + pos = add(i, 1); + move16(); + BREAK; + } + } + + IF(pos > 0) + { + if (LT_16(pos, 3)) + { + pos = add(pos, 1); + } + energy = L_deposit_l(0); + j = i_mult(L, pos); + move16(); + FOR(i = 0; i < j; i++) + { +#ifdef BASOP_NOGLOB + energy = L_mac0_sat(energy, error[i], error[i]); /*Q(2*Q_synth) */ +#else + energy = L_mac0(energy, error[i], error[i]); /*Q(2*Q_synth) */ +#endif + } + + exp_j = norm_s(j); + tmp = div_s(shl(1, sub(14, exp_j)), j); /*Q(29-exp_j) */ + energy = Mult_32_16(energy, tmp); /*Q(29-exp_j+1-16) -> Q(-exp_j+14 +2*Q_synth) */ + energy_16 = 0; + move16(); + + IF(energy != 0) + { + exp = norm_l(energy); + frac = extract_h(L_shl(energy, exp)); + /*exp = sub(exp, 30-(-exp_j+14 +2*Q_synth)); */ + exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_j))); + tmp = div_s(16384, frac); + L_tmp = L_deposit_h(tmp); + energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ + energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */ + } + + tmp = mult_r(energy_16, 6554); /*Q0 */ + if (LT_16(prev_td_energy, tmp)) + { + prev_td_energy = tmp; + move16(); + } + + tmp_ener = 0; + move16(); + exp = 0; + move16(); + IF(energy_16 != 0) + { + exp = norm_s(energy_16); + tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */ + } + L_tmp = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ + tmp_exp = add(1, exp); + FOR(i = 0; i < j; i++) + { +#ifdef BASOP_NOGLOB + error[i] = round_fx_sat(L_shl_sat(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ +#else + error[i] = round_fx(L_shl(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ +#endif + } + + energy = L_deposit_l(0); + FOR(i = j; i < (j + L); i++) + { +#ifdef BASOP_NOGLOB + energy = L_mac0_sat(energy, error[i], error[i]); /*(2*Q_synth) */ +#else + energy = L_mac0(energy, error[i], error[i]); /*(2*Q_synth) */ +#endif + } + + energy = Mult_32_16(energy, inv_L); /*Q(29-exp_L+1-16) -> Q(-exp_L+14) */ + energy_16 = 0; + move16(); + IF(energy != 0) + { + exp = norm_l(energy); + frac = extract_h(L_shl(energy, exp)); + /*exp = sub(exp, 30-(-exp_L+14+2*Q_synth)); */ + exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_L))); + + tmp = div_s(16384, frac); + L_tmp = L_deposit_h(tmp); + energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ + energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */ + } + + tmp_ener = 0; + move16(); + exp = 0; + move16(); + IF(energy_16 != 0) + { + exp = norm_s(energy_16); + tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */ + } + Ltmp_ener = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ + L_tmp1 = L_shl(1, sub(30, exp)); + + pit = &error[j]; + move16(); + FOR(i = 0; i < L; i++) + { + tmpi = round_fx(L_shl(L_mult(i, inv_L), add(1, exp_L))); /*Q15 */ + L_tmp = L_sub(L_tmp1, Ltmp_ener); /*Q(30-exp) */ + L_tmp = Mult_32_16(L_tmp, tmpi); /*Q(30-exp) */ + L_tmp = L_add(Ltmp_ener, L_tmp); /*Q(30-exp) */ +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */ +#else + tmp = round_fx( L_shl( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */ +#endif + *pit++ = tmp; + } + } + + return; +} + +/*-------------------------------------------------------------------* + * calc_normal_length_fx_32() + * + *-------------------------------------------------------------------*/ +void calc_normal_length_fx_32( + const Word16 core, /* i : core : Q0 */ + const Word32 *sp, /* i : input signal : Q12 */ + const Word16 mode, /* i : input mode : Q0 */ + const Word16 extl, /* i : extension layer : Q0 */ + Word16 *L_swb_norm, /* o : normalize length : Q0 */ + Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ +) +{ + Word16 i, n_freq, n_band, THRES; + Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; + Word16 N; + + const Word32 *pit; + Word32 peak, mean, mag; + Word32 L_tmp1, L_tmp2; + + THRES = 4; + move16(); + test(); + test(); + if (EQ_16(core, HQ_CORE) || EQ_16(extl, SWB_BWE) || EQ_16(extl, FB_BWE)) + { + THRES = 8; + move16(); + } + + N = 16; + move16(); + test(); + test(); + if (EQ_16(core, HQ_CORE) && (EQ_16(mode, HQ_HARMONIC) || EQ_16(mode, HQ_HVQ))) + { + N = 13; + move16(); + } + + n_band = 0; + move16(); + pit = sp; + move16(); + FOR(i = 0; i < N; i++) + { + peak = 0; + move16(); + mean = 0; + move16(); + + FOR(n_freq = 0; n_freq < 16; n_freq++) + { + mag = L_abs(*pit); + if (GT_32(mag, peak)) + { + peak = mag; + move16(); + } +#ifdef BASOP_NOGLOB + mean = L_add_sat( mean, mag ); +#else + mean = L_add( mean, mag ); +#endif + pit++; + } + + L_tmp1 = Mult_32_16(peak, shl(15 + THRES, 10)); + L_tmp2 = Mult_32_16(mean, shl(THRES, 10)); + test(); + if (GT_32(L_tmp1, L_tmp2) && GT_32(peak, 40960)) + { + n_band = add(n_band, 1); + } + } + + IF(EQ_16(core, ACELP_CORE)) + { + L_swb_norm_trans = add(4, shr(n_band, 2)); + L_swb_norm_norm = add(8, shr(n_band, 1)); + L_swb_norm_harm = s_max(add(32, shl(n_band, 1)), 24); + + IF(mode == HARMONIC) + { + L_swb_norm_cur = L_swb_norm_harm; + move16(); + } + ELSE IF(mode == NORMAL) + { + L_swb_norm_cur = L_swb_norm_norm; + move16(); + } + ELSE + { + L_swb_norm_cur = L_swb_norm_trans; + move16(); + } + + *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1); + move16(); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + ELSE + { + test(); + IF(mode == HQ_HARMONIC || mode == HQ_HVQ) + { + L_swb_norm_cur = add(32, add(shl(n_band, 1), shr(n_band, 1))); + } + ELSE + { + L_swb_norm_cur = add(8, shr(n_band, 1)); + } + + *L_swb_norm = extract_h(L_add(L_mac(L_mult(L_swb_norm_cur, 3276), *prev_L_swb_norm, 29491),32768)); + *prev_L_swb_norm = L_swb_norm_cur; + move16(); + } + + return; +} + + +/*-------------------------------------------------------------------* + * calc_norm_envelop_fx_32() + * + *-------------------------------------------------------------------*/ +void calc_norm_envelop_fx_32( + const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ + Word32 *envelope_fx, /* o : normalized envelope : Q16 */ + const Word16 L_swb_norm, /* i : length of envelope : Q0 */ + const Word16 SWB_flength, /* i : Length of input/output : Q0 */ + const Word16 st_offset /* i : offset : Q0 */ +) +{ + Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; + + lookback = L_swb_norm / 2; + move16(); + env_index = swb_bwe_subband[0] + st_offset; + move16(); + n_lag_now = L_swb_norm; + move16(); + tmp = sub(add(SWB_flength, st_offset), L_swb_norm); + FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++) + { + /* Apply MA filter */ + envelope_fx[env_index] = 0; + move16(); + FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) + { +#ifdef BASOP_NOGLOB + envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); +#else + envelope_fx[env_index] = L_add( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); +#endif + move32(); + } + env_index++; + } + i = 0; + move16(); + tmp = sub(add(SWB_flength, st_offset), lookback); + FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++) + { + Word32 L_tmp; + + n_lag_now = L_swb_norm - i; + move16(); + /* Apply MA filter */ + L_tmp = L_deposit_l(0); + FOR(n_lag = 0; n_lag < n_lag_now; n_lag++) + { + L_tmp = L_add(L_tmp, L_abs(SWB_signal_fx[n_freq + n_lag])); + } + envelope_fx[env_index] = L_tmp; + move32(); + env_index = add(env_index, 1); + i++; + } + + return; +} + +/*-------------------------------------------------------------------* + * hq_generic_decoding_fx() + * + *-------------------------------------------------------------------*/ +void hq_generic_decoding_fx( + const Word16 HQ_mode, /* i : HQ mode : Q0 */ + Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ + const Word16 *R +) +{ + Word16 i, n_freq, n_band, L_swb_norm; + Word16 k; + Word16 nenv; + Word16 tenv; + + Word16 exp, exp1, exp2, frac, tmp, tmp2, cs; + Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx; + Word16 fenvL_fx, wfenv_fx, factor_fx; + Word32* pit1_fx; + Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx; + Word32 energy_fx; + + Word32 envelope_fx[L_FRAME16k]; + Word32 mean_vector_fx[20]; + Word16 rn_weight0_fx; + Word16 s; + Word16 blen, nband_lf, sfidx, efidx; + Word16 bwe_seed; + Word16 signum[L_FRAME16k]; + + nenv = sub(SWB_FENV, 2); + if (LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) + { + nenv = SWB_FENV; + move16(); + } + + tenv = nenv; + move16(); + if (EQ_16(HQ_mode, HQ_GEN_FB)) + { + tenv = add(nenv, DIM_FB); + } + + max_coeff_fx = 0; + move16(); + tmp = add(swb_bwe_subband[0], hq_generic_offset); + FOR(n_freq = add(HQ_GENERIC_ST_FREQ, hq_generic_offset); n_freq < tmp; n_freq++) + { + max_coeff_fx = L_max(max_coeff_fx, L_abs(coeff_out1_fx[n_freq])); + } + cs = norm_l(max_coeff_fx); + + L_tmp = 0; + move16(); + tmp2 = add(swb_bwe_subband[0], hq_generic_offset); + FOR(n_freq = add(HQ_GENERIC_ST_FREQ, hq_generic_offset); n_freq < tmp2; n_freq++) + { + tmp = extract_h(L_shl(coeff_out1_fx[n_freq], cs));/*12 + cs - 16 */ + L_tmp1 = L_mult0(tmp, tmp);/*2*(cs-2) */ + L_tmp = L_add(L_tmp, L_shr(L_tmp1, 5));/*2*(cs-2) - 5 */ + } + cs = sub(shl(cs, 1), 9); + fenvL_fx = 0; + move16(); + IF(L_tmp != 0) + { + exp = norm_l(L_tmp); +#ifdef EVS_FUNC_MODIFIED + frac = round_fx_sat(L_shl(L_tmp, exp));/*cs+exp-16 */ +#else + frac = round_fx(L_shl(L_tmp, exp));/*cs+exp-16 */ +#endif + tmp = div_s(16384, frac);/*15 + 14 - (cs+exp-16) */ + exp = sub(add(cs, exp), 30); + L_tmp = Isqrt_lc(L_deposit_h(tmp), &exp);/*Q31 - exp */ +#ifdef BASOP_NOGLOB + fenvL_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ +#else + fenvL_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ +#endif + } + + calc_normal_length_fx_32(HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm); + + calc_norm_envelop_lf_fx(coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx); + + blen = 16; + move16(); + + IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC0)) + { + rn_weight0_fx = 819; + move16();/* 0.8 Q10 */ + } + ELSE IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC1)) + { + rn_weight0_fx = 51; + move16();/* 0.05 Q10*/ + } + ELSE + { + rn_weight0_fx = 205; + move16();/* 0.02 Q10 */ + } + + tmp = sub(efidx, sfidx); + IF(EQ_16(tmp, 0)) + { + nband_lf = 0; + } + ELSE + { + exp = norm_s(tmp); + nband_lf = shl(tmp,sub(exp,1)); + exp1 = norm_s(blen); + tmp = shl(blen,exp1); + nband_lf = shr(div_s(nband_lf,tmp), add(sub(14,exp1),exp));/* 15 + exp-1 - exp1, Q0*/ + } + + FOR(n_freq = sfidx; n_freq < efidx; n_freq++) + { + IF(coeff_out1_fx[n_freq] < 0) + { + signum[n_freq] = -1; + move16(); + coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); + move32(); + } + ELSE + { + signum[n_freq] = 1; + move16(); + } + } + + /* applying whitening */ + FOR(n_freq = sfidx; n_freq < efidx; n_freq++) + { + exp = norm_l(coeff_out1_fx[n_freq]) - 1; + exp1 = norm_l(envelope_fx[n_freq]); + + L_tmp = L_shl(coeff_out1_fx[n_freq], exp); + L_tmp1 = L_shl(envelope_fx[n_freq], exp1); + + logic16(); + coeff_out1_fx[n_freq] = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); + move32();/*31 + exp1 - exp2*/ + + exp = add(31, sub(exp, exp1)); + coeff_out1_fx[n_freq] = L_shl(coeff_out1_fx[n_freq], sub(20, exp)); + move32();/*Q12->Q20*/ + } + + /* mean vector generation for controlling dynamic range */ + FOR(k = 0; k < nband_lf; ++k) + { + energy_fx = 1; + move16(); + + tmp = add(i_mult2(add(k, 1), blen), sfidx); + FOR(i = add(i_mult2(k, blen), sfidx); i < tmp; ++i) + { + energy_fx = L_add(energy_fx, coeff_out1_fx[i]); + } + exp = sub(norm_l(energy_fx), 1); + L_tmp = L_shl(energy_fx, exp); + exp1 = norm_l(L_and(blen, 0x00007fff)); + L_tmp1 = L_shl(blen, exp1); + logic16(); + mean_vector_fx[k] = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); + move32();/*31 + 20 + exp1 - exp2*/ + exp = add(51, sub(exp, exp1)); + mean_vector_fx[k] = L_shl(mean_vector_fx[k], sub(20, exp)); + move32();/*Q12->Q20*/ + } + + /* dynamics control */ + FOR(k = 0; k < nband_lf; ++k) + { + tmp = add(i_mult2(add(k, 1), blen), sfidx); + FOR(i = add(i_mult2(k, blen), sfidx); i < tmp; ++i) + { + L_tmp = L_sub(coeff_out1_fx[i], mean_vector_fx[k]); + exp = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, exp); /* exp+12*/ + exp1 = norm_l(rn_weight0_fx); + L_tmp1 = L_shl(rn_weight0_fx, exp1); /* exp1+10*/ + L_tmp = L_mult(extract_h(L_tmp), extract_h(L_tmp1)); + L_tmp = L_shr(L_tmp, add(exp, sub(exp1, 21))); /* Q20*/ + coeff_out1_fx[i] = L_sub(coeff_out1_fx[i], L_tmp); + move32(); + } + } + + IF(EQ_16(hq_generic_exc_clas, HQ_GENERIC_EXC0)) + { + bwe_seed = add(add(shl(R[0], 3), shl(R[1], 2)), add(shl(R[2], 1), R[3])); + + FOR(n_freq = sfidx; n_freq < efidx; n_freq++) + { + IF(signum[n_freq] < 0) + { + coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); + move32(); + } + + IF(Random(&bwe_seed) < 0) + { + coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); + move32(); + } + } + } + ELSE + { + FOR(n_freq = sfidx; n_freq < efidx; n_freq++) + { + IF(signum[n_freq] < 0) + { + coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); + move32(); + } + } + } + + /* normalizing modified low frequency spectrum */ + FOR(k = 0; k < nband_lf; ++k) + { + energy_fx = 1; + move16(); + tmp = add(i_mult2(add(k, 1), blen), sfidx); + FOR(i = add((i_mult2(k, blen)), sfidx); i < tmp; ++i) + { + exp = norm_l(coeff_out1_fx[i]); + L_tmp1 = L_shl(coeff_out1_fx[i], exp);/* exp + 12*/ + + L_tmp = Mult_32_32(L_tmp1, L_tmp1); + L_tmp = L_shr(L_tmp, sub(i_mult2(2, exp), 11));/*Q20 */ + energy_fx = L_add(energy_fx, L_tmp); + } + + exp = norm_l(energy_fx); + L_tmp = L_shl(energy_fx, sub(exp, 1)); + exp1 = norm_s(blen); + L_tmp1 = L_shl((Word32)blen, add(exp1, 16)); + + L_tmp = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); + exp = sub(add(34, exp), exp1); + L_tmp = L_shr(L_tmp, sub(exp, 31)); + exp = 31; + move16(); + + exp = sub(31, exp); + IF(exp & 0x1) + { + L_tmp = L_shr(L_tmp, 1); + exp = add(exp, 1); + } + L_tmp = Sqrt_l(L_tmp, &exp1); + exp = add(31, sub(shr(exp1, 1), shr(exp, 1))); + energy_fx = L_shl(L_tmp, sub(31, exp)); /*Q31*/ + + tmp = add(i_mult2(add(k, 1), blen), sfidx); + FOR(i = add((i_mult2(k, blen)), sfidx); i < tmp; ++i) + { + IF(NE_32(L_abs(coeff_out1_fx[i]), coeff_out1_fx[i])) + { + s = -1; + move16(); + coeff_out1_fx[i] = L_abs(coeff_out1_fx[i]); + move32(); + } + ELSE + { + s = 0; + move16(); + } + exp = norm_l(coeff_out1_fx[i]); + L_tmp = L_shl(coeff_out1_fx[i], sub(exp, 1)); + exp1 = norm_l(energy_fx); + L_tmp1 = L_shl((Word32)energy_fx, exp1); + logic16(); + L_tmp = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1, 1)) & 0x00007fff); + exp = add(sub(19, exp1), exp); + coeff_out1_fx[i] = L_shl(L_tmp, add(sub(12, exp), 15)); + move32(); /* Q12 -> Q27 */ + IF(s) + { + coeff_out1_fx[i] = L_negate(coeff_out1_fx[i]); + move32(); + } + } + } + + Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH0, hq_generic_offset)], HQ_GENERIC_LEN0); + Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH1, hq_generic_offset)], HQ_GENERIC_LEN0); + + IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) + { + Copy32(&coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)], sub(HQ_GENERIC_END_FREQ, HQ_GENERIC_HIGH2)); + } + + IF(EQ_16(HQ_mode, HQ_GEN_FB)) + { + IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) + { + Copy32(&coeff_out1_fx[sub(add(HQ_GENERIC_LOW0, HQ_GENERIC_END_FREQ), HQ_GENERIC_HIGH2)], &coeff_out_fx[fb_bwe_subband[0]], 160); + } + ELSE + { + Copy32(&coeff_out1_fx[add(HQ_GENERIC_OFFSET , HQ_GENERIC_LEN0)], &coeff_out_fx[fb_bwe_subband[0]], 160); + } + } + + + L_tmp1 = L_deposit_l(0); + L_tmp2 = L_deposit_l(0); + FOR(i = 0; i < 5; ++i) + { + L_tmp1 = L_add(L_tmp1, L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH1, hq_generic_offset), i)])); + L_tmp2 = L_add(L_tmp2, L_abs(coeff_out_fx[sub(add(sub(HQ_GENERIC_HIGH1, 2), hq_generic_offset), i)])); + } + + pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH1, hq_generic_offset)]; + L_tmp1 = L_max(L_tmp1, 1); + L_tmp2 = L_max(L_tmp2, 1); + exp1 = norm_l(L_tmp1); + exp2 = sub(norm_l(L_tmp2), 1); + tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); + tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); + tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ + + if (LT_16(tmp3_fx, 307)) + { + tmp3_fx = 307; + move16(); + } + FOR(; tmp3_fx < 1024; tmp3_fx += 102) + { + *pit1_fx = Mult_32_16(*pit1_fx, shl(tmp3_fx, 5)); + move32();/*15 + 5 + 10 -15 */ + pit1_fx++; + } + + pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH1, 1), hq_generic_offset)]; + + exp1 = sub(norm_l(L_tmp1), 1); + exp2 = norm_l(L_tmp2); + tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); + tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); + tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ + + IF(GT_16(tmp3_fx, 5120)) + { + FOR(tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512) + { + L_tmp1 = Mult_32_16(L_shl(*pit1_fx, 5), tmp3_fx); /*15 + 5 + 10 -15 */ + *pit1_fx-- = L_tmp1; + move32(); + } + } + + IF(LE_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4)) + { + L_tmp1 = L_add(L_abs(coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)]), L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH2, 1), hq_generic_offset)])); + L_tmp2 = L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 4), hq_generic_offset)]), L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 3), hq_generic_offset)]), + L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 2), hq_generic_offset)]), L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 1), hq_generic_offset)])))); + + pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH2, hq_generic_offset)]; + + L_tmp1 = L_max(L_tmp1, 1); + L_tmp2 = L_max(L_tmp2, 1); + exp1 = norm_l(L_tmp1); + exp2 = sub(norm_l(L_tmp2), 1); + tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); + tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); + tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ +#ifdef BASOP_NOGLOB + tmp3_fx = shr_sat( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ +#else + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ +#endif + if (LT_16(tmp3_fx, 307)) + { + tmp3_fx = 307; + move16(); + } + FOR(; tmp3_fx < 1024; tmp3_fx += 102) + { + L_tmp = L_shl(Mult_32_16(*pit1_fx, tmp3_fx), 5); /*15 + 5 + 10 -15 */ + *pit1_fx++ = L_tmp; + move32(); + } + + pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH2, 1), hq_generic_offset)]; + + exp1 = sub(norm_l(L_tmp1), 1); + exp2 = norm_l(L_tmp2); + tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); + tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); + tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ + tmp3_fx = shr(tmp3_fx, 1); + tmp4_fx = mult_r(tmp3_fx, 1638); + WHILE(tmp3_fx > 1024) + { +#ifdef EVS_FUNC_MODIFIED + L_tmp1 = L_shl(Mult_32_16(*pit1_fx , tmp3_fx), 5); /*15 + 5 + 10 -15 */ +#else + L_tmp1 = Mult_32_16(L_shl(*pit1_fx, 5), tmp3_fx); /*15 + 5 + 10 -15 */ +#endif + *pit1_fx-- = L_tmp1; + move32(); + tmp3_fx = sub(tmp3_fx, tmp4_fx); + } + } + + + wfenv_fx = hq_generic_fenv_fx[0]; + move16();/*1 */ + i = 0; + move16(); + tmp2 = add(add(swb_bwe_subband[0], hq_generic_offset), 8); + FOR(n_freq = add(swb_bwe_subband[0], hq_generic_offset); n_freq < tmp2; n_freq++) + { + factor_fx = shl(i, 12);/*15 */ + L_tmp1 = L_mult(sub(32767, factor_fx), fenvL_fx);/*17 */ + L_tmp2 = L_mult(factor_fx, wfenv_fx);/*17 */ + L_tmp1 = L_add(L_tmp1, L_tmp2);/*17 */ + + cs = norm_l(L_tmp1); + tmp = extract_h(L_shl(L_tmp1, cs));/*17 + cs - 16 */ + L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 17 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shr(L_tmp, add(1, cs)); + move32();/*12 */ + i++; + move16(); + } + + k = sub(nenv, 2); + FOR(n_band = 0; n_band < k; n_band++) + { + wfenv_fx = hq_generic_fenv_fx[add(n_band, 1)]; + move16();/*1 */ + + tmp2 = swb_bwe_sm_subband[add(n_band, 1)] + hq_generic_offset; + FOR(i = 0; n_freq < tmp2; i++) + { + L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[n_band]), smooth_factor_fx[n_band]);/*17 */ + L_tmp1 = Mult_32_16(L_tmp1, shl(i, 10));/*17 + 10 - 15 */ + L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[n_band], 11));/*12 */ + + cs = norm_l(L_tmp1); + tmp = extract_h(L_shl(L_tmp1, cs));/*12 + cs - 16 */ + L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 12 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl(L_tmp, sub(4, cs)); + move32();/*12 */ + n_freq++; + } + } + + wfenv_fx = hq_generic_fenv_fx[sub(nenv, 1)]; + move16();/*1 */ + tmp2 = add(swb_bwe_sm_subband[sub(nenv, 1)], hq_generic_offset); + FOR(i = 0; n_freq < tmp2; i++) + { + L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[sub(nenv, 2)]), smooth_factor_fx[sub(nenv, 2)]);/*17 */ + L_tmp1 = Mult_32_16(L_tmp1, shl(i, 10));/*17 + 10 - 15 */ + L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[sub(nenv, 2)], 11));/*12 */ + + cs = norm_l(L_tmp1); + tmp = extract_h(L_shl(L_tmp1, cs));/*12 + cs - 16 */ + L_tmp = Mult_32_16(coeff_out_fx[n_freq], tmp);/*12 + 15 + 12 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl(L_tmp, sub(4, cs)); + move32();/*12 */ + n_freq++; + } + + IF(EQ_16(HQ_mode, HQ_GEN_SWB)) + { + FOR(n_band = sub(nenv, 1); n_band < nenv; ++n_band) + { + wfenv_fx = hq_generic_fenv_fx[n_band]; + move16();/*1 */ + tmp2 = add(swb_bwe_subband[add(n_band, 1)], hq_generic_offset); + FOR(; n_freq < tmp2; n_freq++) + { + L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr(L_tmp, 1); + move32();/*12 */ + } + } + } + ELSE + { + test(); + IF(hq_generic_fenv_fx[sub(nenv,1)] - hq_generic_fenv_fx[nenv] > 30 || hq_generic_fenv_fx[nenv] < 10) + { + wfenv_fx = hq_generic_fenv_fx[sub(nenv,1)]; + move16();/*1 */ + FOR(i = 0; n_freq < fb_bwe_subband[0]; i++) + { + L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr(L_tmp, 1); + move32();/*12 */ + n_freq++; + } + + FOR(n_band = 0; n_band < DIM_FB; n_band++) + { + wfenv_fx = hq_generic_fenv_fx[add(n_band , nenv)]; + move16();/*1 */ + tmp2 = fb_bwe_subband[add(n_band,1)]; + FOR(i = 0; n_freq < tmp2; i++) + { + L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr(L_tmp, 1); + move32();/*12 */ + n_freq++; + } + } + } + ELSE + { + FOR(n_band = 0; n_band < DIM_FB; n_band++) + { + wfenv_fx = hq_generic_fenv_fx[sub(add(n_band,nenv),1)]; + move16();/*1 */ + + FOR(i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++) + { + L_tmp1 = L_mult(sub(wfenv_fx, hq_generic_fenv_fx[add(n_band,nenv)]), fb_smooth_factor_fx[n_band]);/*17 */ + L_tmp1 = Mult_32_16(L_tmp1, shl(i, 9));/*17 + 9 - 15 */ + L_tmp1 = L_add(L_tmp1, L_shl(hq_generic_fenv_fx[add(n_band,nenv)], 10));/*11 */ + + cs = norm_l(L_tmp1); + tmp = extract_h(L_shl(L_tmp1, cs));/*11 + cs - 16 */ + L_tmp = Mult_32_16(coeff_out_fx[n_freq] , tmp);/*12 + 15 + 11 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl(L_tmp, sub(5, cs)); + move32();/*12 */ + n_freq++; + } + } + + wfenv_fx = hq_generic_fenv_fx[sub(tenv,1)]; + move16();/*1 */ + + FOR(; n_freq < fb_bwe_subband[DIM_FB]; n_freq++) + { + L_tmp = Mult_32_16(coeff_out_fx[n_freq], wfenv_fx);/*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr(L_tmp, 1); + move32();/*12 */ + } + } + } + + return; +} + + + +/*-------------------------------------------------------------------* + * save_old_syn() + * + * Save and delay the ACELP core synthesis signal by + * DELAY_FD_BWE_ENC_xxkx to be used by SWB BWE + *-------------------------------------------------------------------*/ + +void save_old_syn_fx( + const Word16 L_frame, /* i : frame length */ + const Word16 syn[], /* i : ACELP synthesis */ + Word16 old_syn[], /* o : old synthesis buffer */ + Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ + const Word16 preemph_fac, /* i : preemphasis factor */ + Word16 *mem_deemph /* i/o: deemphasis filter memory */ +) +{ + Word16 tmps; + + tmps = NS2SA(16000, DELAY_FD_BWE_ENC_16k_NS); + move16(); + if (EQ_16(L_frame, L_FRAME)) + { + tmps = NS2SA(12800, DELAY_FD_BWE_ENC_12k8_NS); + move16(); + } + Copy(old_syn_mem, old_syn, tmps); + Copy(syn, old_syn + tmps, L_frame - tmps); + Copy(syn + L_frame - tmps, old_syn_mem, tmps); + + deemph_fx(old_syn, preemph_fac, L_frame, mem_deemph); + + return; +} diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 35e0f39f87d2a3b333ebf120b08f56b1f7e0b6c0..9eb548b4b1352b2e0d47d76c61ffdc04f2ba3999 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -2290,8 +2290,11 @@ void ton_ene_est_fx( exp_pow = sub(14, temp_hi_fx); L_band_energy_Linear[i] = Pow2(14, temp_lo_fx); move32(); /* Qexp_pow */ - L_band_energy_Linear[i] = L_shl(L_band_energy_Linear[i], sub(*QbeL, exp_pow)); - +#ifdef BASOP_NOGLOB + L_band_energy_Linear[i] = L_shl_sat( L_band_energy_Linear[i], sub( *QbeL, exp_pow ) ); +#else + L_band_energy_Linear[i] = L_shl( L_band_energy_Linear[i], sub( *QbeL, exp_pow ) ); +#endif /* Div Part */ E_r_fx = 0x7fff; move16(); @@ -2380,7 +2383,11 @@ void ton_ene_est_fx( L_E = sum2_fx(&xSynth_har_fx[sub(band_start[i], fLenLow)], band_width[i]); QE = add(shl(QxSynth_sft, 1), 1); - L_E = L_shl(L_E, sub(*QbeL, QE)); +#ifdef BASOP_NOGLOB + L_E = L_shl_sat( L_E, sub( *QbeL, QE ) ); +#else + L_E = L_shl( L_E, sub( *QbeL, QE ) ); +#endif QE = *QbeL; } ELSE @@ -2584,16 +2591,22 @@ void Gettonl_scalfact_fx exp_pow = sub(14, temp_hi_fx); L_band_energy_Linear[band_pos_fx] = Pow2(14, temp_lo_fx); move32(); /* Qexp_pow */ - L_band_energy_Linear[band_pos_fx] = L_shl(L_band_energy_Linear[band_pos_fx], sub(QbeL, exp_pow)); - +#ifdef BASOP_NOGLOB + L_band_energy_Linear[band_pos_fx] = L_shl_sat( L_band_energy_Linear[band_pos_fx], sub( QbeL, exp_pow ) ); +#else + L_band_energy_Linear[band_pos_fx] = L_shl( L_band_energy_Linear[band_pos_fx], sub( QbeL, exp_pow ) ); +#endif /* Div Part */ exp_normd = norm_l(L_be_tonal[band_pos_fx]); exp_normd = sub(exp_normd, 1); exp_normn = norm_l(L_band_energy_Linear[band_pos_fx]); temp_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_band_energy_Linear[band_pos_fx], exp_normn))); /* QbeL+exp_normd-(QbeL+exp_normn-16)-1 */ sqrt_32n_16_fx(L_deposit_h(temp_fx), add(sub(exp_normd, exp_normn), 31), &temp_fx, &Qtemp); - enrd_r_fx = extract_h(L_shl(L_mult(enrd_r_fx, temp_fx), sub(15, Qtemp))); - +#ifdef BASOP_NOGLOB + enrd_r_fx = extract_h( L_shl_sat( L_mult( enrd_r_fx, temp_fx ), sub( 15, Qtemp ) ) ); +#else + enrd_r_fx = extract_h( L_shl( L_mult( enrd_r_fx, temp_fx ), sub( 15, Qtemp ) ) ); +#endif enrd_r_fx = sub(enrd_r_fx, step_fx); } ELSE diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 50166970b989f1f43bb4600b647c8cb9fd6e562f..a9d1e6ce0c82836f3f852e929fe6537ce83c2c23 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3042,23 +3042,38 @@ void ScaleShapedWB_fx( { /* mod_syn in (16+Q_bwe_exc), frame_gain in Q18 */ L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* L_tmp in (Q_bwe_exc+3) */ - synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift) ); /* Qx */ +#ifdef BASOP_NOGLOB + synSHB[i] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ + synSHB[i] = add_sat( synSHB[i], overlap[i] ); + move16(); /* Qx */ + synSHB[i + l_shb_lahead] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx */ +#else + synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ synSHB[i] = add( synSHB[i], overlap[i] ); - move16(); /* Qx */ - synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift) ); /* Qx */ + move16(); /* Qx */ + synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift ) ); /* Qx */ +#endif } FOR ( ; i < l_frame; i++ ) { L_tmp = Mult_32_32( mod_syn[i], frame_gain); /* L_tmp in (Q_bwe_exc+3) */ - synSHB[i] = round_fx( L_shl(L_tmp, shift) ); /* Qx; */ +#ifdef BASOP_NOGLOB + synSHB[i] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx; */ +#else + synSHB[i] = round_fx( L_shl( L_tmp, shift ) ); /* Qx; */ +#endif } l_frame_tmp = add(l_frame, l_shb_lahead); FOR ( ; i < l_frame_tmp; i++ ) { L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* (Q_bwe_exc+3) */ - overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ +#ifdef BASOP_NOGLOB + overlap[i - l_frame] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ +#else + overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ +#endif } return; @@ -3088,7 +3103,11 @@ static Word32 non_linearity_scaled_copy( { FOR ( i = 0; i < j; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ output[i] = L_tmp; move32(); @@ -3098,7 +3117,11 @@ static Word32 non_linearity_scaled_copy( } FOR ( ; i < length; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ output[i] = L_tmp; move32(); @@ -3108,7 +3131,11 @@ static Word32 non_linearity_scaled_copy( { FOR ( i = 0; i < j; i++ ) { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat( input[i], input[i] ); /* 2*Q_inp+1 */ +#else + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ if ( input[i] < 0 ) @@ -4267,10 +4294,82 @@ void elliptic_bpf_48k_generic_fx( FOR( j=0; j<4; j++ ) { - memory2_fx_2[j] =L_shl(memory_fx2[2][j],sub(add(add(*Q_input_fx,6),Q_temp) ,memory_fx_Q[2])); +#ifdef BASOP_NOGLOB + memory2_fx_2[j] = L_shl_sat( memory_fx2[2][j], sub( add( add( *Q_input_fx, 6 ), Q_temp ), memory_fx_Q[2] ) ); + memory2_fx_3[j] =L_shl_sat(memory_fx2[3][j],sub(add(add(*Q_input_fx,1) ,Q_temp) ,memory_fx_Q[3])); +#else + memory2_fx_2[j] = L_shl( memory_fx2[2][j], sub( add( add( *Q_input_fx, 6 ), Q_temp ), memory_fx_Q[2] ) ); memory2_fx_3[j] =L_shl(memory_fx2[3][j],sub(add(add(*Q_input_fx,1) ,Q_temp) ,memory_fx_Q[3])); +#endif } - L_tmpX = L_shr(Mult_32_16(memory2_fx_2[0],full_band_bpf_fx[2][4]),3);/* *Q_input_fx+6 +Q_temp +13 -15 -3 */ +#ifdef BASOP_NOGLOB + L_tmpX = L_shr( Mult_32_16( memory2_fx_2[0], full_band_bpf_fx[2][4] ), 3 ); /* *Q_input_fx+6 +Q_temp +13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[1], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[2], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[3], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[2], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[1], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + L_output[0] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[0], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2 */ + move32(); + L_tmpMax = L_abs(L_output[0]); + + L_tmpX = L_shr(Mult_32_16(memory2_fx_2[1],full_band_bpf_fx[2][4]),3);/*Q_input_fx + 6 +Q_temp +13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[2], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[3], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[1], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx+Q_temp + 6 +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[0], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[2], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + L_output[1] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[1], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +13 -15 + 2+Q_temp*/ + move32(); + L_tmpMax = L_max(L_tmpMax,L_abs(L_output[1])); + + L_tmpX = L_shr(Mult_32_16(memory2_fx_2[2],full_band_bpf_fx[2][4]),3);/*Q_input_fx + 6 +Q_temp+13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( memory2_fx_2[3], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp+ 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[1], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp + 6 +13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[2], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx +Q_temp + 6 +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[1], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[0], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1+Q_temp +13 -15 + 2*/ + L_output[2] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[2], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + move32(); + L_tmpMax = L_max(L_tmpMax,L_abs(L_output[2])); + + L_tmpX = L_shr(Mult_32_16(memory2_fx_2[3],full_band_bpf_fx[2][4]),3);/*Q_input_fx + 6 +Q_temp +13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[0], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[1], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[2], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[3], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[2], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[1], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[0], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_output[3] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( memory2_fx_3[3], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + move32(); + L_tmpMax = L_max(L_tmpMax,L_abs(L_output[3])); + + FOR( i=4; i 0) r = L_shr(r, 2); tmp = shl(x[j], s); - r = L_mac0(r, tmp, tmp); +#ifdef BASOP_NOGLOB + r = L_mac0_sat( r, tmp, tmp ); +#else + r = L_mac0( r, tmp, tmp ); +#endif } r = L_max(r, L_shl(100, shl(s, 1))); r = Mpy_32_16_1(r, 16386/*1.0001f Q14*/); diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 3f0d0887cdff197b9cdb1202423a84068c595ff5..4501fa27348eb2f42b4f9f6e28cac3d47a940569 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -393,11 +393,17 @@ void tcx_windowing_synthesis_current_frame( tmp2 = mult_r(signal[i+overlap-acelp_mem_len], window_trans[i].v.im); /*Time TDAC: 1)forward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-tmp+i], mult_r(window_trans[i].v.re, window_trans[i].v.re))); +#ifdef BASOP_NOGLOB + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); /*Time TDAC: 1)reward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); + tmp2 = add_sat(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); +#else + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[i].v.re, window_trans[i].v.re ) ) ); + /*Time TDAC: 1)reward part of ACELP*/ + tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[i].v.im, window_trans[i].v.re))); +#endif move16(); signal[i+overlap-acelp_mem_len] = tmp2; } @@ -408,11 +414,17 @@ void tcx_windowing_synthesis_current_frame( tmp2 = mult_r(signal[i+overlap-acelp_mem_len], window_trans[tmp-1-i].v.re); /*Time TDAC: 1)forward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-tmp+i], mult_r(window_trans[tmp-1-i].v.im, window_trans[tmp-1-i].v.im))); - +#ifdef BASOP_NOGLOB + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); +#else + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - tmp + i], mult_r( window_trans[tmp - 1 - i].v.im, window_trans[tmp - 1 - i].v.im ) ) ); +#endif /*Time TDAC: 1)reward part of ACELP*/ - tmp2 = add(tmp2, mult_r(old_syn[acelp_zir_len-i-1], mult_r(window_trans[tmp-1-i].v.re, window_trans[tmp-1-i].v.im))); - +#ifdef BASOP_NOGLOB + tmp2 = add_sat( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); +#else + tmp2 = add( tmp2, mult_r( old_syn[acelp_zir_len - i - 1], mult_r( window_trans[tmp - 1 - i].v.re, window_trans[tmp - 1 - i].v.im ) ) ); +#endif move16(); signal[i+overlap-acelp_mem_len] = tmp2; } @@ -420,7 +432,11 @@ void tcx_windowing_synthesis_current_frame( FOR (i=0; i= 0; j-- ) +#ifdef BASOP_NOGLOB + Lacc = L_mac_sat( Lacc, buf[j], b[j + 1] ); + Lacc = L_mac_sat( Lacc, s_mem, b[0] ); +#else Lacc = L_mac( Lacc, buf[j], b[j + 1] ); Lacc = L_mac( Lacc, s_mem, b[0] ); +#endif /* Lacc in Q(1+Qc+Qn-Qa)*/ FOR ( j = s_max(PDR, PNR ) - 1; j > 0; j-- ) @@ -2455,8 +2460,11 @@ void pz_filter_dp_fx ( FOR ( j = PDR - 1; j >= 0; j-- ) Lacc = Msub_32_16( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ - s_mem = L_shl( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ - +#ifdef BASOP_NOGLOB + s_mem = L_shl_sat( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ +#else + s_mem = L_shl( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ +#endif Lacc = L_deposit_l(0); FOR ( j = PNR - 1; j >= 0; j-- ) Lacc = Madd_32_16( Lacc, buf[j], b[j + 1] ); @@ -2472,7 +2480,11 @@ void pz_filter_dp_fx ( buf[0] = s_mem; move16(); - Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ +#ifdef BASOP_NOGLOB + Ltemp1 = L_shr_sat( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ +#else + Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ +#endif y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ } } @@ -2495,16 +2507,26 @@ void Copy_Scale_sig32_16( { FOR (i = 0; i < len; i++ ) { - *dst++ = round_fx(*src++); +#ifdef BASOP_NOGLOB + *dst++ = round_fx_sat( *src++ ); +#else + *dst++ = round_fx( *src++ ); +#endif } return; } FOR (i = 0; i < len; i++ ) { - L_temp = L_shl(*src++, exp0); +#ifdef BASOP_NOGLOB + L_temp = L_shl_sat( *src++, exp0 ); + + *dst++ = round_fx_sat(L_temp); +#else + L_temp = L_shl( *src++, exp0 ); *dst++ = round_fx(L_temp); +#endif } } diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index 67fc70bfe032df382daa8cb4dfcfbd6d15c6971f..6404b84340067cd181aac3ff6bbf869f05404931 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -147,12 +147,20 @@ void preecho_sb_fx( fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; FOR( i = 0; i < len3xLp20; i++ ) { - *fxptr1++ = negate(extract_h(L_shl(*fx32ptr1--,15-q_sig32))); +#ifdef BASOP_NOGLOB + *fxptr1++ = negate( extract_h( L_shl_sat( *fx32ptr1--, 15 - q_sig32 ) ) ); +#else + *fxptr1++ = negate( extract_h( L_shl( *fx32ptr1--, 15 - q_sig32 ) ) ); +#endif move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ } FOR( i = 0; i < L_shr(framelength, 1); i++ ) { - *fxptr1++ = negate(extract_h(L_shl(wtda_audio_fx[i], 15-q_sig32))); +#ifdef BASOP_NOGLOB + *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], 15 - q_sig32 ) ) ); +#else + *fxptr1++ = negate( extract_h( L_shl( wtda_audio_fx[i], 15 - q_sig32 ) ) ); +#endif move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ } qmemp1 = 0; /*already in q-1*/ @@ -253,11 +261,15 @@ void preecho_sb_fx( FOR (j = 0; j < NUMSF; j++) /* 8 present subframes */ { tmp_fx2 = sub(j, 1); - tmp_fx1 = shr(*fxptr2, q16p1); /*q-1 to avoisd saturation in energy*/ +#ifdef BASOP_NOGLOB + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat(25, tmp_fx1, tmp_fx1); + tmp_fxL2 = L_mac0_sat(100, *fxptr3, *fxptr3); +#else + tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ tmp_fxL1 = L_mac0(25, tmp_fx1, tmp_fx1); - tmp_fxL2 = L_mac0(100, *fxptr3, *fxptr3); - +#endif sptr2_loc = 0; move16(); @@ -277,12 +289,13 @@ void preecho_sb_fx( *fx32ptr6 = tmp_fxL1; move32(); } - tmp_fx1 = shr(*fxptr2, q16p1); /*q-1 to avoisd saturation in energy*/ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac0_sat(tmp_fxL1, tmp_fx1, tmp_fx1); + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); tmp_fxL2 = L_mac0_sat(tmp_fxL2, *fxptr3, *fxptr3); #else - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); + tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); tmp_fxL2 = L_mac0(tmp_fxL2, *fxptr3, *fxptr3); #endif cntnzcr = add(cntnzcr, 1); diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 9dd61d2da431e81148a0fb80817c320505480e7c..d6386fa05fc9bb68a46458f19fa8a314f9455742 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -442,11 +442,18 @@ Word16 DTFS_alignment_full_fx( /* Calculating the expected alignment shift */ Eshift = mult_r(ph_offset_fx, shl(X2_DTFS_fx.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */ find_rem((Word16)L_FRAME, shr(add(X2_DTFS_fx.lag_fx, X1_DTFS_fx.lag_fx), 1), &temp); - temp = add(shl(temp, 7), Eshift); /* Q7 */ - +#ifdef BASOP_NOGLOB + temp = add_sat( shl( temp, 7 ), Eshift ); /* Q7 */ +#else + temp = add( shl( temp, 7 ), Eshift ); /* Q7 */ +#endif IF (temp<0) { - temp = add(temp, shl(X1_DTFS_fx.lag_fx, 7)); /* Q7 */ +#ifdef BASOP_NOGLOB + temp = add_sat( temp, shl_sat( X1_DTFS_fx.lag_fx, 7 ) ); /* Q7 */ +#else + temp = add( temp, shl( X1_DTFS_fx.lag_fx, 7 ) ); /* Q7 */ +#endif } find_rem(temp, shl(X1_DTFS_fx.lag_fx, 7), &Eshift); /* Q7 */ Eshift=shl(shr(Eshift,7),1); /* Q1 but integer */ @@ -1217,7 +1224,11 @@ static void DTFS_transform_fx( tmptmp3_40_fx=L_add(tmptmp3_40_fx, Mult_32_16(x_r_fx[m],sinc_fx[k][j])); } - out_fx[i] = round_fx(L_shl(tmptmp3_40_fx,2)); +#ifdef BASOP_NOGLOB + out_fx[i] = round_fx_sat( L_shl_sat( tmptmp3_40_fx, 2 ) ); +#else + out_fx[i] = round_fx( L_shl( tmptmp3_40_fx, 2 ) ); +#endif } @@ -1765,7 +1776,11 @@ static Word32 DTFS_setEngy_fx( expb = norm_l(en1_fx); - fracb = round_fx(L_shl(en1_fx,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( en1_fx, expb ) ); +#else + fracb = round_fx( L_shl( en1_fx, expb ) ); +#endif expb = sub(30, add(expb, shl(X_DTFS_FX->Q, 1))); @@ -2560,9 +2575,15 @@ void DTFS_to_erb_fx( tmp = div_s(fracb,fraca); exp = sub(expb,expa); - L_tmp = L_shl(tmp, add(exp,14)); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( tmp, add( exp, 14 ) ); + + out_fx[i] = round_fx_sat(L_tmp); +#else + L_tmp = L_shl( tmp, add( exp, 14 ) ); out_fx[i] = round_fx(L_tmp); +#endif } } return; @@ -3381,7 +3402,11 @@ Word16 ppp_extract_pitch_period_fx( spike=i; move16(); } - en1 =L_mac0(en1, ptr[i], ptr[i]); /* Q0 */ +#ifdef BASOP_NOGLOB + en1 = L_mac0_sat( en1, ptr[i], ptr[i] ); /* Q0 */ +#else + en1 = L_mac0( en1, ptr[i], ptr[i] ); /* Q0 */ +#endif } IF (ptr[spike]>0) @@ -3508,7 +3533,11 @@ Word16 ppp_extract_pitch_period_fx( Lacc = L_deposit_l(0); FOR (i=0; i= 0) { if (GT_32(L_temp,maxPosEn_fx)) @@ -3980,7 +4016,17 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 tmp1 = round_fx(ftmp_real_fx); tmp2 = round_fx(ftmp_imag_fx); - *(farray_ptr_fx + kj) = sub(*(farray_ptr_fx + k), tmp1); +#ifdef BASOP_NOGLOB + *( farray_ptr_fx + kj ) = sub_sat( *( farray_ptr_fx + k ), tmp1 ); + move16(); + *(farray_ptr_fx + kj + 1) = sub_sat(*(farray_ptr_fx + k + 1), tmp2); + move16(); + *(farray_ptr_fx + k) = add_sat(*(farray_ptr_fx + k), tmp1); + move16(); + *(farray_ptr_fx + k + 1) = add_sat(*(farray_ptr_fx + k + 1), tmp2); + move16(); +#else + *( farray_ptr_fx + kj ) = sub( *( farray_ptr_fx + k ), tmp1 ); move16(); *(farray_ptr_fx + kj + 1) = sub(*(farray_ptr_fx + k + 1), tmp2); move16(); @@ -3988,6 +4034,7 @@ static void c_fft_wi_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word1 move16(); *(farray_ptr_fx + k + 1) = add(*(farray_ptr_fx + k + 1), tmp2); move16(); +#endif } } } diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index c0171dbb328ac702c1d087d998a9a27078b682e6..8af07df1c38f0b9fc50155616d43675b767948f3 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -29,7 +29,11 @@ void sinq_fx( tmp2 = round_fx(L_tmp); /*Q15 */ x[1] = sub(tmp1, tmp2); move16(); /* sin(x) approximated by (x-x^3/3!); Q15 */ - tmp1 = add(shl(tmp,1), phi); /*Q15 */ +#ifdef BASOP_NOGLOB + tmp1 = add_sat( shl_sat( tmp, 1 ), phi ); /*Q15 */ +#else + tmp1 = add( shl( tmp, 1 ), phi ); /*Q15 */ +#endif L_tmp = L_mult(tmp1, tmp1); /*Q31 */ L_tmp = Mult_32_16(L_tmp, tmp1); /*Q31 */ L_tmp = Mult_32_16(L_tmp, 5461); /*Q31; division by 6 */ @@ -857,9 +861,15 @@ void core_switching_OLA_fx( temp_len = i_mult2(shr(R2_16,2), delta); FOR( i=0 ; i Q15 */ - *pt2 = shl( mult_r(*pt2,*pt4),1); +#ifdef BASOP_NOGLOB + *pt = shl_sat( mult_r_sat( *pt, *pt5 ), 1 ); + move16(); /* // Q14* Q15 + shl ==> Q15 */ + *pt2 = shl_sat( mult_r_sat( *pt2, *pt4 ), 1 ); +#else + *pt = shl( mult_r( *pt, *pt5 ), 1 ); + move16(); /* // Q14* Q15 + shl ==> Q15 */ + *pt2 = shl( mult_r( *pt2, *pt4 ), 1 ); +#endif move16();/*/= win[(3*L_FRAME16k/2-1-i/2)*decimate+decay-L_FRAME48k*14/20]; */ pt+=2; pt2+=2; @@ -929,7 +939,11 @@ void core_switching_OLA_fx( temp_len = sub(L,tmp); FOR( i=0; i< temp_len; i++ ) { - *pt = add(add(*pt,*pt2++),*pt3++); +#ifdef BASOP_NOGLOB + *pt = add_sat( add_sat( *pt, *pt2++ ), *pt3++ ); +#else + *pt = add( add( *pt, *pt2++ ), *pt3++ ); +#endif move16(); pt++; } diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 7d21bf4bb6b349e83af15a83ec2f66877523f9e2..645bc43137e6c70578f875b4a43a7fbce1963a04 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -359,8 +359,11 @@ void HQ_FEC_processing_fx( exp2 = norm_l(norm_values_fx[0]); tmp_fx = div_s(extract_h(L_shl(norm_p_fx[i], exp1)), extract_h(L_shl(norm_values_fx[0], exp2)));/*15 + (5 + exp1 - 16) - (12 + exp2 - 16)*/ - tmp_fx = shl(tmp_fx, add(6, sub(exp2, exp1)));/*14*/ - +#ifdef BASOP_NOGLOB + tmp_fx = shl_sat( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ +#else + tmp_fx = shl( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ +#endif if (GT_16(tmp_fx, 16384)) { tmp_fx = 16384; @@ -830,7 +833,11 @@ void HQ_FEC_Mem_update_fx( move16();/*15*/ L_tmp = Mult_32_16(tmp_energy_fx, tmp_fx);/*8 + 15 - 15*/ - hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h(L_shl(L_tmp, 16-8)); +#ifdef BASOP_NOGLOB + hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl_sat( L_tmp, 16 - 8 ) ); +#else + hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl( L_tmp, 16 - 8 ) ); +#endif /* Moving Average */ hHQ_nbfec->energy_MA_Curr_fx[0] = s_max(1,add(mult_r(26214, hHQ_nbfec->energy_MA_Curr_fx[0]), mult_r(6554, hHQ_nbfec->energy_MA_Curr_fx[1]))); @@ -1535,7 +1542,11 @@ static void Repetition_smoothing_nextgood_fx( /*mvr2r(&ImdctOutWin[L], OldauOut, L);*/ FOR (i = 0; i < L; i++) { - auOut_fx[i] = add(ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i]); +#ifdef BASOP_NOGLOB + auOut_fx[i] = add_sat( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); +#else + auOut_fx[i] = add( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); +#endif move16(); } Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); @@ -1626,7 +1637,11 @@ static void common_overlapping_fx( FOR (i=0 ; i < end1; i++) { /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ - auOut_fx[i] = add(ImdctOutWin_fx[i+N_ZERO_NB], OldauOut_fx[i+offset1]); +#ifdef BASOP_NOGLOB + auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); +#else + auOut_fx[i] = add( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); +#endif move16(); } FOR (i=start2 ; i < end2; i++) diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 08c2955f2c0bd2585a398ae4032837aa9adfc16d..f7c581b4f1ce3c873f1754b3fac49b840d5f0bc0 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -549,14 +549,22 @@ static void trans_ana_fx( tr_dec[k] = 0; move16(); Mpy_32_16_ss(*pGrPowLeft, THRESH_TR_LIN_BY2_FX, &acc, &lsb); /* To facilitate fixed-point implementation, divide threshold by 2. */ - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#ifdef BASOP_NOGLOB + acc = L_or( L_shl_sat( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#else + acc = L_or( L_shl( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#endif if (GT_32(*pGrPowRight, acc)) /* gr_pow_right > thres_tr_lin*gr_pow_left */ { tr_dec[k] = 1; move16(); } Mpy_32_16_ss(*pGrPowRight, THRESH_TR_LIN_BY2_FX, &acc, &lsb); - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#ifdef BASOP_NOGLOB + acc = L_or( L_shl_sat( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#else + acc = L_or( L_shl( acc, 16 ), L_and( 0xffffL, lsb ) ); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ +#endif if (GT_32(*pGrPowLeft, acc)) /* gr_pow_left > thres_tr_lin*gr_pow_right */ { tr_dec[k] = 1; @@ -1885,7 +1893,11 @@ static void spec_ana_fx( man = mult_r(man,FEC_HQ_ECU_ROOT2); /* FEC_HQ_ECU_ROOT2 is sqrt(2) in Q14 */ expoBy2 = sub(expoBy2, 1); } - *pXfp++ = shr(man, expoBy2); +#ifdef BASOP_NOGLOB + *pXfp++ = shr_sat( man, expoBy2 ); +#else + *pXfp++ = shr( man, expoBy2 ); +#endif move16();/* Denormalize the mantissa back to Q0. */ } } @@ -2763,8 +2775,13 @@ static void subst_spec_fx( IF(EQ_16(element_mode, EVS_MONO)) #endif { - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); +#ifdef BASOP_NOGLOB + tmp = sub_sat( mult_r( re, cos_F ), mult_r( im, sin_F ) ); + im = add_sat(mult_r(re, sin_F), mult_r(im, cos_F)); +#else + tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); im = add(mult_r(re, sin_F), mult_r(im, cos_F)); +#endif } #ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE @@ -3705,8 +3722,11 @@ Word16 abs_iter_fx(Word16 re, Word16 im, Word16 N) i = s_min(sub(i,1), 9); tmp = abs_s(re); /*A = round_fx(L_shr(L_mult(tmp, cor[i]), exp)); //this can be ommited, if we don't need the exact abs value */ - A = shr(tmp, exp); - +#ifdef BASOP_NOGLOB + A = shr_sat( tmp, exp ); +#else + A = shr( tmp, exp ); +#endif return A; } /*-------------------------------------------------------------------------- @@ -3967,7 +3987,11 @@ void singenerator_fx( ptr = xx; - *ptr = L_add(*ptr, L_C0); +#ifdef BASOP_NOGLOB + *ptr = L_add_sat( *ptr, L_C0 ); +#else + *ptr = L_add( *ptr, L_C0 ); +#endif move32(); ptr++; @@ -3978,7 +4002,11 @@ void singenerator_fx( L_C1 = L_msu(L_C1, S0, sinfreq); /*Qin+16 */ L_S1 = L_mult(C0, sinfreq); S1 = mac_r(L_S1, S0, cosfreq); - *ptr = L_add(*ptr, L_C1); +#ifdef BASOP_NOGLOB + *ptr = L_add_sat( *ptr, L_C1 ); +#else + *ptr = L_add( *ptr, L_C1 ); +#endif move32(); /*Qin+16 */ ptr++; @@ -3987,7 +4015,11 @@ void singenerator_fx( L_C0 = L_msu(L_C0, S1, sinfreq); L_S0 = L_mult(C1, sinfreq); S0 = mac_r(L_S0, S1, cosfreq); - *ptr = L_add(*ptr, L_C0); +#ifdef BASOP_NOGLOB + *ptr = L_add_sat( *ptr, L_C0 ); +#else + *ptr = L_add( *ptr, L_C0 ); +#endif move32(); ptr++; } @@ -3996,7 +4028,11 @@ void singenerator_fx( S0 = extract_h(L_S0); L_C1 = L_mult(C0, cosfreq); L_C1 = L_msu(L_C1, S0, sinfreq); - *ptr = L_add(*ptr, L_C1); +#ifdef BASOP_NOGLOB + *ptr = L_add_sat( *ptr, L_C1 ); +#else + *ptr = L_add( *ptr, L_C1 ); +#endif move32(); ptr++; @@ -4508,7 +4544,11 @@ void fec_noise_filling_fx( tmp_fx = div_s(1, Rnd_N_noise); /*Q15 */ - tmp_fx = round_fx(L_shl(L_mult(tmp_fx, 25736),2)); /*Q15 */ +#ifdef BASOP_NOGLOB + tmp_fx = round_fx_sat( L_shl_sat( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ +#else + tmp_fx = round_fx( L_shl( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ +#endif #ifdef IVAS_FEC_ECU_TO_COMPLETE if (element_mode == EVS_MONO) { diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index 47a0e307a505b84ebad73634bd3f8d2e15e4f00a..b0648eb8508b18710eae7055793a74bda80af842 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -353,7 +353,11 @@ void FEC_clas_estim_fx( tmp_x = extract_h(L_shl(Ltmp, exp2)); exp2 = sub(31-1+3, exp2); BASOP_SATURATE_WARNING_OFF_EVS - tmpS = shr(sub(tmp_x, tmp_y), 16); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ +#ifdef BASOP_NOGLOB + tmpS = shr( sub_sat( tmp_x, tmp_y ), 16 ); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ +#else + tmpS = shr( sub( tmp_x, tmp_y ), 16 ); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ +#endif BASOP_SATURATE_WARNING_ON_EVS tmp_y = shl(tmp_y, tmpS); exp1 = sub(exp1, tmpS); diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 2c608b2545ae70c3993ce34e862b3e130f8b3778..897864e495a38f56d7d7b15b81b6980a5d6fd322 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -655,7 +655,11 @@ void FEC_exc_estim_fx( /* non-causal ringing of the FIR filter */ /**pt_exc++ *= (gain_inov * gain);*/ L_tmp = L_mult(tmp, *pt_exc); /* Q_exc+18 * Q-3 -> Q_exc+16 */ - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); +#ifdef BASOP_NOGLOB + *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); +#else + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); +#endif } FOR( i=0; i< L_frame; i++ ) @@ -663,7 +667,11 @@ void FEC_exc_estim_fx( /* the inner part of the FIR filter */ /* *pt_exc++ *= (gain_inov * gain); */ L_tmp = L_mult(tmp, *pt_exc); - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); +#ifdef BASOP_NOGLOB + *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); +#else + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); +#endif /* gain -= step; */ L_tmp2 = L_sub(L_tmp2, L_step); tmp = round_fx(L_tmp2); @@ -674,7 +682,11 @@ void FEC_exc_estim_fx( { /* *pt_exc++ *= (gain_inov * gain) */ L_tmp = L_mult(tmp, *pt_exc); - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); +#ifdef BASOP_NOGLOB + *pt_exc++ = round_fx_sat( L_shl_sat( L_tmp, exp ) ); +#else + *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); +#endif } } @@ -711,9 +723,17 @@ void FEC_exc_estim_fx( L_tmp = L_mult(hp_filt[0], pt_exc[0]); FOR (j = 1; j < MODE1_L_FIR_FER; j++) { - L_tmp = L_mac(L_tmp, hp_filt[j], pt_exc[j]); +#ifdef BASOP_NOGLOB + L_tmp = L_mac_sat( L_tmp, hp_filt[j], pt_exc[j] ); +#else + L_tmp = L_mac( L_tmp, hp_filt[j], pt_exc[j] ); +#endif } - exc2[i] = msu_r(L_tmp, -32768, exc[i]); +#ifdef BASOP_NOGLOB + exc2[i] = msu_r_sat( L_tmp, -32768, exc[i] ); +#else + exc2[i] = msu_r( L_tmp, -32768, exc[i] ); +#endif move16(); pt_exc++; } @@ -802,7 +822,11 @@ static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 tmp_pit2 = L_mult(Tc,4915/*0.15f Q15*/);/*Q16*/ BASOP_SATURATE_WARNING_OFF_EVS /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ - tmp_pit2 = L_shl(L_negate(tmp_pit2),sub(15-16,tmp_pit_e)); +#ifdef BASOP_NOGLOB + tmp_pit2 = L_shl_sat( L_negate( tmp_pit2 ), sub( 15 - 16, tmp_pit_e ) ); +#else + tmp_pit2 = L_shl( L_negate( tmp_pit2 ), sub( 15 - 16, tmp_pit_e ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS *cond3 = L_sub(L_mult0(-1, tmp_pit),tmp_pit2); } diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 0502417be40df622af42964771c72bc29829c5dd..8e65665f17e6136983676db45ea821c51ed89cd7 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -257,7 +257,11 @@ void FEC_scale_syn_fx( ( (prev_bfi) || ( (EQ_16(coder_type,GENERIC) ) && (EQ_16(LSF_Q_prediction,AUTO_REGRESSIVE) ) ) ) ) { /*if( enr_q > scaling * enr_old ){enr_q = scaling * enr_old;}*/ - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ +#ifdef BASOP_NOGLOB + L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#else + L_enr_q = L_min( L_enr_q, L_shl( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#endif } ELSE { @@ -351,7 +355,11 @@ void FEC_scale_syn_fx( exc[i] = mac_r(L_mult(exc[i], gain1), exc[i], gain1); move16(); /*exc2[i] *= gain1;*/ - exc2[i] = mac_r(L_mult(exc2[i], gain1), exc2[i], gain1); +#ifdef BASOP_NOGLOB + exc2[i] = mac_r_sat( L_mult( exc2[i], gain1 ), exc2[i], gain1 ); +#else + exc2[i] = mac_r( L_mult( exc2[i], gain1 ), exc2[i], gain1 ); +#endif move16(); } /* smoothing is done in excitation domain, so redo synthesis */ @@ -398,7 +406,11 @@ void FEC_scale_syn_fx( ( (EQ_16(clas,UNVOICED_CLAS))||(EQ_16(clas,INACTIVE_CLAS))))) /* unvoiced classification */ { /*if( enr_q > scaling * enr_old )enr_q = scaling * enr_old;*/ - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ +#ifdef BASOP_NOGLOB + L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#else + L_enr_q = L_min( L_enr_q, L_shl( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ +#endif } ELSE IF( GE_16(last_good,VOICED_TRANSITION)&<_16(last_good,INACTIVE_CLAS)&&GE_16(clas,VOICED_TRANSITION)&<_16(clas,INACTIVE_CLAS)) { @@ -594,9 +606,15 @@ void FEC_scale_syn_fx( FOR( i=0; ifilt_lfE_fx[i]); tmp16 = s_max(min_g_2k, tmp16); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); - +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } FOR(; i < BIN_4KHZ; i++) @@ -344,7 +347,11 @@ void LD_music_post_filter_fx tmp16 = s_min(max_ovf_4k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_4k, tmp16); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } test(); @@ -356,7 +363,11 @@ void LD_music_post_filter_fx tmp16 = s_min(max_ovf_6k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_6k, tmp16); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } } } @@ -367,7 +378,11 @@ void LD_music_post_filter_fx { tmp16 = s_min(4096, hMusicPF->filt_lfE_fx[i]); /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); +#ifdef BASOP_NOGLOB + dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); +#else + dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); +#endif } } } @@ -743,7 +758,11 @@ static void find_enr_dct_fx( FOR( i = min_band; i <= NB_LIMIT_BAND; i++ ) { /* total channel energy */ - Ltmp = L_add(band[i],Ltmp); +#ifdef BASOP_NOGLOB + Ltmp = L_add_sat( band[i], Ltmp ); +#else + Ltmp = L_add( band[i], Ltmp ); +#endif } *Etot = Ltmp; diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 4df7086399ead01a277b68e18640e6f4b3d03091..9273bcbb3e5e8c2b6a2d938ed99dc1a42233759b 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -327,7 +327,11 @@ ivas_error acelp_core_switch_dec_fx( pt2 = &hb_synth_tmp[tmp]; FOR( i=0; ilp_ener_fx; */ IF(EQ_16(m1,1)) { - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#endif } ELSE { tmp1 = div_s(1,m1); L_tmp = Mult_32_16(L_tmp,tmp1); - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); +#endif } env[i] = L_tmp; move32(); @@ -581,7 +593,11 @@ void CNG_dec_fx( { /* Update hangover memory during CNG */ test(); - IF ( *allow_cn_step == 0 && LT_32(hTdCngDec->Enew_fx,L_add(st_fx->lp_ener_fx,L_shr(st_fx->lp_ener_fx,1)))) +#ifdef BASOP_NOGLOB + IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#else + IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) +#endif { /* update the pointer to circular buffer of old LSP vectors */ hTdCngDec->ho_hist_ptr_fx = add(hTdCngDec->ho_hist_ptr_fx, 1); @@ -964,7 +980,11 @@ static void shb_CNG_decod_fx( IF ( st_fx->trans_cnt_fx > 0 ) { i = extract_l(L_mult0(st_fx->trans_cnt_fx, 17)); /*Q0 */ - ener_fx = add(st_fx->shb_cng_ener_fx, mult(sin_table256_fx[i], sub(st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx))); /*Q8 */ +#ifdef BASOP_NOGLOB + ener_fx = add_sat( st_fx->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx ) ) ); /*Q8 */ +#else + ener_fx = add( st_fx->shb_cng_ener_fx, mult( sin_table256_fx[i], sub( st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx ) ) ); /*Q8 */ +#endif st_fx->trans_cnt_fx = sub(st_fx->trans_cnt_fx, 1); } @@ -978,7 +998,11 @@ static void shb_CNG_decod_fx( move32(); } fra = L_Extract_lc(L_tmp, &exp); - L_tmp = L_shl(Pow2(exp, fra), 5); /*Q5 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( Pow2( exp, fra ), 5 ); /*Q5 */ +#else + L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ +#endif L_tmp = L_shr(L_tmp, 10); if( L_tmp == 0 ) { diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index ce1f1b908f857a5eab38d4f2656651d392169796..e35f52d3972fe7780e0143c1f52e268b8b39f66c 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -198,7 +198,11 @@ static void gain_dec_uv( *-----------------------------------------------------------------*/ *past_gpit = *gain_pit; *past_gcode = L_tmp; - L_tmp = L_shl(Mpy_32_16_1(L_tmp, *gain_inov), 3); /* Q16*Q12 -> Q13 -> Q16 */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( Mpy_32_16_1( L_tmp, *gain_inov ), 3 ); /* Q16*Q12 -> Q13 -> Q16 */ +#else + L_tmp = L_shl( Mpy_32_16_1( L_tmp, *gain_inov ), 3 ); /* Q16*Q12 -> Q13 -> Q16 */ +#endif *gain_code = L_tmp; move32(); @@ -304,7 +308,11 @@ static void gain_dec_gacelp_uv( *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32(); - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#else + *gain_code = L_shl( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#endif move32(); diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 110e09167756d597acbaa6cb1f697eff529259b1..fc5d1168c1f20c3369561e0af62405873378a729 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -463,15 +463,26 @@ void decoder_acelp( Ltmp = Mpy_32_16_1(gain_code2, code2[i]); Ltmp = L_shl(Ltmp, add(5,st->Q_exc)); Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); - exc2[i + i_subfr] = round_fx(L_shl(Ltmp, 1)); - +#ifdef BASOP_NOGLOB + exc2[i + i_subfr] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); +#else + exc2[i + i_subfr] = round_fx( L_shl( Ltmp, 1 ) ); +#endif Ltmp2 = Mpy_32_16_1(gain_code, code[i]); Ltmp2 = L_shl(Ltmp2, add(5,st->Q_exc)); Ltmp = L_add(Ltmp, Ltmp2); BASOP_SATURATE_WARNING_OFF_EVS - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ +#else + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ +#endif BASOP_SATURATE_WARNING_ON_EVS - exc[i + i_subfr] = round_fx(Ltmp); +#ifdef BASOP_NOGLOB + exc[i + i_subfr] = round_fx_sat( Ltmp ); +#else + exc[i + i_subfr] = round_fx( Ltmp ); +#endif } tmp2 = L_SUBFR; move16(); diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 489aba7984f09f561d949459348b9307572a76ef..ee1739c8c1e93a3a7e49af1071de0f1441252239 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -251,16 +251,28 @@ ivas_error decod_gen_voic_fx( Ltmp1 = L_shl(Ltmp1,tmp1_fx); /* Q16 + Q_exc */ /* Compute exc2 */ - L_tmp = L_shl(L_mult(gain_pit_fx,exc_fx[i+i_subfr_fx]),1); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); + exc2_fx[i+i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); +#else + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); - +#endif /* code in Q9, gain_pit in Q14 */ L_tmp = L_mult(gain_code16, code_fx[i]); - L_tmp = L_shl(L_tmp, 5); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); + L_tmp = L_mac_sat(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); + L_tmp = L_shl_sat(L_tmp, 1); /* saturation can occur here */ + + exc_fx[i+i_subfr_fx] = round_fx_sat(L_add_sat(L_tmp, Ltmp1)); +#else + L_tmp = L_shl( L_tmp, 5 ); L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ exc_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); +#endif } } ELSE @@ -345,8 +357,13 @@ ivas_error decod_gen_voic_fx( curr_spch_nrg = L_deposit_l(1); FOR( i=0; iQ_exc */ +#ifdef BASOP_NOGLOB + curr_res_nrg = L_mac0_sat( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ + curr_spch_nrg = L_mac0_sat(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ +#else + curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ curr_spch_nrg = L_mac0(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ +#endif p_exc++; p_syn++; } @@ -359,7 +376,11 @@ ivas_error decod_gen_voic_fx( expa = sub(30,expa+(2*st_fx->prev_Q_exc_fr)); expb = norm_l(curr_res_nrg); - fracb = round_fx(L_shl(curr_res_nrg,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); +#else + fracb = round_fx( L_shl( curr_res_nrg, expb ) ); +#endif expb = sub(30,expb+(2*st_fx->Q_exc)); scale = shr(sub(fraca,fracb),15); @@ -384,7 +405,11 @@ ivas_error decod_gen_voic_fx( expa = sub(30,expa+(2*st_fx->prev_Q_syn_fr)); expb = norm_l(curr_spch_nrg); - fracb = round_fx(L_shl(curr_spch_nrg,expb)); +#ifdef BASOP_NOGLOB + fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); +#else + fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); +#endif expb = sub(30,expb+(2*st_fx->Q_syn)); scale = shr(sub(fraca,fracb),15); diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index de01c152b494697b457ec01c28db046bc4bf143b..941fbc3cffa56b75851c0607450e6c7114199113 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -81,8 +81,13 @@ void transf_cdbk_dec_fx( } L_tmp = Mult_32_16(gain_code,gain16); /* Q16 * Q12 - 15 -> Q13*/ - L_tmp = L_shl(L_tmp,5); /* Q13 -> Q18*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx_sat(L_tmp); /* Q2*/ +#else + L_tmp = L_shl( L_tmp, 5 ); /* Q13 -> Q18*/ *gain_preQ = round_fx(L_tmp); /* Q2*/ +#endif } ELSE { diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index b954820ac8cf3512b82b1de8bb1ae9e65d4011a9..8457c5596d27e59286164de4f016852817fab93b 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -262,8 +262,13 @@ void dec_pit_exc_fx( { FOR (i = 0; i < L_subfr_fx; i++) { - L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i+i_subfr_fx]), 1); /*Q16+Q_exc*/ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ +#else + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ +#endif } } ELSE @@ -273,7 +278,11 @@ void dec_pit_exc_fx( FOR (i = 0; i < L_subfr_fx; i++) { L_tmp = L_mult(gain_pitx2, exc_fx[i+i_subfr_fx]); /*Q16+Q_exc*/ - exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ +#ifdef BASOP_NOGLOB + exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ +#else + exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ +#endif } } } diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 80385bcfb96c9f214ff1c03e749ebe577c23a7b9..de4afc8c496ae1b3aaddaf2a418fb4932460ffdf 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -856,7 +856,11 @@ static void pst_ltp( FOR (i = 0; i < L_SUBFR; i++) { /* nb_sh_sig may be >0, <0 or =0 */ - ptr_y_up[i] = shl(ptr_y_up[i], nb_sh_sig); +#ifdef BASOP_NOGLOB + ptr_y_up[i] = shl_sat( ptr_y_up[i], nb_sh_sig ); +#else + ptr_y_up[i] = shl( ptr_y_up[i], nb_sh_sig ); +#endif move16(); } } @@ -1467,7 +1471,11 @@ static void compute_ltp_l( L_acc = L_mult(y_up[0], y_up[0]); FOR (n = 1; n < L_SUBFR; n++) { - L_acc = L_mac(L_acc, y_up[n], y_up[n]); +#ifdef BASOP_NOGLOB + L_acc = L_mac_sat( L_acc, y_up[n], y_up[n] ); +#else + L_acc = L_mac( L_acc, y_up[n], y_up[n] ); +#endif } temp = sub(16, norm_l(L_acc)); temp = s_max(temp, 0); @@ -1720,11 +1728,18 @@ void Filt_mu( L_temp = L_mac(L_acc, 16384, *ptrs); /* sig_in(n) * 2**15 */ L_temp = Madd_32_16(L_fact, L_temp, ga); - L_temp = L_shr(L_temp, sh_fact); /* mult. temp x ga */ - +#ifdef BASOP_NOGLOB + L_temp = L_shr_sat( L_temp, sh_fact ); /* mult. temp x ga */ +#else + L_temp = L_shr( L_temp, sh_fact ); /* mult. temp x ga */ +#endif BASOP_SATURATE_WARNING_OFF_EVS; /*sig_out[n] = saturate(L_temp); move16();*/ - sig_out[n] = round_fx(L_temp); +#ifdef BASOP_NOGLOB + sig_out[n] = round_fx_sat( L_temp ); +#else + sig_out[n] = round_fx( L_temp ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } @@ -1823,7 +1838,11 @@ void Filt_mu_fx( BASOP_SATURATE_WARNING_OFF_EVS; /*sig_out[n] = saturate(L_temp); move16();*/ - sig_out[n] = round_fx(L_temp); +#ifdef BASOP_NOGLOB + sig_out[n] = round_fx_sat( L_temp ); +#else + sig_out[n] = round_fx( L_temp ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index a5ff481b574b2d076094feb5f77c2e883b93fad5..6fdfdbb4c37e306590ee30b43372cd831254fcf5 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -574,7 +574,11 @@ void decoder_tcx( /* gainCompensate = st->last_gain_syn_deemph/(float)sqrt(dot_product( h1, h1, L_SUBFR)); */ tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gainCompensate_e)/*Q15, gainCompensate_e*/; gainCompensate_e = add(gainCompensate_e,10/*scaling of h1[0] and E_UTIL:synthesis*/); - gainCompensate = round_fx(Sqrt32(tmp32,&gainCompensate_e))/*Q15, gainCompensate_e*/; +#ifdef BASOP_NOGLOB + gainCompensate = round_fx_sat( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; +#else + gainCompensate = round_fx( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; +#endif BASOP_Util_Divide_MantExp ( st->last_gain_syn_deemph, st->last_gain_syn_deemph_e, gainCompensate, @@ -1491,7 +1495,11 @@ void decoder_tcx_post(Decoder_State *st_fx, #endif FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) { - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gainFB, synthFB[i]),1)); +#ifdef BASOP_NOGLOB + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) ); +#else + synthFB[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) ); +#endif move16(); #ifdef BASOP_NOGLOB conceal_eof_gainFB = L_sub_o(conceal_eof_gainFB, stepFB, &Overflow); @@ -1503,7 +1511,11 @@ void decoder_tcx_post(Decoder_State *st_fx, conceal_eof_gain32 = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ FOR( i=0; i < st_fx->L_frame; i++ ) { - xn_buf[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gain32 /*Q30*/, xn_buf[i]),1)); +#ifdef BASOP_NOGLOB + xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) ); +#else + xn_buf[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) ); +#endif move16(); #ifdef BASOP_NOGLOB conceal_eof_gain32 = L_sub_o(conceal_eof_gain32, step, &Overflow); @@ -2122,7 +2134,11 @@ void IMDCT(Word32 *x, Word16 x_e, tmp1 = sub(overlap, tcx_mdct_window_min_length); FOR (i=0; i < tmp1; i++) { - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], shr(old_out[i+nz], tmp2)), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], shr_sat( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], shr( old_out[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#endif move16(); } @@ -2131,19 +2147,31 @@ void IMDCT(Word32 *x, Word16 x_e, FOR ( ; i < tmp1; i++) { tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[i-overlap+tcx_mdct_window_min_length].v.re); - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR ( ; i < overlap; i++) { tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[overlap-1-i].v.im); - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp4] = shl_sat( add_sat( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp4] = shl( add( xn_buf[i + tmp4], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR (i = add(i, tmp4) ; i < L_frame; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } @@ -2176,26 +2204,43 @@ void IMDCT(Word32 *x, Word16 x_e, tmp3 = shr(tcx_mdct_window_half_length, 1); FOR (i=0; i < tmp1; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR (i = 0; i < tmp3; i++) { - tmp2 = add(xn_buf[i+tmp1], mult_r(old_syn_overl[i], tcx_mdct_window_half[i].v.re)); - xn_buf[i+tmp1] = shl(tmp2, TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + tmp2 = add_sat( xn_buf[i + tmp1], mult_r( old_syn_overl[i], tcx_mdct_window_half[i].v.re ) ); + xn_buf[i + tmp1] = shl_sat( tmp2, TCX_IMDCT_HEADROOM ); +#else + tmp2 = add( xn_buf[i + tmp1], mult_r( old_syn_overl[i], tcx_mdct_window_half[i].v.re ) ); + xn_buf[i + tmp1] = shl( tmp2, TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { tmp2 = add(xn_buf[i+tmp1], mult_r(old_syn_overl[i], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im)); - xn_buf[i+tmp1] = shl(tmp2, TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = shl_sat( tmp2, TCX_IMDCT_HEADROOM ); +#else + xn_buf[i + tmp1] = shl( tmp2, TCX_IMDCT_HEADROOM ); +#endif move16(); } IF (LT_16(add(i, tmp1), L_frame)) { FOR (i = add(i, tmp1); i < L_frame; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } @@ -2231,14 +2276,22 @@ void IMDCT(Word32 *x, Word16 x_e, tmp1 = shr(overlap, 1); FOR (i=0; i < tmp1; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } tmpP16 = xn_buf + tmp1; FOR (i=0; i < overlap; i++) { - tmpP16[i] = shl(add(tmpP16[i], old_syn_overl[i]), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + tmpP16[i] = shl_sat( add( tmpP16[i], old_syn_overl[i] ), TCX_IMDCT_HEADROOM ); +#else + tmpP16[i] = shl( add( tmpP16[i], old_syn_overl[i] ), TCX_IMDCT_HEADROOM ); +#endif move16(); } @@ -2246,7 +2299,11 @@ void IMDCT(Word32 *x, Word16 x_e, { FOR (i = add(i, tmp1); i < L_frame; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf[i] = shl_sat( xn_buf[i], TCX_IMDCT_HEADROOM ); +#else + xn_buf[i] = shl( xn_buf[i], TCX_IMDCT_HEADROOM ); +#endif move16(); } } @@ -2336,14 +2393,24 @@ void IMDCT(Word32 *x, Word16 x_e, tmp3 = shr(tcx_mdct_window_half_length, 1); FOR (i = 0; i < tmp3; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); + xn_buf[i+tmp1] = add_sat( xn_buf[i+tmp1], mult_r_sat(hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#endif move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i+tmp1] = add_sat( xn_buf[i+tmp1], mult_r_sat(hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); +#endif move16(); } } @@ -2353,14 +2420,24 @@ void IMDCT(Word32 *x, Word16 x_e, tmp3 = shr(tcx_mdct_window_half_length, 1); FOR (i = 0; i < tmp3; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[i].v.im ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); +#endif move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); +#ifdef BASOP_NOGLOB + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); +#else + xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); +#endif move16(); } } diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index b51e8268d7c4d48264cbf8463b28eabd62567652..4135eb0665c5eeb01bd3efc3cf1ff07cc152844f 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -205,7 +205,11 @@ void con_acelp( Tc = round_fx(tmp_tc); BASOP_SATURATE_WARNING_OFF_EVS /*if this ever saturates, it doesn't matter*/ - tmp = sub(shl(abs_s(sub(T0,Tc)),6) , mult(19661/*0.15f Q17*/,shl(Tc,4)) /*Q6*/); +#ifdef BASOP_NOGLOB + tmp = sub( shl_sat( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl_sat( Tc, 4 ) ) /*Q6*/ ); +#else + tmp = sub( shl( abs_s( sub( T0, Tc ) ), 6 ), mult( 19661 /*0.15f Q17*/, shl( Tc, 4 ) ) /*Q6*/ ); +#endif BASOP_SATURATE_WARNING_ON_EVS test(); test(); @@ -531,8 +535,11 @@ void con_acelp( gain_32 = st->Mode2_lp_gainc; /*15Q16 *//* start-of-the-frame gain */ move16(); - ftmp = round_fx(L_shl(gain_32,1));/*Q0*/ - +#ifdef BASOP_NOGLOB + ftmp = round_fx_sat( L_shl_sat( gain_32, 1 ) ); /*Q0*/ +#else + ftmp = round_fx( L_shl( gain_32, 1 ) ); /*Q0*/ +#endif BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmp_16 = sub(shl_sat(gainCNG,sub(gainCNG_e,5/*Q5*/)),ftmp); @@ -649,14 +656,23 @@ void con_acelp( /* gain_16 = gain_32 = gain_inov * gain */ gain_32 = Mpy_32_16_1(gain_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ - gain_32 = L_shl(gain_32, add(15, s_gain_inov)); /* Q31 */ - gain_16 = round_fx(gain_32); /* Q15 */ +#ifdef BASOP_NOGLOB + gain_32 = L_shl_sat( gain_32, add( 15, s_gain_inov ) ); /* Q31 */ + gain_16 = round_fx_sat( gain_32 ); /* Q15 */ +#else + gain_32 = L_shl( gain_32, add( 15, s_gain_inov ) ); /* Q31 */ + gain_16 = round_fx( gain_32 ); /* Q15 */ +#endif /* step_32 = gain_inov * step */ step_32 = Mpy_32_16_1(step_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ step_32 = L_shl(step_32, add(15, s_gain_inov)); /* Q31 */ - g_e = norm_s(round_fx(L_shl(Mpy_32_16_1(st->Mode2_lp_gainc, gain_inov), add(15, s_gain_inov)))); /* norm_s for gain*gain_inov at the end of the following loops */ +#ifdef BASOP_NOGLOB + g_e = norm_s( round_fx_sat( L_shl_sat( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ +#else + g_e = norm_s( round_fx( L_shl( Mpy_32_16_1( st->Mode2_lp_gainc, gain_inov ), add( 15, s_gain_inov ) ) ) ); /* norm_s for gain*gain_inov at the end of the following loops */ +#endif g_e = s_min(norm_s(gain_16), g_e); gain_16 = shl(gain_16, g_e); gain_32 = L_shl(gain_32, g_e); @@ -947,7 +963,11 @@ void con_acelp( { FOR( i=0 ; i < st->L_frame; i++ ) { - syn[i] = add(syn[i], syn_unv[i]); +#ifdef BASOP_NOGLOB + syn[i] = add_sat( syn[i], syn_unv[i] ); +#else + syn[i] = add( syn[i], syn_unv[i] ); +#endif move16(); } } @@ -1002,8 +1022,11 @@ void con_acelp( /*updating enr_old parameters*/ frame_ener_fx( st->L_frame, st->last_good, syn, round_fx(tmp_tc), &(st->enr_old_fx), 1, 0, 0, 0 ); - st->enr_old_fx = L_shl(st->enr_old_fx,shl(negate(Qf_syn),1)); - +#ifdef BASOP_NOGLOB + st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); +#else + st->enr_old_fx = L_shl( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); +#endif /* update ACELP synthesis memory */ Copy(mem_syn, st->mem_syn2_fx , M); Copy(syn+st->L_frame-L_SYN_MEM, st->mem_syn_r , L_SYN_MEM); diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index ca81d2706eb0501d16df1f7d1f7b5a248e7eb5ab..73ee5ba1161118dd347b254231319d93c2302eb3 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -395,7 +395,21 @@ void con_tcx( FOR( i=0 ; i< Tc; i++ ) { move16(); - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( +#ifdef BASOP_NOGLOB + *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( + L_mult(174/* 0.0053f Q15*/, pt1_exc[-5]), + 0/* 0.0000f Q15*/, pt1_exc[-4]), + -1442/*-0.0440f Q15*/, pt1_exc[-3]), + 0/* 0.0000f Q15*/, pt1_exc[-2]), + 8641/* 0.2637f Q15*/, pt1_exc[-1]), + 18022/* 0.5500f Q15*/, pt1_exc[0] ), + 8641/* 0.2637f Q15*/, pt1_exc[1] ), + 0/* 0.0000f Q15*/, pt1_exc[2] ), + -1442/*-0.0440f Q15*/, pt1_exc[3] ), + 0/* 0.0000f Q15*/, pt1_exc[4] ), + 174/* 0.0053f Q15*/, pt1_exc[5] ); +#else + *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mult(174/* 0.0053f Q15*/, pt1_exc[-5]), 0/* 0.0000f Q15*/, pt1_exc[-4]), -1442/*-0.0440f Q15*/, pt1_exc[-3]), @@ -407,6 +421,7 @@ void con_tcx( -1442/*-0.0440f Q15*/, pt1_exc[3] ), 0/* 0.0000f Q15*/, pt1_exc[4] ), 174/* 0.0053f Q15*/, pt1_exc[5] ); +#endif pt1_exc++; } } @@ -415,7 +430,8 @@ void con_tcx( FOR( i=0 ; i< Tc; i++ ) { move16(); - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( +#ifdef BASOP_NOGLOB + *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mult(-174/*-0.0053f Q15*/, pt1_exc[-5]), -121/*-0.0037f Q15*/, pt1_exc[-4]), -459/*-0.0140f Q15*/, pt1_exc[-3]), @@ -427,6 +443,20 @@ void con_tcx( -459/*-0.0140f Q15*/, pt1_exc[3] ), -121/*-0.0037f Q15*/, pt1_exc[4] ), -174/*-0.0053f Q15*/, pt1_exc[5] ); +#else + *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( + L_mult(-174/*-0.0053f Q15*/, pt1_exc[-5]), + -121/*-0.0037f Q15*/, pt1_exc[-4]), + -459/*-0.0140f Q15*/, pt1_exc[-3]), + 590/* 0.0180f Q15*/, pt1_exc[-2]), + 8743/* 0.2668f Q15*/, pt1_exc[-1]), + 16355/* 0.4991f Q15*/, pt1_exc[0] ), + 8743/* 0.2668f Q15*/, pt1_exc[1] ), + 590/* 0.0180f Q15*/, pt1_exc[2] ), + -459/*-0.0140f Q15*/, pt1_exc[3] ), + -121/*-0.0037f Q15*/, pt1_exc[4] ), + -174/*-0.0053f Q15*/, pt1_exc[5] ); +#endif pt1_exc++; } } @@ -775,8 +805,11 @@ void con_tcx( { gain32 = Mpy_32_16_1(gain32, 22938/*0.7f Q15*/); } - L_tmp = L_shl(gain32,1); - +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_shl_sat( gain32, 1 ); +#else + L_tmp = L_shl( gain32, 1 ); +#endif IF (GT_32(L_shl(L_deposit_h(gainCNG),sub(gainCNG_e,31-16)/*Q16*/) , L_tmp)) { gainCNG_e = sub(15+1,norm_l(L_tmp)); @@ -822,7 +855,11 @@ void con_tcx( tmp_e = norm_l(L_tmp); L_tmp = L_shl(L_tmp,tmp_e); gain_inov_e = add(sub(gain_inov_e,tmp_e),31-29);/*->Q31*/ - gain_inov = round_fx(L_tmp);/*Q15,gain_inov_e*/ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ +#else + gain_inov = round_fx( L_tmp ); /*Q15,gain_inov_e*/ +#endif } st->Mode2_lp_gainp = L_shr(L_deposit_h(alpha/*Q14*/)/*Q14+16*/,1);/*Q29*/ @@ -870,7 +907,7 @@ void con_tcx( FOR( i=0 ; i< tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat(exc[i], shl(noise[i + (L_FIR_FER2 / 2)], Q_exc + noise_e));/*Q1*/ move16(); + exc[i] = add_sat(exc[i], shl_sat(noise[i + (L_FIR_FER2 / 2)], Q_exc + noise_e));/*Q1*/ move16(); #else exc[i] = add(exc[i] , shl(noise[i+(L_FIR_FER2/2)],Q_exc+noise_e));/*Q1*/ move16(); #endif @@ -1043,13 +1080,21 @@ void con_tcx( FOR (i=0; isyn_Overl_TDACFB[i] = add(buf[i] , buf[W1-1-i]); +#ifdef BASOP_NOGLOB + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[W1 - 1 - i] ); +#else + hTcxDec->syn_Overl_TDACFB[i] = add( buf[i], buf[W1 - 1 - i] ); +#endif move16(); } FOR (i=0; isyn_Overl_TDACFB[W2+i] = add(buf[W2+i] , buf[W1-1-W2-i]); +#ifdef BASOP_NOGLOB + hTcxDec->syn_Overl_TDACFB[W2 + i] = add_sat( buf[W2 + i], buf[W1 - 1 - W2 - i] ); +#else + hTcxDec->syn_Overl_TDACFB[W2 + i] = add( buf[W2 + i], buf[W1 - 1 - W2 - i] ); +#endif move16(); } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 23145a7d06c89312928c5e8802f301dfb47b7f42..6703b540472bea6b75d2aaeaa1038a688bc92a57 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -54,10 +54,18 @@ static Word16 GetMinimumPosition( FOR (i = 0; i < cnt; i++) { tmp16 = shr(x[i],tmp_e); - energy = L_msu(energy_old,tmp16,tmp16); +#ifdef BASOP_NOGLOB + energy = L_msu_sat( energy_old, tmp16, tmp16 ); +#else + energy = L_msu( energy_old, tmp16, tmp16 ); +#endif tmp16 = shr(x[i+filterLength],tmp_e); BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ - energy = L_mac(energy,tmp16,tmp16); +#ifdef BASOP_NOGLOB + energy = L_mac_sat( energy, tmp16, tmp16 ); +#else + energy = L_mac( energy, tmp16, tmp16 ); +#endif BASOP_SATURATE_WARNING_ON_EVS /*if (energy == MAXVAL_WORD32)*/ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 117c0eabad9e078963e1c0acb88df99144c6bad6..009bbe52ff36e6e921f4be6560335ae487180acf 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -156,11 +156,19 @@ ivas_error evs_dec_fx( /* st_fx->old_out_fx, st_fx->L_frameTCX); */ FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - hHQ_core->old_out_fx[i] = shl(mult_r(hHQ_core->old_out_fx[i] , st_fx->plcInfo.recovery_gain), 1); +#ifdef BASOP_NOGLOB + hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#else + hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#endif } FOR( i = 0; i < st_fx->L_frame; i++ ) { - hHQ_core->old_out_LB_fx[i] = shl(mult_r(hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain), 1); +#ifdef BASOP_NOGLOB + hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#else + hHQ_core->old_out_LB_fx[i] = shl( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); +#endif } /* attenuate PLC buffers, if no aldo window is used and if no sid or zero frame is received */ @@ -176,7 +184,11 @@ ivas_error evs_dec_fx( FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { - hTcxDec->syn_OverlFB[i] = shl(mult(tmp1, hTcxDec->syn_OverlFB[i]), add(s,1)); +#ifdef BASOP_NOGLOB + hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); +#else + hTcxDec->syn_OverlFB[i] = shl( mult( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); +#endif move16(); } @@ -185,7 +197,11 @@ ivas_error evs_dec_fx( tmp1 = extract_l(L_shr_r(f,s)); FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ ) { - hTcxDec->syn_Overl[i] = shl(mult(tmp1, hTcxDec->syn_Overl[i]),s); +#ifdef BASOP_NOGLOB + hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); +#else + hTcxDec->syn_Overl[i] = shl( mult( tmp1, hTcxDec->syn_Overl[i] ), s ); +#endif move16(); } } @@ -1018,7 +1034,11 @@ ivas_error evs_dec_fx( { FOR (i=0; i < st_fx->L_frame/2; i++) { - output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame/4] ); +#ifdef BASOP_NOGLOB + output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); +#else + output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); +#endif move16(); } } @@ -1184,7 +1204,11 @@ ivas_error evs_dec_fx( FOR (i = 0; i < tmps; i++) { - output_sp[i+delay_comp] = msu_r(L_mult(output_sp[i+delay_comp], alpha), shr(hHQ_core->old_out_fx[i+nz], timeIn_e), add(alpha, -32768)); +#ifdef BASOP_NOGLOB + output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); +#else + output_sp[i + delay_comp] = msu_r( L_mult( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); +#endif move16(); alpha = add(alpha, step); } @@ -1307,7 +1331,11 @@ ivas_error evs_dec_fx( FOR (i = 0; i < tmps; i++) { - output_sp[i+tmps] = msu_r(L_mult(shr(pcmbufFB[i], timeIn_e), alpha), output_sp[i+tmps], add(alpha, -32768)); +#ifdef BASOP_NOGLOB + output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); +#else + output_sp[i + tmps] = msu_r( L_mult( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); +#endif move16(); alpha = add(alpha, step); } @@ -1345,7 +1373,11 @@ ivas_error evs_dec_fx( FOR (i = delta; i < tmps; i++) { - output_sp[i] = msu_r(L_mult(output_sp[i], alpha), shr(hTcxDec->FBTCXdelayBuf[i], timeIn_e), add(alpha, -32768)); +#ifdef BASOP_NOGLOB + output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); +#else + output_sp[i] = msu_r( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); +#endif move16(); #ifdef BASOP_NOGLOB alpha = add_sat(alpha, step); diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index b215d98b4f36c8e50e6df347c00cfc1eed576ef7..9e6ff1dc93f6b5fd2bea44f6fc27f6180af5181b 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -3561,7 +3561,11 @@ generate_comfort_noise_dec ( s = sub(15-NOISE_HEADROOM,noiseExp); FOR (i=0; i Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); +#endif move32(); /* Q14 -> Q16 */ /**norm_gain_code = *gain_code / *gain_inov;*/ @@ -458,7 +466,11 @@ void gain_dec_mless_fx( /**gain_code *= gcode0;*/ L_tmp = L_mult(gain_code16,gcode0_fx); /*Q0*Q0 -> Q1*/ - *gain_code_fx = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#endif move32(); /*Q16*/ } ELSE @@ -727,7 +739,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[0] = *gain_code_fx; @@ -874,8 +890,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)); /* Q10 -> Q16*/ - +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ +#endif gc_mem[2] = *gain_code_fx; move32(); gp_mem[2] = *gain_pit_fx; @@ -954,7 +973,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 move32(); /* Q10 -> Q16*/ } @@ -1249,7 +1272,11 @@ void gain_dec_SQ_fx( /**gain_code *= gcode0;*/ L_tmp = L_mult(tmp16,gcode0); /* Q0*Q0 -> Q1*/ /**gain_code = L_shl(L_tmp,add(expg,15)); Q16*/ - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#else + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#endif move32(); /*Q16*/ /**norm_gain_code = *gain_code / *gain_inov;*/ diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 5511a70e8da61e00d0639c8cae5447ca73b1f067..5075e40fc2e480f9a847e4f58da5028ae516d2aa 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -93,7 +93,11 @@ void hq_pred_hb_bws_fx( L_tmp = L_deposit_l(0); FOR(i=25; iprev_ener_shb_fx = extract_l(L_tmp);/*Q1*/ diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 34203c87cf5b125de784f4639133b6d0c38c7ecb..0b37fcee9d59e539323b5955598575e5b88df231 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -344,7 +344,11 @@ void hq_lr_dec_fx( frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ L_tmp = Pow2(30, frac1); exp = sub(exp, 30); - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ +#ifdef BASOP_NOGLOB + Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#else + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#endif } FOR( i = 0; i < bands_fx; i++ ) @@ -419,13 +423,21 @@ void hq_lr_dec_fx( { IF( GE_16(i,lowband)) { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#else + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - +#endif } ELSE { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif if(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) { Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ @@ -499,11 +511,12 @@ void hq_lr_dec_fx( IF(EQ_16(last_bitalloc_max_band[j++], 1)) { L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = Calc_inv(L_shl(L_tmp,14), &exp); #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat(Mult_32_16(Ep_avrg_fx, tmp), sub(14, exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + tmp = Calc_inv( L_shl_sat( L_tmp, 14 ), &exp ); + L_tmp = L_shl_sat( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #else - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + tmp = Calc_inv( L_shl( L_tmp, 14 ), &exp ); + L_tmp = L_shl( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #endif L_tmp =L_max(L_tmp,16384); /*14 */ tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ @@ -545,7 +558,11 @@ void hq_lr_dec_fx( { IF(GE_16(i,lowband)) { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif } ELSE { diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 3bc13fae37c53bae72b6948e07b5576f6bbb133c..92caeba8cf1d6f22de54057d61e8f915ea254960 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -1643,7 +1643,11 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* calc square root of L_tmp and store result in dN */ L_tmp = Sqrt32(L_tmp, &L_tmp_e); - dN[sfb] = round_fx(L_tmp); +#ifdef BASOP_NOGLOB + dN[sfb] = round_fx_sat( L_tmp ); +#else + dN[sfb] = round_fx( L_tmp ); +#endif dN_e[sfb] = L_tmp_e; move16(); dN[sfb+1] = dN[sfb]; @@ -1699,8 +1703,13 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* Build a threshold and compare with L_tmp. Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ BASOP_SATURATE_WARNING_OFF_EVS - L_tmp2 = L_shl(L_negate(Mpy_32_16_1(sNlocal, 33/*0.001f Q15*/)), sub(sNlocal_e,L_tmp_e)); +#ifdef BASOP_NOGLOB + L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); + L_tmp2 = L_sub_sat(L_tmp2, L_negate(L_tmp)); +#else + L_tmp2 = L_shl( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); L_tmp2 = L_sub(L_tmp2, L_negate(L_tmp)); +#endif BASOP_SATURATE_WARNING_ON_EVS IF (L_tmp2 < 0 ) @@ -1968,7 +1977,11 @@ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivate /* gain[sfb] = min(gain[sfb], 12.f); */ BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ - tmp = shl(gain[sfb], sub(gain_e[sfb], 15 - 5)); /* 10Q5 | tmp is in 10Q5 */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#else + tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#endif BASOP_SATURATE_WARNING_ON_EVS IF (tmp > 384) /* 10Q5 | 384 = 12 in 10Q5 */ @@ -2615,7 +2628,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* gain[sfb] = min(gain[sfb], 12.f); */ BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ - tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#else + tmp = shl( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ +#endif BASOP_SATURATE_WARNING_ON_EVS IF( tmp > 384 ) /* 10Q5 | 384 = 12 in 10Q5 */ diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 62f8c06322f063d175a31f93dc3415b5ad963d6c..2e3e023b5a08526a96c99a901bdf6a827190bf2e 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -318,7 +318,11 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 E3 = L_deposit_l(1); FOR (i=0 ; ilp_gainc_fx = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ +#ifdef BASOP_NOGLOB + st_fx->lp_gainc_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ +#else + st_fx->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ +#endif } /* reset the pitch buffer in case of FRAME_NO_DATA or SID frames */ IF( EQ_16(st_fx->L_frame,L_FRAME)) diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 06b1e682180ad0b4437d242d445533d45e9a4635..441f6ac0a47e9589fd8767dd6f2e7398c0648745 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -870,7 +870,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub(exp, 13); - SWB_fenv[n_band] = shl(tmp, add(exp,1)); +#ifdef BASOP_NOGLOB + SWB_fenv[n_band] = shl_sat( tmp, add( exp, 1 ) ); +#else + SWB_fenv[n_band] = shl( tmp, add( exp, 1 ) ); +#endif move16();/*Q1 */ } diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 0307a57974765d7968ead35c39ea5e3a73e0ca92..f2dfdadec25ed6f18893ee227a3a5b17ceddd213 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -914,7 +914,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ move16(); FOR( i = 0; i < Nsv*WIDTH_BAND; i++ ) { - t_audio_tmp[i] = shl(x_norm[i], t_audio_exp); +#ifdef BASOP_NOGLOB + t_audio_tmp[i] = shl_sat( x_norm[i], t_audio_exp ); +#else + t_audio_tmp[i] = shl( x_norm[i], t_audio_exp ); +#endif move16(); } @@ -1262,7 +1266,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ FOR( i=0; istate_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#else prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#endif } rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); @@ -1376,7 +1380,11 @@ void wb_tbe_dec_fx( sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { +#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 ); @@ -1394,8 +1402,13 @@ void wb_tbe_dec_fx( curr_pow = 0; FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { +#ifdef BASOP_NOGLOB + curr_pow = L_mac0_sat( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ +#else curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ +#endif } if( GT_16( voice_factors[0], 24576 )) @@ -1659,7 +1672,11 @@ void wb_tbe_dec_fx( exp = sub( add( exp, 22 ), 30 ); tmp = div_s( 16384, tmp ); L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ +#ifdef BASOP_NOGLOB + st_fx->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ +#else st_fx->last_wb_bwe_ener_fx = round_fx( L_shl( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ +#endif } @@ -2598,8 +2615,11 @@ void swb_tbe_dec_fx( #endif } } - ener = s_max(1, round_fx( L_shl( L_ener, sub(19, shl(Q_bwe_exc, 1)) ) )); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ - +#ifdef BASOP_NOGLOB + ener = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ +#else + ener = s_max( 1, round_fx( L_shl( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ +#endif /* WB/SWB bandwidth switching */ IF( st_fx->bws_cnt > 0 ) { @@ -2676,7 +2696,11 @@ void swb_tbe_dec_fx( /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } L_tmp = L_mult0(st_fx->prev_ener_shb_fx, inv_ener); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr(L_tmp, sub(9, exp_ener)); /*27 -exp_ener -(9-exp_ener )= Q18*/ +#ifdef BASOP_NOGLOB + GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ +#else + GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ +#endif } ELSE { @@ -2738,7 +2762,11 @@ void swb_tbe_dec_fx( exp_ener = norm_s(ener); tmp = shl(ener, exp_ener);/*Q(3+exp)*/ inv_ener = div_s(16384, tmp);/*Q(15+14-3-exp)*/ - prev_ener_ratio_fx = L_shr(L_mult0(st_fx->prev_ener_shb_fx, inv_ener), sub(9, exp_ener)); /*Q: 1+26-exp-9+exp = 18 */ +#ifdef BASOP_NOGLOB + prev_ener_ratio_fx = L_shr_sat( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ +#else + prev_ener_ratio_fx = L_shr( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ +#endif } IF(EQ_16(st_fx->nbLostCmpt, 1)) @@ -3162,7 +3190,11 @@ void swb_tbe_dec_fx( move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation[add(i,i_mult(j,40))] = shl(mult_r( shaped_shb_excitation[add(i,i_mult(j,40))], scale) ,3); +#ifdef BASOP_NOGLOB + shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl_sat( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); +#else + shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); +#endif move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -3219,7 +3251,11 @@ void swb_tbe_dec_fx( tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); +#ifdef BASOP_NOGLOB + st_fx->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#else st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#endif } /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ @@ -3233,7 +3269,11 @@ void swb_tbe_dec_fx( tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#else tmp = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#endif } set16_fx(st_fx->prev_SWB_fenv_fx, tmp, SWB_FENV); /* Q1 */ @@ -4321,7 +4361,11 @@ void fb_tbe_dec_fx( /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ FOR (i=0; ilastBlockData.nSamples, &inv_exp ); tiltFactor = round_fx( BASOP_Util_fPow( L_max( L_tmp, L_deposit_h( tiltCompFactor ) ), 0, L_deposit_h( inv_samples ), inv_exp, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ +#ifdef BASOP_NOGLOB + tiltFactor = shl_sat( tiltFactor, exp ); +#else tiltFactor = shl( tiltFactor, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = MAX16B; move16(); @@ -1913,7 +1917,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( hTonalMDCTConc->pTCI_float->upperIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] - hTonalMDCTConc->pTCI_float->lowerIndex[hTonalMDCTConc->pTCI_float->numIndexes - 1] + 1 ), 15, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ - tmp = shl( tmp, exp ); +#ifdef BASOP_NOGLOB + tmp = shl_sat( tmp, exp ); +#else + tmp = shl( tmp, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = mult_r( tilt, tmp ); @@ -2323,7 +2331,11 @@ void TonalMDCTConceal_InsertNoise( inv_samples = Inv16(hTonalMDCTConc->lastBlockData.nSamples, &inv_exp); tiltFactor = round_fx(BASOP_Util_fPow(L_max(L_tmp, L_deposit_h(tiltCompFactor)), 0, L_deposit_h(inv_samples),inv_exp, &exp)); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ - tiltFactor = shl(tiltFactor, exp); +#ifdef BASOP_NOGLOB + tiltFactor = shl_sat( tiltFactor, exp ); +#else + tiltFactor = shl( tiltFactor, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = 32767/*1.0f Q15*/; @@ -2498,7 +2510,11 @@ void TonalMDCTConceal_InsertNoise( tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI_fix->upperIndex[hTonalMDCTConc->pTCI_fix->numIndexes-1]-hTonalMDCTConc->pTCI_fix->lowerIndex[hTonalMDCTConc->pTCI_fix->numIndexes-1]+1),15, &exp)); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ - tmp = shl(tmp, exp); +#ifdef BASOP_NOGLOB + tmp = shl_sat( tmp, exp ); +#else + tmp = shl( tmp, exp ); +#endif BASOP_SATURATE_WARNING_ON_EVS tilt = mult_r(tilt,tmp); diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index cb99fa9a3d1c465b34f92ecffe46baf81004d423..1e1371878bd324745dbecf313e94cdd4a7b3ba96 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -323,8 +323,13 @@ ivas_error ppp_voiced_decoder_fx( /* temp32_fx = (Word32)divide_dp((Word40)819200,(Word40)L_shl((Word32)CURRP_Q_D_FX->lag_fx,6),-23,1);//Q6 */ exp = norm_s(CURRP_Q_D_FX->lag_fx); tmp = div_s(shl(1,sub(14,exp)),CURRP_Q_D_FX->lag_fx);/*29-exp */ - L_tmp =L_shl(L_mult0(tmp,12800),exp - 7); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_mult0( tmp, 12800 ), exp - 7 ); + temp32_fx = round_fx_sat( L_tmp ); +#else + L_tmp = L_shl( L_mult0( tmp, 12800 ), exp - 7 ); temp32_fx = round_fx(L_tmp); +#endif diff = round_fx(L_shl(temp32_fx,16-6));/*Q0 */ CURRP_Q_D_FX->nH_fx = find_rem(upper_cut_off_freq,diff,&rem_fx);/*Q0 */ diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index 323cd536a5bad560029ab23bdbb435ed58679324..6653dbab76236fc6db83d61d41ea47a7f886d304 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -1538,15 +1538,26 @@ void waveform_adj2_fix( Word16 *overlapbuf, ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); dat= shl(sbuf[i],s16MaxCoefNorm); temp_OUT= mult(*recovery_gain, sub(32767,ratio)); - outx_new[i]= round_fx(L_add(L_shr(L_mult(temp_OUT,dat ),s16MaxCoefNorm-1), L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2))); +#ifdef BASOP_NOGLOB + outx_new[i] = round_fx_sat( L_add_sat( L_shr_sat( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); +#else + outx_new[i] = round_fx( L_add( L_shr( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); +#endif move16(); - *recovery_gain =sub(*recovery_gain,shr_r(step_concealgain,1)); /* q14 */ +#ifdef BASOP_NOGLOB + *recovery_gain = sub_sat( *recovery_gain, shr_r( step_concealgain, 1 ) ); /* q14 */ +#else + *recovery_gain = sub( *recovery_gain, shr_r( step_concealgain, 1 ) ); /* q14 */ +#endif } FOR (i = gain_zero_start; i < Framesize; i++) { ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); - outx_new[i] = round_fx(L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2)); - +#ifdef BASOP_NOGLOB + outx_new[i] = round_fx_sat( L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); +#else + outx_new[i] = round_fx( L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); +#endif } if (*recovery_gain < 0) diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c index eea94dea19432876652d74264a7961d223581e5d..c3fc505167a3dbf3a330db56b0fb1becaef60940 100644 --- a/lib_enc/SNR_calc_fx.c +++ b/lib_enc/SNR_calc_fx.c @@ -320,7 +320,11 @@ void snr_calc( } *tsnr = VAD_Log2(tmp, minscale2); move32(); - *tsnr = L_add(*tsnr, MUL_F(*tsnr, 6226)); /* *tsnr *= 1.2; */ +#ifdef BASOP_NOGLOB + *tsnr = L_add_sat( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */ +#else + *tsnr = L_add( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */ +#endif move32(); } ELSE diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index ce7dfa21252ca91224d1831a0618cb31e34ac5e0..50a98b6b2c6e0615ed73639152d2237e46ada5b9 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -365,10 +365,17 @@ static void encod_gen_voic_core_switch_fx( { /* code in Q9, gain_pit in Q14 */ L_tmp = L_mult(gcode16, code[i]); - L_tmp = L_shl(L_tmp, 5); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); + L_tmp = L_mac_sat(L_tmp, exc[i ], gain_pit); + L_tmp = L_shl_sat(L_tmp, 1); /* saturation can occur here */ + exc[i ] = round_fx_sat(L_tmp); +#else + L_tmp = L_shl( L_tmp, 5 ); L_tmp = L_mac(L_tmp, exc[i ], gain_pit); L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ exc[i ] = round_fx(L_tmp); +#endif } /* write reserved bits */ @@ -385,7 +392,11 @@ static void encod_gen_voic_core_switch_fx( FOR( i = L_SUBFR; i < 2*L_SUBFR; i++ ) { - exc[i] = round_fx(L_shl(L_mult(exc[i], gain_pit), 1)); +#ifdef BASOP_NOGLOB + exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) ); +#else + exc[i] = round_fx( L_shl( L_mult( exc[i], gain_pit ), 1 ) ); +#endif } return; diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index 89399a711e4f43d7bc3f5ce29d335326788dbdf3..b5cb95dc0ed6cecfdb42599a4510e36b9b8b0356 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -78,7 +78,21 @@ Word16 E_ACELP_toeplitz_mul_fx( L_maxloc = L_shr(L_maxloc, 2); /* Do not warn saturation of L_tot, since its for headroom estimation. */ BASOP_SATURATE_WARNING_OFF_EVS - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ +#ifdef BASOP_NOGLOB + L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ + L_maxloc = L_shr(L_maxloc, 1); + L_tot = L_add_sat(L_tot, L_maxloc); /* +max/8 */ + if ( highrate ) + { + L_tot = L_add_sat(L_tot, L_maxloc); /* +max/8 */ + } + L_maxloc = L_shr(L_maxloc, 1); + if ( highrate ) + { + L_tot = L_add_sat(L_tot, L_maxloc); /* +max/16 */ + } +#else + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ L_maxloc = L_shr(L_maxloc, 1); L_tot = L_add(L_tot, L_maxloc); /* +max/8 */ if ( highrate ) @@ -90,6 +104,7 @@ Word16 E_ACELP_toeplitz_mul_fx( { L_tot = L_add(L_tot, L_maxloc); /* +max/16 */ } +#endif BASOP_SATURATE_WARNING_ON_EVS } diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 23e72016c2ef55f16da4c0feddcb8408fb06c0cc..bafbe9acc44b3cd4beae83324f1ec76154daeedf 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -361,7 +361,11 @@ void amr_wb_enc_fx( { lp_bckr = Mean32(hNoiseEst->bckr_fx+1, 9 ); } - hp_bckr = L_shr(L_add(hNoiseEst->bckr_fx[st->max_band -1] , hNoiseEst->bckr_fx[st->max_band]),1); +#ifdef BASOP_NOGLOB + hp_bckr = L_shr( L_add_sat( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 ); +#else + hp_bckr = L_shr( L_add( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 ); +#endif if( hp_bckr == 0 ) /* Avoid division by zero. */ { hp_bckr = L_deposit_l(1); diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 0e115ffa5e82aa41a8dfff3ff539b34016cbeb33..ae577bf626efe55d98ca0eef18d31fcb5d24cd00 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -427,8 +427,11 @@ static void find_enr( * Find the total energy over the input bandwidth *-----------------------------------------------------------------*/ - etot = L_add(*LEtot, L_shl(etot, sub(exp_etot, 4))); - +#ifdef BASOP_NOGLOB + etot = L_add_sat( *LEtot, L_shl_sat( etot, sub( exp_etot, 4 ) ) ); +#else + etot = L_add( *LEtot, L_shl( etot, sub( exp_etot, 4 ) ) ); +#endif *LEtot = etot; move32(); diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 9a6bb3e77d4ea29347906287bf6fd0f4ac0a1c1d..ef4c39dfd7b666895cd74a7fc158b8e78bf9dc29 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -92,7 +92,11 @@ static Word16 tcx_arith_estimate_scale( /* scale and accumulate */ BASOP_SATURATE_WARNING_OFF_EVS; - accu = L_add(accu, L_shr(L_tmp, sub(tmp, s))); +#ifdef BASOP_NOGLOB + accu = L_add_sat( accu, L_shr( L_tmp, sub( tmp, s ) ) ); +#else + accu = L_add( accu, L_shr( L_tmp, sub( tmp, s ) ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } s = sub(shl(add(abs_spectrum_e, envelope_e), 1), s); diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index b05b84536be3574a3f6fa95e96731734af3d5406..9b52741bdecd119ae08c5e8cc5ebcb65deb7c6f8 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -123,7 +123,11 @@ void AVQ_cod_fx( /* o: comfort noise gain factor */ /* estimated gain (when offset=0, estimated gain=1) */ f_tmp = L_Extract_lc(Ltmp, &e_tmp); tmp16 = extract_l(Pow2(14, f_tmp)); - Lgain = L_shl(tmp16, e_tmp); +#ifdef BASOP_NOGLOB + Lgain = L_shl_sat( tmp16, e_tmp ); +#else + Lgain = L_shl( tmp16, e_tmp ); +#endif /* gain_inv = 1.0f / gain */ e_tmp = norm_l(Lgain); tmp16 = extract_h(L_shl(Lgain, e_tmp)); diff --git a/lib_enc/bass_psfilter_enc_fx.c b/lib_enc/bass_psfilter_enc_fx.c index 4173a2ac63ea8e3fe842938b3b68c9137de28991..68995ca338d6183cee3ee08c01318d8206d7cc91 100644 --- a/lib_enc/bass_psfilter_enc_fx.c +++ b/lib_enc/bass_psfilter_enc_fx.c @@ -399,8 +399,13 @@ Word16 bass_pf_enc_fx( /* *gain_factor_param = (int)(-2.f*(cross_n_d/nrg_n)+0.5f); */ tmp16 = BASOP_Util_Divide3232_Scale(cross_n_d, nrg_n, &st); /* Q15-st-s3+s4 */ BASOP_SATURATE_WARNING_OFF_EVS; - tmp16 = shl(negate(tmp16), add(sub(add(st, s3), s4), 1-14)); /* Q1 */ +#ifdef BASOP_NOGLOB + tmp16 = shl_sat( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */ + tmp16 = shr(add_sat(tmp16, 1), 1); /* Q0 */ +#else + tmp16 = shl( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */ tmp16 = shr(add(tmp16, 1), 1); /* Q0 */ +#endif BASOP_SATURATE_WARNING_ON_EVS; *gain_factor_param = tmp16; diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index e18b66d00dedf4afecce6a100151f6315d9a6d12..5db72e0c328a5587f5144bebe2d2f069b9dd3d2b 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -657,19 +657,31 @@ void CNG_enc_fx( FOR ( j=0; jlp_ener_fx; */ IF(EQ_16(m1,1)) { - L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#endif } 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)); +#ifdef BASOP_NOGLOB + L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#else + L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); +#endif } env[i] = L_tmp; @@ -795,9 +807,15 @@ void CNG_enc_fx( 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) */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ +#else + L_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 */ +#endif } } ELSE /* L_FRAME16k */ @@ -808,9 +826,15 @@ void CNG_enc_fx( 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) */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ +#else + 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 */ +#endif } } /* convert log2 of residual signal energy */ @@ -840,7 +864,11 @@ void CNG_enc_fx( L_tmp1 = L_add(env[i], 0); FOR ( j=0; j< hDtxEnc->cng_hist_size; j++ ) { - L_tmp1 = L_add(L_tmp1,hTdCngEnc->cng_res_env_fx[j*NUM_ENV_CNG+i]); +#ifdef BASOP_NOGLOB + L_tmp1 = L_add_sat( L_tmp1, hTdCngEnc->cng_res_env_fx[j * NUM_ENV_CNG + i] ); +#else + L_tmp1 = L_add( L_tmp1, hTdCngEnc->cng_res_env_fx[j * NUM_ENV_CNG + i] ); +#endif } 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); @@ -1361,7 +1389,11 @@ static Word16 shb_DTX_fx( shb_ener_fx = L_deposit_l(0); FOR ( i=0; imem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); move16(); BASOP_SATURATE_WARNING_OFF_EVS; - hLPDmem->mem_w0 =shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#else + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#endif BASOP_SATURATE_WARNING_ON_EVS; /*-------------------------------------------------------* @@ -379,7 +383,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ Ltmp = L_shl(Ltmp, Q_new_p5); Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); #ifdef BASOP_NOGLOB - exc2[i] = round_fx(L_shl_o(Ltmp, 1, &Overflow)); + exc2[i] = round_fx_sat(L_shl_o(Ltmp, 1, &Overflow)); #else BASOP_SATURATE_WARNING_OFF_EVS exc2[i] = round_fx(L_shl(Ltmp, 1)); @@ -387,8 +391,13 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ #endif Ltmp2 = Mpy_32_16_1(gain_code, code[i]); - Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); +#ifdef BASOP_NOGLOB + Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); + Ltmp = L_add_sat( Ltmp, Ltmp2 ); +#else + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); + Ltmp = L_add( Ltmp, Ltmp2 ); +#endif #ifdef BASOP_NOGLOB Ltmp = L_shl_o(Ltmp, 1, &Overflow); /* saturation can occur here */ exc[i + i_subfr] = round_fx_o(Ltmp, &Overflow); diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 035e03000514164ba9d659ddf3098a3bfe972d99..c203dd2bb5b0034694b1a495e41f3fd5dc356b5a 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1688,7 +1688,11 @@ void QuantizeSpectrum_fx( IF (tmp2 >= 0) { BASOP_SATURATE_WARNING_OFF_EVS; - tmp2 = sub(sqGain, shr(tmp1, tmp2)); +#ifdef BASOP_NOGLOB + tmp2 = sub_sat( sqGain, shr_sat( tmp1, tmp2 ) ); +#else + tmp2 = sub( sqGain, shr( tmp1, tmp2 ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } ELSE @@ -2304,7 +2308,11 @@ void QuantizeSpectrum_fx( /* add part of current sub-window overlapping with previous window */ FOR (i = 0; i < L_ola; i++) { - tmpP16[i] = add(tmpP16[i], win[i]); +#ifdef BASOP_NOGLOB + tmpP16[i] = add_sat( tmpP16[i], win[i] ); +#else + tmpP16[i] = add( tmpP16[i], win[i] ); +#endif move16(); } /* copy new sub-window region not overlapping with previous window */ @@ -2387,7 +2395,11 @@ void QuantizeSpectrum_fx( /* add part of current sub-window overlapping with previous window */ FOR (i = 0; i < L_ola; i++) { - tmpP16[i] = add(tmpP16[i], win[i]); +#ifdef BASOP_NOGLOB + tmpP16[i] = add_sat( tmpP16[i], win[i] ); +#else + tmpP16[i] = add( tmpP16[i], win[i] ); +#endif move16(); } @@ -2581,7 +2593,11 @@ void QuantizeSpectrum_fx( tmp1 = sub(overlap, hTcxCfg->tcx_mdct_window_min_length); FOR (i=0; i < tmp1; i++) { - xn_buf16[i] = shl(add(xn_buf16[i], shr(hTcxEnc->old_out_fx[i+nz], tmp2)), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], shr_sat( hTcxEnc->old_out_fx[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( add( xn_buf16[i], shr( hTcxEnc->old_out_fx[i + nz], tmp2 ) ), TCX_IMDCT_HEADROOM ); +#endif move16(); } @@ -2590,19 +2606,31 @@ void QuantizeSpectrum_fx( FOR ( ; i < tmp1; i++) { tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[i-overlap+hTcxCfg->tcx_mdct_window_min_length].v.re); - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( add( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } FOR ( ; i < overlap; i++) { tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[overlap-1-i].v.im); - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); +#ifdef BASOP_NOGLOB + xn_buf16[i] = shl_sat( add_sat( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#else + xn_buf16[i] = shl( add( xn_buf16[i], tmp3 ), TCX_IMDCT_HEADROOM ); +#endif move16(); } 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/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 4252372b6d396b50c7ad799545ae7feeedc3bc89..7e2efe970d1fa78deb459bd8933c90cca38a96d3 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -414,8 +414,13 @@ static void init_tcx_fx( move16(); } +#ifdef BASOP_NOGLOB /*pit = pit_old * (float)st->L_frame/(float)L_frame_old;*/ + pit = shl_sat(mult_r(pit_old, div_s(st->L_frame, shl(L_frame_old, 2))), 2); +/* Note : the saturation here that can happens when FS == 32kHz*/ +#else pit = shl(mult_r(pit_old, div_s(st->L_frame, shl(L_frame_old, 2))), 2); +#endif /* assert(pit <= st->L_frame);*/ hTcxEnc->tcxltp_pitch_int_past = pit; @@ -722,7 +727,11 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old , const Word16 Copy( hLPDmem->mem_syn2, tmp_buf+1, M ); deemph_fx( tmp_buf+1, st->preemph_fac, M, &tmp ); Residu3_fx( Ap, tmp_buf+M, &tmp, 1, 1 ); - hLPDmem->mem_w0 = sub(shr(st->wspeech_enc[-1],shift), tmp); +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = sub_sat( shr_sat( st->wspeech_enc[-1], shift ), tmp ); +#else + hLPDmem->mem_w0 = sub( shr( st->wspeech_enc[-1], shift ), tmp ); +#endif } } ELSE IF((NE_16(st->L_frame,L_frame_old))) diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index 62f022bb3717e3de2153003897ddd078f5cfb3aa..fb31e3794f291e6ba30a956c011a5c7715679fa5 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -1233,7 +1233,11 @@ void core_acelp_tcx20_switching_fx( #else /* BASOP_NOGLOB */ (LT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) || EQ_16(stab_fac, 0x7fff) || #endif - (EQ_32(st->sr_core, INT_FS_12k8) && EQ_16(st->sp_aud_decision0,1) && LT_16(add(st->prevTempFlatness_fx, currFlatness), 2560/*20.f Q7*/) )) && +#ifdef BASOP_NOGLOB + ( EQ_32( st->sr_core, INT_FS_12k8 ) && EQ_16( st->sp_aud_decision0, 1 ) && LT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && +#else + ( EQ_32( st->sr_core, INT_FS_12k8 ) && EQ_16( st->sp_aud_decision0, 1 ) && LT_16( add( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && +#endif (LE_16(st->acelpFramesCount, 6) )) { dsnr = -512/*-2.0f Q8*/; @@ -1244,7 +1248,11 @@ void core_acelp_tcx20_switching_fx( test();test();test(); if ((LT_16(snr_acelp, snr_tcx))&& (GT_16(snr_acelp, sub(snr_tcx, 512/*2.0f Q8*/)) ) && - (GT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) ) && +#ifdef BASOP_NOGLOB + ( GT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) && +#else + ( GT_16( add( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) && +#endif (GE_16(st->acelpFramesCount, 6) )) { dsnr = 512/*2.0f Q8*/; diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 8cad74f964bf775fae4ff77a155202f484f658cf..416e325737e68897e685ca1fa86fe468d1e1808b 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -75,9 +75,13 @@ static void hp_filter_fx( #else /* BASOP_NOGLOB */ L_tmp = L_mult(sub(x[0], *oldx), 24465);/*Q_new+16 */ #endif /* BASOP_NOGLOB */ - L_tmp = L_mac(L_tmp, *oldy, 16158);/*Q_new+16 */ +#ifdef BASOP_NOGLOB + L_tmp = L_mac_sat( L_tmp, *oldy, 16158 ); /*Q_new+16 */ + y[0] = round_fx_sat(L_tmp);/*Q_new */ +#else + L_tmp = L_mac( L_tmp, *oldy, 16158 ); /*Q_new+16 */ y[0] = round_fx(L_tmp);/*Q_new */ - +#endif FOR(i = 1; i < L; i++) { /*y[i] = 0.4931f*y[i-1] + 0.7466f*(x[i] - x[i-1]); */ diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 1fb6f1feb9201305973f25f0bb0d4c41f88a1d91..c635ce6f3f5497787ed42387db6f33b1a8d5fa1b 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -780,7 +780,11 @@ void dtx_hangover_control_fx( } exp = norm_l(enr_est); - fra = round_fx(L_shl(enr_est,exp)); +#ifdef BASOP_NOGLOB + fra = round_fx_sat( L_shl_sat( enr_est, exp ) ); +#else + fra = round_fx( L_shl( enr_est, exp ) ); +#endif exp2 = norm_s(weights); fra2 = shl(weights,exp2); exp = sub(sub(exp,16),exp2); diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index d234a1dd9d2c4c2890f93f5bad5e657cbd5751db..450a27671b814c65b3936b387d44843c7d23ec73 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -466,8 +466,13 @@ static void E_ACELP_xh_corr(Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr) L_maxloc = L_shr(L_maxloc, 2); /* Do not warn saturation of L_tot, since its for headroom estimation. */ BASOP_SATURATE_WARNING_OFF_EVS - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ +#ifdef BASOP_NOGLOB + L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add_sat(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ +#else + L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */ L_tot = L_add(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ +#endif BASOP_SATURATE_WARNING_ON_EVS } diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index b7e8fbb21b7bc7a8871d0a8ee7299ae44fd55fa8..a2fc69216693f0fc97b21fd47556c0c47ec7ff02 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -196,7 +196,11 @@ static void E_ACELP_2pulse_searchx( move16(); /* dn[x] has only nb_pos_ix positions saved */ /*ps1 = ps0 + dn[x]; INDIRECT(1);ADD(1);*/ - ps1 = add(ps0, dn[x]); +#ifdef BASOP_NOGLOB + ps1 = add_sat( ps0, dn[x] ); +#else + ps1 = add( ps0, dn[x] ); +#endif /*alp1 = alp0 + 2*sgnx*cor[x]; INDIRECT(1);MULT(1); MAC(1);*/ #ifdef BASOP_NOGLOB alp1 = L_mac_o(alp0, cor[x], sgnx, &Overflow); /* Qalp = (Q_R=Q_cor)*Q_signval */ @@ -208,8 +212,11 @@ static void E_ACELP_2pulse_searchx( FOR (y = track_y; y < L_SUBFR; y += 4) { /*ps2 = ps1 + dn[y]; ADD(1);*/ - ps2 = add(ps1, dn[y]); - +#ifdef BASOP_NOGLOB + ps2 = add_sat( ps1, dn[y] ); +#else + ps2 = add( ps1, dn[y] ); +#endif /*alp2 = alp1 + 2.0f*sign[y]*(cor[y] + sgnx*pR[y]); MULT(1); MAC(2);*/ /*alp2 = alp1 + 2.0f*sign[y]*cor[y] + 2.0f*sign[y]*sgnx*pR[y]; MULT(1); MAC(2);*/ assert(sign[y] == sign_val_2 || sign[y] == -sign_val_2); diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index be7d3bd07552f35c6a4bcb3dc7d5fb8c4b2449c0..b35777e7fc498ea27963f9c5be8eb26cb4404487 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -216,17 +216,26 @@ void encod_amr_wb_fx( Ltmp = L_negate(Ltmp); Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); Ltmp = L_msu(Ltmp, y1[L_SUBFR - 1], gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - +#endif /*-----------------------------------------------------------------* * Find the total excitation *-----------------------------------------------------------------*/ FOR (i = 0; i < L_SUBFR; i++) { L_tmp = L_mult(gcode16, code[i]); - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc[i + i_subfr], gain_pit); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, 5 ); + L_tmp = L_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); +#else + L_tmp = L_shl( L_tmp, 5 ); + L_tmp = L_mac( L_tmp, exc[i + i_subfr], gain_pit ); +#endif #ifdef BASOP_NOGLOB L_tmp = L_shl_o(L_tmp, 1, &Overflow); /* saturation can occur here */ exc[i + i_subfr] = round_fx_o(L_tmp, &Overflow); diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index bbe55a384cd2dd51172d8ea256a10c477d8e57e8..dd4aca890230d8cbffab831ab874023bc1715f7d 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -323,9 +323,13 @@ void encod_gen_voic_fx( Ltmp = L_negate(Ltmp); Ltmp = L_mac(Ltmp, xn_fx[L_SUBFR - 1], 16384); Ltmp = L_msu(Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx); - Ltmp = L_shl(Ltmp, sub(1, shift)); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - +#endif IF(gain_preQ_fx != 0 ) { tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 1cf16e5d5d53e34b9ecb7580ae2a4d32925cf728..88f202c6cffd06741a891647b18269a55fc06ba4 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -99,8 +99,13 @@ void transf_cdbk_enc_fx( Ltmp = L_negate(Ltmp); Ltmp = L_mac(Ltmp, xn[i], 16384); Ltmp = L_msu(Ltmp, y1[i], *gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + x_tran[i] = round_fx_sat(Ltmp); /*Q_new-1 */ +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); x_tran[i] = round_fx(Ltmp); /*Q_new-1 */ +#endif } find_cn_fx( x_tran, Ap, p_Aq, x_in ); } @@ -148,11 +153,12 @@ 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 ); #ifdef BASOP_NOGLOB + stmp = shl_sat( x_norm[i], Q_AVQ_OUT ); L_corr = L_mac_sat( L_corr, x_tran[i], stmp ); L_ener = L_mac_sat(L_ener, stmp, stmp); #else + stmp = shl( x_norm[i], Q_AVQ_OUT ); L_corr = L_mac( L_corr, x_tran[i], stmp ); L_ener = L_mac(L_ener, stmp, stmp); #endif @@ -176,12 +182,20 @@ void transf_cdbk_enc_fx( } m_corr = div_s(m_corr, m_ener); e_corr = sub(e_corr, e_ener); - Ltmp = L_shl(m_corr, s_min(add(e_corr,1),31)); /* Lgain in Q16 */ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ +#else + Ltmp = L_shl( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ +#endif IF ( EQ_16(st_fx->coder_type,INACTIVE)) { Ltmp1 = L_max(gain_code,1); e_den = norm_l(Ltmp1); - m_den = extract_h(L_shl(Ltmp1, e_den)); +#ifdef BASOP_NOGLOB + m_den = extract_h( L_shl_sat( Ltmp1, e_den ) ); +#else + m_den = extract_h( L_shl( Ltmp1, e_den ) ); +#endif /* ensure m_corr < m_den */ test(); IF( m_corr>0 && m_den >0) @@ -213,8 +227,13 @@ void transf_cdbk_enc_fx( index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12>>1, (1 << G_AVQ_BITS) ); } Ltmp = Mult_32_16(gain_code,stmp); /* Q16 * Q12 - 15 -> Q13*/ - Ltmp = L_shl(Ltmp,5); /* Q13 -> Q18*/ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 5 ); /* Q13 -> Q18*/ + *gain_preQ = round_fx_sat(Ltmp); /* Q2*/ +#else + Ltmp = L_shl( Ltmp, 5 ); /* Q13 -> Q18*/ *gain_preQ = round_fx(Ltmp); /* Q2*/ +#endif } ELSE { @@ -468,8 +487,13 @@ Word16 gain_quant_fx( /* o: quantization index */ /*tmp1 = sub(c_max,c_min); Q14*/ /*tmp2 = sub(c_gain,c_min); Q14*/ - tmp1 = msu_r(L_deposit_h(c_max/*in Q13 already*/),c_min, 16384); /*Q13*/ +#ifdef BASOP_NOGLOB + tmp1 = msu_r_sat( L_deposit_h( c_max /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ + tmp2 = msu_r_sat(L_deposit_h(c_gain/*in Q13 already*/),c_min,16384); /*Q13*/ +#else + tmp1 = msu_r( L_deposit_h( c_max /*in Q13 already*/ ), c_min, 16384 ); /*Q13*/ tmp2 = msu_r(L_deposit_h(c_gain/*in Q13 already*/),c_min,16384); /*Q13*/ +#endif IF(tmp1 != 0) { exp = norm_s(tmp1); diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index f3a72bed25fd87ca41632ee988c3d263104e1b34..5b8efe1100d658832c598fed522b681a3906e575 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -145,7 +145,11 @@ void encod_nelp_fx( * Updates: last value of new target is stored in mem_w0 *-----------------------------------------------------------------*/ - hLPDmem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = sub_sat( shr_sat( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); +#else + hLPDmem->mem_w0 = sub( shr( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); +#endif move16();/*Q_new-1 */ hLPDmem->tilt_code = 0; move16();/* purely unvoiced */ diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index c5718ff8a943991985a582df0ce578137e2441bd..f44ab267f72ef27d510e233a1f601e0aa800f409 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -343,8 +343,13 @@ void enc_pit_exc_fx( } gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); +#ifdef BASOP_NOGLOB + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); +#else + Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx( Lgcode ); +#endif IF( use_fcb != 0) { hLPDmem->tilt_code = Est_tilt2(&exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); @@ -381,9 +386,15 @@ void enc_pit_exc_fx( ELSE { Ltmp = L_mult(xn[L_subfr - 1], 16384); - Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); +#ifdef BASOP_NOGLOB + Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); + Ltmp = L_shl_sat(Ltmp, sub(1, shift)); + hLPDmem->mem_w0 = round_fx_sat(Ltmp); /*Q_new-1 */ +#else + Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); Ltmp = L_shl(Ltmp, sub(1, shift)); hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ +#endif } /*-----------------------------------------------------------------* @@ -416,8 +427,13 @@ void enc_pit_exc_fx( { Ltmp = L_mult(exc[i + i_subfr], gain_pit); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_sat(Ltmp); +#else + Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ exc[i + i_subfr] = round_fx(Ltmp); +#endif } } diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index dad3acf3ba4af7ec0c1a05e1ec1c65f4ab412352..6f3c21ff74876b568a483049aef876caecf99947 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -246,9 +246,13 @@ Word16 encod_tran_fx( L_tmp = L_negate(L_tmp); L_tmp = L_mac(L_tmp, xn[L_SUBFR - 1], 16384); L_tmp = L_msu(L_tmp, y1[L_SUBFR - 1], gain_pit); - L_tmp = L_shl(L_tmp, sub(1, shift)); +#ifdef BASOP_NOGLOB + L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) ); + hLPDmem->mem_w0 = round_fx_sat(L_tmp); /*Q_new-1*/ +#else + L_tmp = L_shl( L_tmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx(L_tmp); /*Q_new-1*/ - +#endif /*-----------------------------------------------------------------* * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc @@ -264,7 +268,11 @@ Word16 encod_tran_fx( { FOR (i = 0; i < L_SUBFR; i++) { - exc2_fx[i+i_subfr] = round_fx(L_shl(L_mult(gain_pit,exc_fx[i+i_subfr]),1)); +#ifdef BASOP_NOGLOB + exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); +#else + exc2_fx[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); +#endif } } ELSE diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 1b7bcd264dcf33e7cb68a95f15655ae73359dad9..cbe7bbe5f8aee3d27879c66f275fe862928c6d6b 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -196,7 +196,11 @@ void encod_unvoiced_fx( hLPDmem->mem_w0 = sub(xn_fx[L_SUBFR - 1], round_fx(L_shl(Ltmp, 1))); move16(); BASOP_SATURATE_WARNING_OFF_EVS; - hLPDmem->mem_w0 = shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ +#ifdef BASOP_NOGLOB + hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#else + hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ +#endif BASOP_SATURATE_WARNING_ON_EVS; /*-------------------------------------------------------* @@ -220,10 +224,15 @@ void encod_unvoiced_fx( Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code_fx[i]); Ltmp2 = L_shl(Ltmp2, Q_new_p5); Ltmp = L_add(Ltmp, Ltmp2); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat(Ltmp, 1); /* saturation can occur here */ + exc_fx[i + i_subfr] = round_fx_sat(Ltmp); +#else BASOP_SATURATE_WARNING_OFF_EVS Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ BASOP_SATURATE_WARNING_ON_EVS exc_fx[i + i_subfr] = round_fx(Ltmp); +#endif } tmp2 = L_SUBFR; move16(); diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index 06638aa5e973fe8132f11c7c5b8adcbd702555c4..487aa34122809224ad80f185fedbbd1fe3bf792c 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -62,8 +62,13 @@ void est_energy_fx( FOR(i = 2; i < BandNum; i++) { Ltmp32 = L_shr(sb_power[i],shr_tmp); - frame_energy2 = L_add(frame_energy2, Ltmp32 ); +#ifdef BASOP_NOGLOB + frame_energy2 = L_add_sat( frame_energy2, Ltmp32 ); + if(i > 6) HB_Power = L_add_sat(HB_Power, Ltmp32 ); +#else + frame_energy2 = L_add( frame_energy2, Ltmp32 ); if(i > 6) HB_Power = L_add(HB_Power, Ltmp32 ); +#endif } frame_energy2 = L_sub(frame_energy2, Ltmp32 ); diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 6df5c076adfba790db56d347a5d9e3fc22bb2ebe..fc8f6b6668431383fbac1ae11851bbc3ae6d9a51 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -310,7 +310,11 @@ void core_signal_analysis_high_bitrate_fx( /* Outter left folding */ FOR(i = 0; i < folding_offset; i++) { - tcx20Win[folding_offset + i] = sub(tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i]); +#ifdef BASOP_NOGLOB + tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); +#else + tcx20Win[folding_offset + i] = sub( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); +#endif move16(); } #ifdef IVAS_CODE diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 25e610e3d43d2e86e9016973e4734751ff86b41a..7978ae278de437fb718d17fc2a21f91a1cee1d37 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -808,7 +808,11 @@ static void msvq_encoder (const Word16 * const cb[], /* i : Codebook (indexed c tmp = L_add(dist[0][c], L_sub(en, L_shl(t1, 1))); BASOP_SATURATE_WARNING_OFF_EVS - t1 = L_sub(tmp,dist[1][p_max]); +#ifdef BASOP_NOGLOB + t1 = L_sub_sat( tmp, dist[1][p_max] ); +#else + t1 = L_sub( tmp, dist[1][p_max] ); +#endif BASOP_SATURATE_WARNING_ON_EVS IF ( t1 <= 0 ) /* IF (L_sub(L_shr(tmp,1), L_shr(dist[1][p_max],1) ) <= 0 ) */ @@ -1498,7 +1502,11 @@ void generate_comfort_noise_enc_fx(Encoder_State *stcod, s = sub(15-NOISE_HEADROOM,noiseExp); FOR (i=0; i Q1*/ - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#else + *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); +#endif move32(); /*Q16*/ /* *norm_gain_code = *gain_code / *gain_inov; */ @@ -954,7 +962,11 @@ void gain_enc_tc_fx( i = sub(exp_num, exp_den); /* Gain_trans in Q7 */ g_code_fx = i_mult2(g_code_fx, tmp16); /* apply sign */ - *gain_code_fx = L_shr(L_deposit_l(g_code_fx),i); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shr_sat( L_deposit_l( g_code_fx ), i ); +#else + *gain_code_fx = L_shr( L_deposit_l( g_code_fx ), i ); +#endif move32(); /*----------------------------------------------------------------* @@ -1058,7 +1070,11 @@ void gain_enc_tc_fx( move16(); /**gain_code *= gcode0;*/ L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); +#ifdef BASOP_NOGLOB + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); +#else + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); +#endif move32(); /* Q14 -> Q16 */ push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); } diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 5d6d2ed184e1b5d70d515a887138808694bf45f0..008b1c186834c9e27601edfbb93e49c057fe01c2 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -117,8 +117,13 @@ Word16 gaus_encode_fx( Ltmp = L_shl(Ltmp, add(5, shift)); Ltmp = L_negate(Ltmp); Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); - Ltmp = L_shl(Ltmp, sub(1, shift)); - *mem_w0 = round_fx(Ltmp); +#ifdef BASOP_NOGLOB + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); + *mem_w0 = round_fx_sat( Ltmp ); +#else + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); + *mem_w0 = round_fx( Ltmp ); +#endif init_gp_clip_fx(clip_gain); /* reset pitch clipping parameters */ *gain_pit = 0; @@ -211,8 +216,13 @@ void gauss2v_fx( { /* fc0 += xn[i]*xn[i] */ /* fc1 += xn[i]*xn[i-1] */ - Lc0 = L_mac(Lc0, xn[i], xn[i]); +#ifdef BASOP_NOGLOB + Lc0 = L_mac_sat( Lc0, xn[i], xn[i] ); + Lc1 = L_mac_sat(Lc1, xn[i], xn[i-1]); +#else + Lc0 = L_mac( Lc0, xn[i], xn[i] ); Lc1 = L_mac(Lc1, xn[i], xn[i-1]); +#endif } /* fgxx = fc1/fc0 */ exp_num = sub(norm_l(Lc1), 1); @@ -599,10 +609,18 @@ void gauss2v_fx( div_result = div_s(Num, Den); /* Q15 */ /* Re-scale to compensate for normalization*/ - GainPortion2 = L_shr(L_deposit_l(div_result), sub(exp_num, exp_den)); +#ifdef BASOP_NOGLOB + GainPortion2 = L_shr_sat( L_deposit_l( div_result ), sub( exp_num, exp_den ) ); +#else + GainPortion2 = L_shr( L_deposit_l( div_result ), sub( exp_num, exp_den ) ); +#endif } - ener_sqrt = Isqrt(L_shl(GainPortion2, 1)); /* Make value a Q16 prior to division (align on power of 4) */ +#ifdef BASOP_NOGLOB + ener_sqrt = Isqrt( L_shl_sat( GainPortion2, 1 ) ); /* Make value a Q16 prior to division (align on power of 4) */ +#else + ener_sqrt = Isqrt( L_shl( GainPortion2, 1 ) ); /* Make value a Q16 prior to division (align on power of 4) */ +#endif ener_sqrt = L_shr(ener_sqrt, 8); /* Left-shift Q23 result to make a Q15 result */ Portion = Mult_32_16(GainPortion1, 19661); /* Performs GainPortion1*.6 */ diff --git a/lib_enc/hf_cod_amrwb_fx.c b/lib_enc/hf_cod_amrwb_fx.c index ac65954d2aaed2f0cfc6b9cfd1fa0b488757cf49..20a1296f92788f73f9eb599b1f41b3d484f70ba0 100644 --- a/lib_enc/hf_cod_amrwb_fx.c +++ b/lib_enc/hf_cod_amrwb_fx.c @@ -193,7 +193,7 @@ void hf_cod_fx( L_tmp = L_mult(ener_hf_fx, HF_calc_gain_fx); /*30-q1+q2 */ q2 = sub(q1, q2); /*30-q2 */ #ifdef BASOP_NOGLOB - HF_calc_gain_fx = round_fx_o(Isqrt(L_shl(L_tmp, sub(q2, 20))), &Overflow); /*Q10 */ + HF_calc_gain_fx = round_fx_o(Isqrt(L_shl_sat(L_tmp, sub(q2, 20))), &Overflow); /*Q10 */ #else /* BASOP_NOGLOB */ HF_calc_gain_fx = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 20)))); /*Q10 */ #endif diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 4906be8fce2bc4977104f4950eba48d502515728..4079e27000cc3f1a7e8792fb8cab669c667cd781 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -349,7 +349,11 @@ void hq_lr_enc_fx( frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ L_tmp = Pow2(30, frac1); exp = sub(exp, 30); - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ +#ifdef BASOP_NOGLOB + Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#else + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ +#endif } FOR( i = 0; i < bands_fx; i++ ) @@ -416,13 +420,22 @@ void hq_lr_enc_fx( { IF( GE_16(i,lowband)) { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif } ELSE { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif IF(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) { Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ @@ -532,7 +545,11 @@ void hq_lr_enc_fx( IF(EQ_16(hHQ_core->last_bitalloc_max_band[j++], 1)) { L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = extract_h(L_shl(L_tmp,14));/*Q-2 */ +#ifdef BASOP_NOGLOB + tmp = extract_h( L_shl_sat( L_tmp, 14 ) ); /*Q-2 */ +#else + tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-2 */ +#endif IF(tmp != 0) { exp = norm_s(tmp); @@ -596,11 +613,19 @@ void hq_lr_enc_fx( { IF(GE_16(i,lowband)) { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#endif } ELSE { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ +#ifdef BASOP_NOGLOB + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ +#else + Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ +#endif IF(GT_32(Ep_tmp_fx[i],Ep_peak_fx)) { Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q13 */ @@ -690,7 +715,11 @@ void hq_lr_enc_fx( test(); IF( GE_16(i,lowband)&&add(sub(i,bands_fx),p2a_bands_fx)<0) { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ +#ifdef BASOP_NOGLOB + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ +#else + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ +#endif #ifdef BASOP_NOGLOB Ep_avrg_fx = L_add_o(Ep_avrg_fx,Ep_tmp_fx[i], &Overflow);/*Q15 */ #else /* BASOP_NOGLOB */ @@ -700,11 +729,19 @@ void hq_lr_enc_fx( IF(GE_16(i,highband)) { - enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ +#ifdef BASOP_NOGLOB + enerH_fx = L_add_sat( enerH_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ +#else + enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ +#endif } ELSE IF(GE_16(i,lowband)) { - enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ +#ifdef BASOP_NOGLOB + enerL_fx = L_add_sat( enerL_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ +#else + enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ +#endif } } diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 7ff0116c407f9400d04fa9491f7b0e846b406cbc..6415ba47681fac38b1d47c14d21e3e32d4a3819f 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -253,7 +253,11 @@ static void IGF_CalculateEnvelope(const IGF_ENC_INSTANCE_HANDLE hInstanc zeroNrg = 1; move16(); } - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyR[sfb]), +#ifdef BASOP_NOGLOB + BASOP_Util_Divide_MantExp( round_fx_sat( sfbEnergyR[sfb] ), +#else + BASOP_Util_Divide_MantExp( round_fx( sfbEnergyR[sfb] ), +#endif sfbEnergyR_exp[sfb], width, 15, @@ -490,7 +494,11 @@ static void IGF_ErodeSpectrum(Word16 *highPassEner_e { /* May overflow - just for threshold comparison */ BASOP_SATURATE_WARNING_OFF_EVS - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); +#else + L_tmp = L_add( pPowerSpectrum[i], highPassEner_Ovfl ); +#endif BASOP_SATURATE_WARNING_ON_EVS IF (L_tmp < 0) @@ -515,7 +523,11 @@ static void IGF_ErodeSpectrum(Word16 *highPassEner_e /* May overflow - just for threshold comparison */ BASOP_SATURATE_WARNING_OFF_EVS - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); +#ifdef BASOP_NOGLOB + L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); +#else + L_tmp = L_add( pPowerSpectrum[i], highPassEner_Ovfl ); +#endif BASOP_SATURATE_WARNING_ON_EVS IF (L_tmp < 0) { @@ -622,8 +634,13 @@ static Word16 IGF_getCrest( /* limit crest factor to a lower bound of 1, may overflow */ BASOP_SATURATE_WARNING_OFF_EVS - tmp = shl(-1, sub(15, *crest_exp)); /* build negative threshold */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ + tmp = add_sat( crest, tmp ); +#else + tmp = shl( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ tmp = add(crest, tmp); +#endif BASOP_SATURATE_WARNING_ON_EVS if (tmp < 0) { @@ -855,7 +872,13 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc BASOP_SATURATE_WARNING_OFF_EVS /*SFM = min(2.7f, SFM);*/ /*Overflow possible in shift, intended*/ - SFM = s_min(22118/*2.7f Q13*/,extract_h(L_shr(SFM32,16-29)/*->Q29*/)/*->Q13*/ ); +#ifdef BASOP_NOGLOB + tmp = add_sat( crest, tmp ); + SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr_sat( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); +#else + tmp = add( crest, tmp ); + SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); +#endif BASOP_SATURATE_WARNING_ON_EVS hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ move32(); diff --git a/lib_enc/lp_exc_e_fx.c b/lib_enc/lp_exc_e_fx.c index b118da9d705335728d1dd112389cdf4764b6b454..6cddd32aa137b99adb96af1c5cb5666faef922b2 100644 --- a/lib_enc/lp_exc_e_fx.c +++ b/lib_enc/lp_exc_e_fx.c @@ -419,7 +419,11 @@ Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ /* Note: shl works as shl or shr. */ exp_xx = sub(exp_xx,1); BASOP_SATURATE_WARNING_OFF_EVS - gain_p_snr = round_fx(L_shl(Mpy_32_16_1( 1717986944l/*ACELP_GAINS_CONST Q31*/, tmp), exp_xx)); +#ifdef BASOP_NOGLOB + gain_p_snr = round_fx_sat( L_shl_sat( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_xx ) ); +#else + gain_p_snr = round_fx( L_shl( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_xx ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS gain = s_min(gain, gain_p_snr); diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 57106caa07e19a8ff3491fd1bc9785f09a40778b..7bc52b96ee27893cf13c8fa061716d0be05c099e 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -44,7 +44,21 @@ FOR (i = 0; i < N; i+=4) { depack_4_values(cbp+i_mult(shr(i,2),3), val0, val1, val2, val3) - Tmp[i+0] = mult_r(shl(w[i+0],2),val0); +#ifdef BASOP_NOGLOB + Tmp[i + 0] = mult_r( shl_sat( w[i + 0], 2 ), val0 ); + move16(); + en = L_mac_sat( en, val0, Tmp[i + 0] ); + Tmp[i + 1] = mult_r( shl_sat( w[i + 1], 2 ), val1 ); + move16(); + en = L_mac_sat( en, val1, Tmp[i + 1] ); + Tmp[i + 2] = mult_r( shl_sat( w[i + 2], 2 ), val2 ); + move16(); + en = L_mac_sat( en, val2, Tmp[i + 2] ); + Tmp[i + 3] = mult_r( shl_sat( w[i + 3], 2 ), val3 ); + move16(); + en = L_mac_sat( en, val3, Tmp[i + 3] ); +#else + Tmp[i + 0] = mult_r( shl( w[i + 0], 2 ), val0 ); move16(); en = L_mac(en, val0, Tmp[i+0]); Tmp[i+1] = mult_r(shl(w[i+1],2),val1); @@ -56,6 +70,7 @@ Tmp[i+3] = mult_r(shl(w[i+3],2),val3); move16(); en = L_mac(en, val3, Tmp[i+3]); +#endif } return en; @@ -245,7 +260,11 @@ void msvq_enc_fx move16(); FOR (j=1; jy1y1 + 2 * (*gain_code) * g_coeff->y1y2); */ s = norm_l(L_tmp1); - tmp = round_fx(L_shl(L_tmp1, s)); +#ifdef BASOP_NOGLOB + tmp = round_fx_sat( L_shl_sat( L_tmp1, s ) ); +#else + tmp = round_fx( L_shl( L_tmp1, s ) ); +#endif s = sub(15, s); c_e = BASOP_Util_Add_MantExp(mult_r(tmp, g_coeff->y1y1), add(s, g_coeff->y1y1_e), diff --git a/lib_enc/scale_enc_fx.c b/lib_enc/scale_enc_fx.c index 31ef140c47ca1c228e7372d9bc96dbc8c5d465eb..0f5575d442b998832cf31d52c89ff4793263ff8b 100644 --- a/lib_enc/scale_enc_fx.c +++ b/lib_enc/scale_enc_fx.c @@ -111,7 +111,11 @@ void Preemph_scaled( /* get max of new preemphased samples (L_FRAME+L_FILT) */ L_tmp = L_mult(new_speech[0], QVal); - L_tmp = L_msu(L_tmp, *mem_preemph, mu); +#ifdef BASOP_NOGLOB + L_tmp = L_msu_sat( L_tmp, *mem_preemph, mu ); +#else + L_tmp = L_msu( L_tmp, *mem_preemph, mu ); +#endif L_maxloc = L_abs(L_tmp); FOR (i = 1; i < Lframe; i++) @@ -179,14 +183,23 @@ void Preemph_scaled( L_tmp = L_msu(L_tmp, new_speech[i - 1], mu); #endif /* BASOP_NOGLOB */ L_tmp = L_shl(L_tmp, *Q_new); - new_speech[i] = round_fx(L_tmp); +#ifdef BASOP_NOGLOB + new_speech[i] = round_fx_sat( L_tmp ); +#else + new_speech[i] = round_fx( L_tmp ); +#endif } L_tmp = L_mult(new_speech[0], QVal); - L_tmp = L_msu(L_tmp, *mem_preemph, mu); +#ifdef BASOP_NOGLOB + L_tmp = L_msu_sat( L_tmp, *mem_preemph, mu ); + L_tmp = L_shl_sat(L_tmp, *Q_new); + new_speech[0] = round_fx_sat(L_tmp); +#else + L_tmp = L_msu( L_tmp, *mem_preemph, mu ); L_tmp = L_shl(L_tmp, *Q_new); new_speech[0] = round_fx(L_tmp); - +#endif *mem_preemph = tmp_fixed; move16(); } diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index ad603ae7e7d7a3ac820273b5f9b5554ac2234e01..fdc92195d5ac88c21bf7bfd94466fc765ec06997 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -161,11 +161,12 @@ void set_impulse_fx( #ifdef BASOP_NOGLOB Lrr = L_mac_o(Lrr, gh_fx[0], gh_fx[0], &Overflow); Ldd = L_mac_o(Ldd, gh_fx[0], xn_fx[0], &Overflow); + dd_fx[i] = round_fx_sat( Ldd ); #else /* BASOP_NOGLOB */ Lrr = L_mac(Lrr, gh_fx[0], gh_fx[0]); Ldd = L_mac(Ldd, gh_fx[0], xn_fx[0]); + dd_fx[i] = round_fx( Ldd ); #endif - dd_fx[i] = round_fx(Ldd); rr_fx[i] = L_max(Lrr, 1); move32(); /* move rr and dd into rr[i] and dd[i] */ diff --git a/lib_enc/spec_flatness_fx.c b/lib_enc/spec_flatness_fx.c index 2d07bc15f2df98849a6aafe81bb5796b73be523d..19bdf6cc30415154febb3a0c828177c31a089040 100644 --- a/lib_enc/spec_flatness_fx.c +++ b/lib_enc/spec_flatness_fx.c @@ -301,7 +301,11 @@ SFM_Qtmp = sub(SFM_Qtmp, SPEC_AMP_Q); SFM_Qtmp = sub(SFM_Qtmp, SFM_Q); - sSFM[2] = add(mult(sSFM[2],0x6ccc),shr(mult(SFM,0x1333),SFM_Qtmp)); +#ifdef BASOP_NOGLOB + sSFM[2] = add_sat( mult( sSFM[2], 0x6ccc ), shr_sat( mult( SFM, 0x1333 ), SFM_Qtmp ) ); +#else + sSFM[2] = add( mult( sSFM[2], 0x6ccc ), shr( mult( SFM, 0x1333 ), SFM_Qtmp ) ); +#endif move16(); } diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 794d13bef662cb8172f5ba62c7008ae0f219e7d4..f7bd718e2eeb1143606e3d7e51e0ff444b8cfe52 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -2767,7 +2767,11 @@ static void flux_fx( { IF ( p2v_map[i] != 0 ) { - L_flux = L_add(L_flux,abs_s(sub(Bin_E[i],old_Bin_E[i]))); /*Q7 */ +#ifdef BASOP_NOGLOB + L_flux = L_add_sat( L_flux, abs_s( sub_sat( Bin_E[i], old_Bin_E[i] ) ) ); /*Q7 */ +#else + L_flux = L_add( L_flux, abs_s( sub( Bin_E[i], old_Bin_E[i] ) ) ); /*Q7 */ +#endif } if ( p2v_map[i] != 0 ) { diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index c3420d2e4c3708a054a98f562b9b76f0c1d90de0..5ad0b1749d99808c66f2f955237da688245b88f1 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -469,10 +469,15 @@ static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain index */ dist = L_deposit_l(0); FOR (j=0; jQ20 */ + dist = L_add_sat(dist, L_tmp); +#else + tmp = sub( x[j], *pit ); /*Q10 */ L_tmp = L_mult0(tmp, tmp);/*Q(10+10)->Q20 */ dist = L_add(dist, L_tmp); - +#endif pit++; } @@ -929,7 +934,11 @@ static void freq_weights_fx( { exp = norm_s(tmp); tmp = div_s(shl(1,sub(14,exp)), tmp); /*(21-exp) */ - tmp = shl(tmp, sub(exp, 6)); /*Q15 */ +#ifdef BASOP_NOGLOB + tmp = shl_sat( tmp, sub( exp, 6 ) ); /*Q15 */ +#else + tmp = shl( tmp, sub( exp, 6 ) ); /*Q15 */ +#endif } ELSE { @@ -1628,7 +1637,11 @@ static void calculate_Tonality_fx( l_shift = norm_s(max); FOR( n_coeff=0; n_coeff= 0; i--) { offs32 = Mpy_32_16_1(L_abs(x[i]), gain); /* multiply */ - offs32 = L_shl(offs32, s); /* convert to 15Q16 */ +#ifdef BASOP_NOGLOB + offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r_sat(offs32, offset, 1); /* add offset and truncate */ +#else + offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ tmp16 = mac_r(offs32, offset, 1); /* add offset and truncate */ +#endif if (x[i] < 0) tmp16 = negate(tmp16); /* restore sign */ xq[i] = tmp16; @@ -869,7 +874,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( tmp32, tmp ) ); +#else + sqGain = round_fx( L_shl( tmp32, tmp ) ); +#endif sqGain_e = sub(sqGain_e, tmp); /* divide */ @@ -1446,7 +1455,11 @@ void tcx_encoder_memory_update_fx( Residu3_fx(Ai+(st->nb_subfr-1)*(M+1), synth + sub(L_frame_glob, 1), &tmp, 1, Q_new+shift-1); LPDmem->mem_w0 =sub(wsig[sub(L_frame_glob, 1)], tmp); move16(); - LPDmem->mem_w0 =shr(LPDmem->mem_w0, shift); /*Qnew-1*/ +#ifdef BASOP_NOGLOB + LPDmem->mem_w0 = shr_sat( LPDmem->mem_w0, shift ); /*Qnew-1*/ +#else + LPDmem->mem_w0 = shr( LPDmem->mem_w0, shift ); /*Qnew-1*/ +#endif } @@ -1643,8 +1656,11 @@ Word16 tcx_res_Q_gain_fx( } /* bring sqGain to same exponent */ - sqGain = shr(sqGain, sub(gain_reQ_e, sqGain_e)); - +#ifdef BASOP_NOGLOB + sqGain = shr_sat( sqGain, sub( gain_reQ_e, sqGain_e ) ); +#else + sqGain = shr( sqGain, sub( gain_reQ_e, sqGain_e ) ); +#endif FOR (bits=0; bits < TCX_RES_Q_BITS_GAIN; bits++) { IF (LT_16(sqGain, gain_reQ)) diff --git a/lib_enc/tfa_enc_fx.c b/lib_enc/tfa_enc_fx.c index 66ee96687bed9da86de3d610f05d3c48422ae776..0dba7d0c9e26fa9dcd4a709c16dd63a481f2cd58 100644 --- a/lib_enc/tfa_enc_fx.c +++ b/lib_enc/tfa_enc_fx.c @@ -31,7 +31,11 @@ void tfaCalcEnv_fx( enr[i] = L_deposit_l(0); FOR (j=0; j= 0x2000000 */ +#else + L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ move16(); facs[iFilter][iSubdivisions] = div_s(0x2000, round_fx(L_tmp)); /* L_tmp is >= 0x2000000 */ +#endif } } diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 68a05f32bf3b5cbc98a75288238b849891049801..875d7ff0bb78b2986225727516f2cb8a0a39a3a2 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -688,7 +688,11 @@ static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvail FOR (k = 0; k < w; k++) { tmp = shr(input[k], SUBBLOCK_NRG_E/2); - accu = L_mac0(accu, tmp, tmp); +#ifdef BASOP_NOGLOB + accu = L_mac0_sat( accu, tmp, tmp ); +#else + accu = L_mac0( accu, tmp, tmp ); +#endif } move32(); @@ -705,7 +709,11 @@ static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvail FOR (; k < k2; k++) { tmp = shr(input[k], SUBBLOCK_NRG_E/2); - accu = L_mac0(accu, tmp, tmp); +#ifdef BASOP_NOGLOB + accu = L_mac0_sat( accu, tmp, tmp ); +#else + accu = L_mac0( accu, tmp, tmp ); +#endif } move32(); pSubblockNrg[w] = accu; diff --git a/lib_enc/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index 3183b65217c95591a3fbd06492000d82c2acc0d9..b6d7779e887322a146f2e3f7b628e0418c0b136e 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -33,11 +33,12 @@ void updt_tar_fx( { /*x2[i] = x[i] - gain*y[i];*/ L_tmp = L_mult(x[i], 16384); - L_tmp = L_msu(L_tmp, y[i], gain); #ifdef BASOP_NOGLOB - x2[i] = extract_h(L_shl_o(L_tmp, 1, &Overflow)); + L_tmp = L_msu_sat( L_tmp, y[i], gain ); + x2[i] = extract_h( L_shl_o( L_tmp, 1, &Overflow ) ); #else /* BASOP_NOGLOB */ - x2[i] = extract_h(L_shl(L_tmp, 1)); + L_tmp = L_msu( L_tmp, y[i], gain ); + x2[i] = extract_h( L_shl( L_tmp, 1 ) ); #endif } return; diff --git a/lib_enc/vlpc_1st_cod_fx.c b/lib_enc/vlpc_1st_cod_fx.c index 7c633039bbf79f1ef0b470db6bc9213d7bf5e7b9..afbb039233b223123a12545c420eac1e3e8c7b03 100644 --- a/lib_enc/vlpc_1st_cod_fx.c +++ b/lib_enc/vlpc_1st_cod_fx.c @@ -55,14 +55,26 @@ static void lsf_weight( FOR (i=1; i<(M-2); i+=2) /*for (i=1; i<(M-2); i+=2)*/ { inv_di1 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*0Q15*/ /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ - w[i-1] = add(inv_di0,inv_di1); +#ifdef BASOP_NOGLOB + w[i - 1] = add_sat( inv_di0, inv_di1 ); +#else + w[i - 1] = add( inv_di0, inv_di1 ); +#endif move16(); /*0Q15*/ /*w[i-1] = inv_di0 + inv_di1;*/ inv_di0 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i+1],lsfq[i]))); /*0Q15*/ /*inv_di0 = 1.0f / (lsfq[i+1] - 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(); /*0Q15*/ /*w[i] = inv_di1 + inv_di0;*/ } inv_di1 = div_s(ISF_ONE, s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ - w[i-1] = add(inv_di0,inv_di1); +#ifdef BASOP_NOGLOB + w[i - 1] = add_sat( inv_di0, inv_di1 ); +#else + w[i - 1] = add( inv_di0, inv_di1 ); +#endif 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]);*/ #ifdef BASOP_NOGLOB diff --git a/lib_enc/voiced_enc_fx.c b/lib_enc/voiced_enc_fx.c index 3281637ee9911d469fe9e8e90f59a0cb2592c9b6..fa9c51bd58acdbac5834c19d55f61a356bf5adff 100644 --- a/lib_enc/voiced_enc_fx.c +++ b/lib_enc/voiced_enc_fx.c @@ -515,7 +515,11 @@ ivas_error ppp_voiced_encoder_fx( tmp = div_s(fracb,fraca); exp = sub(expb,expa); - sp_enratio_fx = L_shl(tmp, exp); /* Q15 */ +#ifdef BASOP_NOGLOB + sp_enratio_fx = L_shl_sat( tmp, exp ); /* Q15 */ +#else + sp_enratio_fx = L_shl( tmp, exp ); /* Q15 */ +#endif } } ELSE diff --git a/lib_enc/waveadjust_fec_cod_fx.c b/lib_enc/waveadjust_fec_cod_fx.c index 988d7564c2c8e2fa883587eeba5c35a247ac9ddd..eb5b8953dd263a4271613fd53b783c0580fa2e1d 100644 --- a/lib_enc/waveadjust_fec_cod_fx.c +++ b/lib_enc/waveadjust_fec_cod_fx.c @@ -38,7 +38,11 @@ Word32 SFM_Cal_fx(Word32 magn[], Word16 n) /* sum(log2(magn(i))) */ sumLogMagn =L_add(sumLogMagn, logMagn); /* Q8 */ - sumMagn =L_add(sumMagn, magn_abs); +#ifdef BASOP_NOGLOB + sumMagn = L_add_sat( sumMagn, magn_abs ); +#else + sumMagn = L_add( sumMagn, magn_abs ); +#endif } IF(EQ_32(sumMagn,MAX_32))