From 26979b2e184129c8915cf304b16acc6d9c769e72 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 23 Dec 2024 10:56:11 +0530 Subject: [PATCH 1/2] MLD improvements and Q-info updates for lib_enc --- lib_com/edct_fx.c | 61 ++++++++++++ lib_com/ivas_spar_com.c | 4 + lib_com/options.h | 1 + lib_com/prot_fx.h | 7 ++ lib_enc/analy_sp_fx.c | 2 +- lib_enc/ari_hm_enc_fx.c | 37 +++++--- lib_enc/arith_coder_enc_fx.c | 16 +++- lib_enc/avq_cod_fx.c | 68 +++++++------- lib_enc/bass_psfilter_enc_fx.c | 11 ++- lib_enc/bw_detect_fx.c | 61 ++++++++---- lib_enc/cng_enc.c | 29 +++--- lib_enc/cng_enc_fx.c | 143 +++++++++++++++++++---------- lib_enc/cod2t32_fx.c | 131 +++++++++++--------------- lib_enc/cod4t64_fast.c | 37 ++++---- lib_enc/cod4t64_fx.c | 138 +++++++++++++++------------- lib_enc/cod_ace_fx.c | 46 ++++++---- lib_enc/cod_tcx.c | 83 ++++++++++------- lib_enc/cod_tcx_fx.c | 18 ++-- lib_enc/ext_sig_ana_fx.c | 6 +- lib_enc/find_tilt.c | 2 +- lib_enc/find_uv.c | 19 ++-- lib_enc/ivas_core_pre_proc.c | 4 +- lib_enc/ivas_core_pre_proc_front.c | 3 +- lib_enc/ivas_cpe_enc.c | 7 +- lib_enc/nois_est_fx.c | 3 +- lib_enc/prot_fx_enc.h | 2 +- 26 files changed, 562 insertions(+), 377 deletions(-) diff --git a/lib_com/edct_fx.c b/lib_com/edct_fx.c index 28a5ed44a..301b66666 100644 --- a/lib_com/edct_fx.c +++ b/lib_com/edct_fx.c @@ -228,6 +228,67 @@ void edct_fx( return; } +void edct_ivas_fx( + const Word32 *x, /* i : input signal Qq */ + Word32 *y, /* o : output transform Qq */ + Word16 length, /* i : length Q0*/ + Word16 *q /* i : Q value of input signal */ +) +{ + Word16 i; + const Word16 *edct_table; /*Q16 */ + Word32 re[L_FRAME_PLUS / 2]; + Word32 im[L_FRAME_PLUS / 2]; + Word32 L_tmp; + Word16 tmp; + Word16 len1; + + edct_table = get_edct_table( length, q ); /*q*/ + len1 = shr( length, 1 ); /*Q0*/ + /* Twiddling and Pre-rotate */ + FOR( i = 0; i < len1; i++ ) + { + L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Q(q+1) */ + re[i] = Madd_32_16( L_tmp, x[( length - ( 1 + ( i * 2 ) ) )], edct_table[( len1 - ( 1 + i ) )] ); /*Q(q+1) */ + move32(); + + L_tmp = Mult_32_16( x[( length - ( 1 + ( i * 2 ) ) )], edct_table[i] ); /*Q(q+1) */ + im[i] = Msub_32_16( L_tmp, x[( i * 2 )], edct_table[( len1 - ( 1 + i ) )] ); /*Q(q+1) */ + move32(); + } + + *q = sub( 31, *q ); + move16(); + tmp = sub( s_min( getScaleFactor32( re, len1 ), getScaleFactor32( im, len1 ) ), find_guarded_bits_fx( len1 ) ); + scale_sig32( re, len1, tmp ); + scale_sig32( im, len1, tmp ); + + fft_fx( re, im, len1, 1 ); + *q = sub( *q, tmp ); + move16(); + + tmp = div_s( 4, length ); /*Q17 */ + tmp = round_fx( L_mult( tmp, 19302 /*0.75f * EVS_PI in Q13*/ ) ); /*Q15 */ + FOR( i = 0; i < len1; i++ ) + { + L_tmp = Msub_32_16( re[i], im[i], tmp ); + im[i] = Madd_32_16( im[i], re[i], tmp ); /*Q(q+1) */ + re[i] = L_tmp; /*Q(q+1) */ + move32(); + move32(); + } + FOR( i = 0; i < len1; i++ ) + { + y[2 * i] = L_add( Mult_32_16( re[i], edct_table[i] ), Mult_32_16( im[i], edct_table[( len1 - ( 1 + i ) )] ) ); /*Q(q+2)*/ + move32(); + y[( length - ( 1 + ( i * 2 ) ) )] = L_sub( Mult_32_16( re[i], edct_table[( len1 - ( 1 + i ) )] ), Mult_32_16( im[i], edct_table[i] ) ); /*Q(q+2)*/ + move32(); + } /*Q(q-2) */ + + *q = sub( 31 + 2, *q ); + move16(); + return; +} /*-------------------------------------------------------------------------* * FUNCTION : edst_fx() * diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 7ab41d5ed..362c1c9ed 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2633,7 +2633,11 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( test(); IF( W_norm( re ) == 0 || W_norm( recon_uu_re[i][j] ) == 0 ) { +#ifdef FIX_ISSUE_1122 + recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], 1 ); // q_recon_uu_re[i][j] - 1 +#else re1[m] = L_shr( re1[m], 1 ); // q_recon_uu_re[i][j]-1 +#endif move32(); q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); move16(); diff --git a/lib_com/options.h b/lib_com/options.h index 7fd5f19dc..68c2542f2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -103,4 +103,5 @@ #define FIX_1110_OPTIM_DIRAC_DECORR_PROC /* FhG: optimize ivas_dirac_dec_decorr_process() */ #define FIX_1100_REMOVE_LPC_RESCALING /* VA: Remove the rescaling of LPC coefficient to Q12 as residu and syn-filt are already taking care of it*/ +#define FIX_ISSUE_1122 /* Ittiam: Fix issue 1122: corrected incorrect scaling of a buffer leading to incorrect metadata bits */ #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 13ab9bebd..b1130115e 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4437,6 +4437,13 @@ void edct_fx( Word16 *q /* i : Q value of i signal */ ); +void edct_ivas_fx( + const Word32 *x, /* i : input signal Qq */ + Word32 *y, /* o : output transform Qq */ + Word16 length, /* i : length Q0*/ + Word16 *q /* i : Q value of input signal */ +); + void edst_fx( const Word32 *x, /* i : i signal Qq */ Word32 *y, /* o : output transform Qq */ diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index d2e34b012..e025bee07 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -555,7 +555,7 @@ void ivas_analy_sp_fx( /* 10.0*log((float)tmp) */ /* 10.0*logf(2) in Q28 = 1860652798 */ - move16(); + move16(); } } diff --git a/lib_enc/ari_hm_enc_fx.c b/lib_enc/ari_hm_enc_fx.c index 3e6519a3b..66b53bc6d 100644 --- a/lib_enc/ari_hm_enc_fx.c +++ b/lib_enc/ari_hm_enc_fx.c @@ -87,7 +87,7 @@ Word16 EncodeIndex_ivas_fx( * *-------------------------------------------------------------------*/ static Word16 SearchPeriodicityIndex_Single( - const Word16 AbsMdct3[], + const Word16 AbsMdct3[], // Qx const Word16 NumToConsider, const Word32 Lag, const Word16 FractionalResolution ) @@ -131,7 +131,7 @@ static Word16 SearchPeriodicityIndex_Single( * *-------------------------------------------------------------------*/ static void SearchPeriodicityIndex_Range( - const Word16 AbsMdct3[], + const Word16 AbsMdct3[], // Qx const Word16 NumToConsider, const Word16 Lo, const Word16 Hi, @@ -139,7 +139,8 @@ static void SearchPeriodicityIndex_Range( const Word16 Adj, const Word16 Spacing, Word16 *PeriodicityIndex, - Word16 *Score ) + Word16 *Score // Q0 +) { Word16 Index, BestIndex; Word16 CurrentScore, BestScore; @@ -194,7 +195,7 @@ static void SearchPeriodicityIndex_Range( B = add( BestIndex, shr( Spacing, 1 ) ); - FOR( Index = add( BestIndex, 1 ); Index <= B; ++Index ) + FOR( Index = BestIndex + 1; Index <= B; ++Index ) { CurrentScore = SearchPeriodicityIndex_Single( AbsMdct3, @@ -225,7 +226,7 @@ Word16 SearchPeriodicityIndex_fx( Word16 NumToConsider, /* i : Number of coefficients */ const Word16 TargetBits, /* i : Target bit budget (excl. Done flag) */ const Word16 LtpPitchLag, /* i : TCX-LTP pitch */ - const Word16 LtpGain, /* i : LTP gain */ + const Word16 LtpGain, /* i : LTP gain Q15 */ Word16 *RelativeScore /* o : Energy concentration factor (2Q13) */ ) { @@ -244,11 +245,12 @@ Word16 SearchPeriodicityIndex_fx( Word32 tmp32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Debug init (not instrumented) */ C = -3000; - + move32(); PeriodicityIndex = 0; move16(); Score = -1; @@ -264,18 +266,22 @@ Word16 SearchPeriodicityIndex_fx( { C = L_shl( L_abs( Mdct[i + 1] ), s ); AbsMdct3[i] = round_fx( L_add( L_add( A, B ), C ) ); + move16(); A = L_shl( L_abs( Mdct[i + 2] ), s ); AbsMdct3[i + 1] = round_fx( L_add( L_add( A, B ), C ) ); + move16(); B = L_shl( L_abs( Mdct[i + 3] ), s ); AbsMdct3[i + 2] = round_fx( L_add( L_add( A, B ), C ) ); + move16(); } IF( LT_16( i, sub( NumToConsider, 1 ) ) ) { C = L_shl( L_abs( Mdct[i + 1] ), s ); AbsMdct3[i] = round_fx( L_add( L_add( A, B ), C ) ); + move16(); } IF( LT_16( i, sub( NumToConsider, 2 ) ) ) @@ -283,6 +289,7 @@ Word16 SearchPeriodicityIndex_fx( A = L_shl( L_abs( Mdct[i + 2] ), s ); assert( C != -3000 ); AbsMdct3[i + 1] = round_fx( L_add( L_add( A, B ), C ) ); + move16(); } AbsTotal = L_deposit_l( 0 ); @@ -479,8 +486,8 @@ Word16 SearchPeriodicityIndex_fx( *-------------------------------------------------------------------*/ static void PeakFilter( - const Word32 x[], /* i : absolute spectrum */ - Word32 y[], /* O : filtered absolute spectrum, must not alias x[] */ + const Word32 x[], /* i : absolute spectrum Qx */ + Word32 y[], /* O : filtered absolute spectrum, must not alias x[] Q(x-4)*/ const Word16 L_frame /* i : number of spectral lines */ ) { @@ -491,7 +498,7 @@ static void PeakFilter( flen = shr( L_frame, 4 ); /* m = kPeakElevationThreshold / (float)(2*flen + 1); */ - m = shr( div_s( 8 /*kPeakElevationThreshold Q3*/, add( shl( flen, 1 ), 1 ) ), 3 ); + m = shr( div_s( 8 /*kPeakElevationThreshold Q3*/, add( shl( flen, 1 ), 1 ) ), 3 ); // Q15 a = L_deposit_l( 0 ); FOR( i = 0; i < flen; ++i ) @@ -501,14 +508,14 @@ static void PeakFilter( FOR( i = 0; i < flen; ++i ) { - y[i] = L_max( 0, L_sub( L_shr( x[i], 4 ), Mpy_32_16_1( a, m ) ) ); + y[i] = L_max( 0, L_sub( L_shr( x[i], 4 ), Mpy_32_16_1( a, m ) ) ); // Q(x-4) move32(); a = L_add( a, L_shr( x[i + flen], 4 ) ); } sub( 0, 0 ); FOR( ; i < L_frame - flen; ++i ) { - y[i] = L_max( 0, L_sub( L_shr( x[i], 4 ), Mpy_32_16_1( a, m ) ) ); + y[i] = L_max( 0, L_sub( L_shr( x[i], 4 ), Mpy_32_16_1( a, m ) ) ); // Q(x-4) move32(); a = L_sub( a, L_shr( x[i - flen], 4 ) ); a = L_add( a, L_shr( x[i + flen], 4 ) ); @@ -516,7 +523,7 @@ static void PeakFilter( FOR( ; i < L_frame; ++i ) { - y[i] = L_max( 0, L_sub( L_shr( x[i], 4 ), Mpy_32_16_1( a, m ) ) ); + y[i] = L_max( 0, L_sub( L_shr( x[i], 4 ), Mpy_32_16_1( a, m ) ) ); // Q(x-4) move32(); a = L_sub( a, L_shr( x[i - flen], 4 ) ); } @@ -598,7 +605,7 @@ static Word32 tcx_hm_get_re( *-------------------------------------------------------------------*/ static void tcx_hm_quantize_gain( - const Word32 x[], /* i: absolute spectrum Q31-e */ + const Word32 x[], /* i: absolute spectrum Q31-x_e */ const Word16 *x_e, /* i: absolute spectrum exponent Q0 */ const Word32 env[], /* i: envelope Q16 */ const Word32 lag, /* i: pitch lag Q0 */ @@ -645,6 +652,7 @@ static void tcx_hm_quantize_gain( FOR( i = 0; i < L_frame; ++i ) { x16[i] = extract_h( L_shl( x[i], s_x ) ); + move16(); } be = tcx_hm_get_re( x16, *gain, lag, fract_res, p, env, L_frame ); @@ -698,7 +706,8 @@ static void tcx_hm_quantize_gain( /* Minimum selection, pe is Q14 */ IF( LT_32( L_shl( Mpy_32_16_1( e, pe ), 1 ), be ) ) { - be = L_add( e, 0 ); + be = e; + move32(); *gain_idx = g; move16(); *gain = qGains[s][g]; diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 6b137f31e..40c1c6b7b 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -50,6 +50,7 @@ static Word16 tcx_arith_estimate_scale( Word32 L_tmp, accu; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -195,19 +196,21 @@ static Word16 tcx_arith_find_max_scale( /* Q15-e * Heap heap = { { { 0, 0 } }, 0 }; /* silence a compiler warning */ Word16 tmpi1, tmpi2; const Word32 limit = -325614240l /*-9.70406052784f Q25*/; /* = ln(1/16384): log of smallest allowed probability */ - + move32(); /* Find the top most offending lines according to probability estimates */ FOR( i = 0; i < kMaxNumHeapElems; i++ ) { heap.mElem[i].mIndex = 0; move16(); heap.mElem[i].mScore = L_deposit_l( 0 ); + move32(); } tmp = add( shl( kMaxNumHeapElems, 1 ), 1 ); FOR( ; i < tmp; i++ ) { heap.mElem[i].mScore = L_deposit_h( 0x7FFF ); + move32(); } FOR( k = 0; k < L_frame; k++ ) @@ -374,6 +377,7 @@ static Word16 tcx_arith_rateloop( Word32 tmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -414,13 +418,14 @@ static Word16 tcx_arith_rateloop( L_tmp = L_mac( 0x7FFFFFFF, exps[k], (Word16) 0x8000 ); /* Q31 */ L_tmp = L_negate( BASOP_Util_Log2( L_tmp ) ); /* Q25 */ fixed_bits[0][k] = round_fx( L_tmp ); /* Q9 */ - + move16(); /* fixed_bits[1][k] = 1 - s*0.5f*LOG2_E - log2f(1 - (exps[k]/65536.0f) * (exps[k]/65536.0f)); */ L_tmp = L_msu( 0x7FFFFFFF, exps[k], exps[k] ); /* Q31 */ L_tmp = BASOP_Util_Log2( L_tmp ); /* Q25 */ L_tmp = L_sub( 1 << 25, L_tmp ); L_tmp = L_sub( L_tmp, L_shl( L_mult0( mult_r( envelope[k], LOG2_E ), 1 << 10 ), envelope_e ) ); fixed_bits[1][k] = round_fx( L_tmp ); /* Q9 */ + move16(); } tmp2 = L_msu0( L_sub( max_complexity, 48 ), L_frame, 11 ); @@ -708,6 +713,8 @@ void tcx_arith_encode_envelope_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; Flag Carry = 0; + move32(); + move32(); #endif assert( L_spec <= N_MAX_ARI ); @@ -730,6 +737,7 @@ void tcx_arith_encode_envelope_fx( FOR( k = 0; k < L_spec; k++ ) { signs[k] = extract_l( L_lshr( spectrum[k], 31 ) ); + move16(); if ( spectrum[k] < 0 ) { spectrum[k] = L_abs( spectrum[k] ); @@ -767,6 +775,7 @@ void tcx_arith_encode_envelope_fx( FOR( k = 0; k < L_spec; k++ ) { exponents[k] = round_fx( expfp( envelope[k], tmp ) ); + move16(); } scale = tcx_arith_rateloop( spectrum, *spectrum_e, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &( hTcxEnc->tcx_target_bits_fac ), &scale_e ); @@ -782,10 +791,12 @@ void tcx_arith_encode_envelope_fx( { /* quantise using dead-zone */ q_spectrum[k] = extract_h( L_add( L_shl( Mpy_32_16_1( spectrum[k], scale ), tmp ), L_tmp ) ); + move16(); } /* Final encoding */ *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm ); + move16(); /* Multiply back the signs */ L_tmp2 = L_deposit_l( 0 ); @@ -810,4 +821,5 @@ void tcx_arith_encode_envelope_fx( /* noise filling seed */ *nf_seed = extract_l( L_tmp2 ); + move16(); } diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index 094d3fd78..c5a101981 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -16,7 +16,7 @@ * Local prototypes *-------------------------------------------------------------------*/ static void wrte_cv( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits ); -static void wrte_cv_ivas( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits ); +static void wrte_cv_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits ); /*-------------------------------------------------------------------* * Function AVQ_cod() * @@ -25,7 +25,7 @@ static void wrte_cv_ivas( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i *-------------------------------------------------------------------*/ void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ + const Word16 xri[], /* i: vector to quantize Qx*/ Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ const Word16 NB_BITS, /* i: number of allocated bits */ const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ @@ -72,7 +72,8 @@ void AVQ_cod_fx( /* o: comfort noise gain factor Ltmp = L_mac( Ltmp, f_ebits, 1 ); Ltmp = L_add( L_shl( Ltmp, 6 ), L_shl( Ltmp, 4 ) ); /* Mult by 5.0 and then by 16 (To go to Q4). Do it using Mult by 80 (which is 64+16) */ ebits[l] = round_fx( Ltmp ); /*Q4*/ - tot_est_bits = add( tot_est_bits, shr( ebits[l], 4 ) ); + move16(); + tot_est_bits = add( tot_est_bits, shr( ebits[l], 4 ) ); // Q0 } test(); test(); @@ -89,12 +90,12 @@ void AVQ_cod_fx( /* o: comfort noise gain factor /* estimate gain according to number of bits allowed */ /* start at the middle (offset range = 0 to 255.75) Q6 */ - fac = 2048; + fac = 2048; // 128.0f in Q4 move16(); offset = 0; move16(); - Ltmp = L_mult( 31130, sub( NB_BITS, Nsv ) ); /* (1810 - 8 - 1152/8)*.95*/ + Ltmp = L_mult( 31130 /*.95f in Q15*/, sub( NB_BITS, Nsv ) ); /* (1810 - 8 - 1152/8)*.95*/ nbits_max = round_fx( L_shl( Ltmp, 4 ) ); /* tree search with 10 iterations : offset with step of 0.25 bits (0.3 dB) */ @@ -115,7 +116,7 @@ void AVQ_cod_fx( /* o: comfort noise gain factor { offset = sub( offset, fac ); } - fac = mult( fac, 16384 ); + fac = mult( fac, 16384 /*.5 in Q15*/ ); } Ltmp = L_shr( L_mult( offset, 13107 ), 6 ); /* offset((2^21)/160 */ @@ -141,7 +142,7 @@ void AVQ_cod_fx( /* o: comfort noise gain factor l_8 = shl( l, 3 ); FOR( i = 0; i < 8; i++ ) { - x1[i] = L_shl( L_mult( xri[l_8 + i], gain_inv ), e_tmp ); + x1[i] = L_shl( L_mult( xri[l_8 + i], gain_inv ), e_tmp ); // Q15 move32(); } @@ -149,7 +150,7 @@ void AVQ_cod_fx( /* o: comfort noise gain factor FOR( i = 0; i < 8; i++ ) { - xriq[l_8 + i] = c[i]; + xriq[l_8 + i] = c[i]; // Q0 move16(); } } @@ -157,7 +158,7 @@ void AVQ_cod_fx( /* o: comfort noise gain factor /* round_fx bit allocations and save */ FOR( i = 0; i < Nsv; i++ ) { - xriq[( Nsv * 8 ) + i] = shl( ebits[i], 7 - 4 ); + xriq[( Nsv * 8 ) + i] = shl( ebits[i], 7 - 4 ); // Q0 move16(); } @@ -229,8 +230,8 @@ void AVQ_encmux_fx( /* sort subvectors by estimated bit allocations in decreasing order */ t = kv; - move16(); /* reuse vector to save memory */ - move16(); /*ptr init*/ + /* reuse vector to save memory */ + /*ptr init*/ FOR( i = 0; i < Nsv; i++ ) { t[i] = xriq[8 * Nsv + i]; @@ -325,11 +326,12 @@ void AVQ_encmux_fx( move16(); move16(); move16(); + move16(); if ( EQ_16( avq_bit_sFlag, 2 ) ) { j = add( i, 1 ); } - WHILE( LT_16( i, Nsvm1 ) ) + WHILE( i < Nsvm1 ) { svOrder[i] = j; move16(); @@ -414,7 +416,7 @@ void AVQ_encmux_fx( } /* for */ /* Bit Saving Solution */ test(); - IF( avq_bit_sFlag > 0 && bits > 8 ) + IF( avq_bit_sFlag > 0 && GT_16( bits, 8 ) ) { // PMT("code not validated yet") bitsMod = s_and( bits, 4 /*bits%5*/ ); @@ -453,7 +455,7 @@ void AVQ_encmux_fx( bitsMod = 0; move16(); } - ELSE IF( nq_est > 4 && ( ( bitsMod == 0 && nullVec > 3 && nullVec < 6 ) || ( bitsMod == 4 && nullVec == 5 ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/ + ELSE IF( nq_est > 4 && ( ( bitsMod == 0 && GT_16( nullVec, 3 ) && GT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/ { overflow = 0; move16(); @@ -627,8 +629,8 @@ void AVQ_encmux_ivas_fx( /* sort subvectors by estimated bit allocations in decreasing order */ t = kv; - move16(); /* reuse vector to save memory */ - move16(); /*ptr init*/ + /* reuse vector to save memory */ + /*ptr init*/ FOR( i = 0; i < Nsv; i++ ) { t[i] = xriq[8 * Nsv + i]; @@ -723,6 +725,7 @@ void AVQ_encmux_ivas_fx( move16(); move16(); move16(); + move16(); if ( EQ_16( avq_bit_sFlag, 2 ) ) { j = add( i, 1 ); @@ -814,17 +817,18 @@ void AVQ_encmux_ivas_fx( bits = sub( bits, 1 ); } - wrte_cv_ivas( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[k * 8], &bits ); + wrte_cv_ivas_fx( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[k * 8], &bits ); } } /* for */ /* Bit Saving Solution */ test(); - IF( avq_bit_sFlag > 0 && bits > 8 ) + IF( avq_bit_sFlag > 0 && GT_16( bits, 8 ) ) { // PMT("code not validated yet") // bitsMod = bits%5; bitsMod = bits; - WHILE( GE_16( bitsMod, 5 ) ) + move16(); + WHILE( bitsMod >= 5 ) { bitsMod = sub( bitsMod, 5 ); } @@ -837,13 +841,13 @@ void AVQ_encmux_ivas_fx( move16(); FOR( j = i; j < Nsv - 1; j++ ) { - if ( nq[svOrder[j]] == 0 ) + IF( nq[svOrder[j]] == 0 ) { nullVec = add( nullVec, 1 ); } } /*nq_est = bits / 5;*/ - nq_est = mult( bits, 6554 ); + nq_est = mult( bits, 6554 /*1/5 in Q15*/ ); assert( nq_est == bits / 5 ); test(); @@ -856,7 +860,7 @@ void AVQ_encmux_ivas_fx( test(); test(); test(); - test(); + IF( ( bitsMod > 0 || ( EQ_16( nullVec, 4 ) && EQ_16( nq_est, 5 ) ) ) && NE_16( bitsMod, 4 ) && GE_16( add( bits, nullVec ), add( add( shl( nq_est, 2 ), nq_est ), 4 ) ) /*5 * nq_est + 4*/ && nq[svOrder[Nsvm2]] == 0 ) /* detect need for dummy bits */ { dummy_bits = sub( 5, bitsMod ); @@ -864,12 +868,12 @@ void AVQ_encmux_ivas_fx( bitsMod = 0; move16(); } - ELSE IF( nq_est > 4 && ( ( bitsMod == 0 && nullVec > 3 && nullVec < 6 ) || ( bitsMod == 4 && nullVec == 5 ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/ + ELSE IF( GT_16( nq_est, 4 ) && ( ( bitsMod == 0 && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/ { overflow = 0; move16(); tmp = add( bitsMod, nullVec ); - WHILE( GE_16( tmp, 5 ) ) + WHILE( tmp >= 5 ) { tmp = sub( tmp, 5 ); } @@ -896,18 +900,18 @@ void AVQ_encmux_ivas_fx( } bits = add( bits, overflow ); /*add fake bit */ unused_bits = sub( bits, add( shl( nq[i], 2 ), nq[i] ) ); - if ( nq[i] == 0 ) /*no bit savings*/ + IF( nq[i] == 0 ) /*no bit savings*/ { unused_bits = sub( unused_bits, 1 ); /*Stop Bit*/ } /*unused_bits_idx = (int16_t)unused_bits / 5;*/ IF( unused_bits >= 0 ) { - unused_bits_idx = mult( unused_bits, 6554 ); + unused_bits_idx = mult( unused_bits, 6554 /*1/5 in Q15*/ ); } ELSE { - unused_bits_idx = negate( mult( negate( unused_bits ), 6554 ) ); + unused_bits_idx = negate( mult( negate( unused_bits ), 6554 /*1/5 in Q15*/ ) ); } assert( unused_bits_idx == unused_bits / 5 ); unusedbitsFlag = 0; @@ -951,7 +955,7 @@ void AVQ_encmux_ivas_fx( /*Compute AVQ code book number from unused Bits */ bit_tmp = add( unusedbitsFlag, unused_bits_idx ); /*nq_est = (int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx)));*/ - nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); + nq_est = mult( 6554 /*.2 in Q15*/, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); assert( (int16_t) ceil( 0.2f * ( bits - 5 * ( unusedbitsFlag + unused_bits_idx ) ) ) == nq_est ); if ( EQ_16( nq_est, 1 ) ) @@ -963,7 +967,7 @@ void AVQ_encmux_ivas_fx( bits = sub( bits, j ); - if ( nq_est != 0 ) + IF( nq_est != 0 ) { bits = sub( bits, 1 ); } @@ -971,11 +975,11 @@ void AVQ_encmux_ivas_fx( move16(); /* write codebook indices (rank I and event. Voronoi index kv) */ - wrte_cv_ivas( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[i * 8], &bits ); + wrte_cv_ivas_fx( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[i * 8], &bits ); bits = sub( bits, dummy_bits ); - if ( NE_16( bitsMod, 4 ) ) + IF( NE_16( bitsMod, 4 ) ) { bits = add( bits, bitsMod ); } @@ -1141,7 +1145,7 @@ static void wrte_cv( return; } -static void wrte_cv_ivas( +static void wrte_cv_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 nq, /* i : AVQ nq index */ const Word16 i_ind, /* i : Base Bitstream index */ diff --git a/lib_enc/bass_psfilter_enc_fx.c b/lib_enc/bass_psfilter_enc_fx.c index df52213c2..e43fa6bc6 100644 --- a/lib_enc/bass_psfilter_enc_fx.c +++ b/lib_enc/bass_psfilter_enc_fx.c @@ -38,6 +38,7 @@ Word16 bass_pf_enc_fx( Word32 ener2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -69,10 +70,12 @@ Word16 bass_pf_enc_fx( move16(); s3 = s4 = 0; /* initialization of s3 and s4 to suppress compiler warnings; s3 and s4 get initialized for i_subfr == 0 */ - + move16(); + move16(); nrg1 = nrg2 = 0; /* initialization fo nrg1 and nrg2 to suppress compiler warnings; nrg1 and nrg1 get initialized for i_subfr == 0 */ - + move32(); + move32(); FOR( i_subfr = 0; i_subfr < l_frame; i_subfr += l_subfr ) { T = T_sf[sf]; @@ -218,7 +221,7 @@ Word16 bass_pf_enc_fx( } mem_bpf->lp_error_ener = L_add( Mpy_32_16_1( L_sub( mem_bpf->lp_error_ener, ener2 ), 32440 /*0.99f Q15*/ ), ener2 ); /* 15Q16 */ - + move32(); st = add( st, 6 ); ener2 = L_sub( mem_bpf->lp_error_ener, L_deposit_h( sub( 31, st ) ) ); IF( ener2 >= 0 ) @@ -282,6 +285,7 @@ Word16 bass_pf_enc_fx( tmp32 = L_mult0( tmp16, syn[i + i_subfr] ); tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); noise_in[i] = round_fx( L_shl( tmp32, s2 ) ); /* Q0+s2 */ + move16(); #ifdef BASOP_NOGLOB error_in[i] = sub_o( orig[i + i_subfr], syn[i + i_subfr], &Overflow ); /*Q0*/ @@ -298,6 +302,7 @@ Word16 bass_pf_enc_fx( set16_fx( noise_in, 0, l_subfr ); set16_fx( error_in, 0, l_subfr ); s2 = s2_old; + move16(); } tmp16 = shl( l_filt, 1 ); diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index f572f4be3..6d2df38cd 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -40,12 +40,12 @@ void bw_detect_fx( Encoder_State *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : input signal */ - Word16 *spectrum, /* i : MDCT spectrum */ + const Word16 signal_in[], /* i : input signal */ + Word16 *spectrum, /* i : MDCT spectrum */ const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ const Word16 *cldfbBuf_Ener_Exp, /* i : CLDFB Energy Exponent */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t mct_on /* i : flag MCT mode */ + const Word16 mct_on /* i : flag MCT mode */ ) { Word16 Q_dct; @@ -63,6 +63,7 @@ void bw_detect_fx( Word32 cldfb_bin[9]; Word16 cldfb_bin_Exp[9]; Word16 cldfb_bin_width = 4; + move16(); const Word32 *pt32; Word32 max_NB32, max_WB32, max_SWB32, max_FB32, mean_NB32, mean_WB32, mean_SWB32, mean_FB32; /* Q11*/ /* we need Word32 for the new cldfb energy vectors */ Word16 bwd_count_wider_bw; @@ -74,6 +75,7 @@ void bw_detect_fx( #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif bwd_count_wider_bw = BWD_COUNT_WIDER_BW; @@ -120,14 +122,15 @@ void bw_detect_fx( move32(); /* result: Q31 */ } - cldfb_bin[0] = Mpy_32_16_1( cldfb_bin[0], ScalFac ); - move32(); /* Q31 */ + cldfb_bin[0] = Mpy_32_16_1( cldfb_bin[0], ScalFac ); // Q(31-cldfb_bin_Exp) + move32(); /* Q31 */ cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP ); move16(); if ( cldfb_bin[i] == 0 ) { cldfb_bin[i] = L_deposit_l( 1 ); + move32(); } L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ #ifdef BASOP_NOGLOB @@ -153,7 +156,7 @@ void bw_detect_fx( } FOR( i = 1; i <= 2; i++ ) { - cldfb_bin[i] = Mpy_32_16_1( cldfb_bin[i], ScalFac ); + cldfb_bin[i] = Mpy_32_16_1( cldfb_bin[i], ScalFac ); // Q(31-(cldfv_bin_Exp+CLDFBscalingFactor_EXP)) move32(); cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP ); move16(); @@ -161,6 +164,7 @@ void bw_detect_fx( if ( cldfb_bin[i] == 0 ) { cldfb_bin[i] = L_deposit_l( 1 ); + move32(); } L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ @@ -191,7 +195,7 @@ void bw_detect_fx( } FOR( i = 3; i <= 6; i++ ) { - cldfb_bin[i] = Mpy_32_16_1( cldfb_bin[i], ScalFac ); + cldfb_bin[i] = Mpy_32_16_1( cldfb_bin[i], ScalFac ); // Q(31-(cldfv_bin_Exp+CLDFBscalingFactor_EXP)) move32(); cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP ); move16(); @@ -199,6 +203,7 @@ void bw_detect_fx( if ( cldfb_bin[i] == 0 ) { cldfb_bin[i] = L_deposit_l( 1 ); + move32(); } L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ @@ -231,6 +236,7 @@ void bw_detect_fx( if ( cldfb_bin[i] == 0 ) { cldfb_bin[i] = L_deposit_l( 1 ); + move32(); } L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ @@ -305,13 +311,14 @@ void bw_detect_fx( #else /* BASOP_NOGLOB */ spect[i] = round_fx( L_shr( spect32[i], Q_dct ) ); #endif + move16(); } Q_dct = -2; move16(); } ELSE { - Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); + Word16 l_frame = extract_l( st->input_Fs / FRAMES_PER_SEC ); IF( EQ_16( st->core, TCX_10_CORE ) ) { l_frame = shr( l_frame, 1 ); @@ -359,6 +366,7 @@ void bw_detect_fx( e_tmp = sub( sub( 30, e_tmp ), Q_dct ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ spect_bin[i] = round_fx( L_shl( L_tmp, 11 ) ); /* Q11 */ + move16(); } } } @@ -527,23 +535,25 @@ void bw_detect_fx( /*if( localVAD || st->lp_noise > 30 )*/ test(); - IF( st->localVAD || GT_16( st->lp_noise_fx, 7680 ) ) + IF( st->localVAD || GT_16( st->lp_noise_fx, 7680 /*30 in Q8*/ ) ) { /*st->lt_mean_NB_fx = ALPHA_BWD * st->lt_mean_NB_fx + (1-ALPHA_BWD) * mean_NB;*/ L_tmp = L_mult( ALPHA_BWD_FX, st->lt_mean_NB_fx ); /* Q15 * Q11 -> Q27 */ L_tmp = L_mac( L_tmp, 32768 - ALPHA_BWD_FX, mean_NB ); /* Q15 * Q11) -> L_mac(Q27, Q27) -> Q27*/ st->lt_mean_NB_fx = round_fx( L_tmp ); /* Q11 (27-16) */ + move16(); /*st->lt_mean_WB_fx = ALPHA_BWD * st->lt_mean_WB_fx + (1-ALPHA_BWD) * mean_WB;*/ L_tmp = L_mult( ALPHA_BWD_FX, st->lt_mean_WB_fx ); L_tmp = L_mac( L_tmp, 32768 - ALPHA_BWD_FX, mean_WB ); st->lt_mean_WB_fx = round_fx( L_tmp ); + move16(); /*st->lt_mean_SWB_fx = ALPHA_BWD * st->lt_mean_SWB_fx + (1-ALPHA_BWD) * mean_SWB;*/ L_tmp = L_mult( ALPHA_BWD_FX, st->lt_mean_SWB_fx ); L_tmp = L_mac( L_tmp, 32768 - ALPHA_BWD_FX, mean_SWB ); st->lt_mean_SWB_fx = round_fx( L_tmp ); - + move16(); IF( enerBuffer != NULL ) { @@ -565,6 +575,7 @@ void bw_detect_fx( IF( GT_32( L_tmp, L_tmp1 ) ) /* Q24 */ { st->count_WB = add( st->count_WB, 1 ); + move16(); } } ELSE @@ -576,6 +587,7 @@ void bw_detect_fx( IF( L_tmp < 0 ) { st->count_WB = sub( st->count_WB, 1 ); + move16(); } } @@ -603,6 +615,7 @@ void bw_detect_fx( IF( L_tmp1 > 0 ) { st->count_SWB = add( st->count_SWB, 1 ); + move16(); } } ELSE @@ -614,6 +627,7 @@ void bw_detect_fx( IF( L_tmp1 < 0 ) { st->count_SWB = sub( st->count_SWB, 1 ); + move16(); } } /*if( max_FB > BWD_LT_THRESH_FX * st->lt_mean_SWB_fx && 0.83f * max_SWB > BWD_LT_THRESH_FX * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH_FX * st->lt_mean_NB_fx )*/ @@ -645,6 +659,7 @@ void bw_detect_fx( IF( L_tmp1 > 0 ) { st->count_FB = add( st->count_FB, 1 ); + move16(); } } ELSE @@ -656,6 +671,7 @@ void bw_detect_fx( IF( L_tmp1 < 0 ) { st->count_FB = sub( st->count_FB, 1 ); + move16(); } } } @@ -666,9 +682,10 @@ void bw_detect_fx( { /*if( 2 * max_WB > max_NB )*/ L_tmp = L_mult( 8192, max_WB ); /* 2.0 in Q12 x Q11 -> Q24*/ - if ( L_msu( L_tmp, max_NB, 4096 ) > 0 ) + IF( L_msu( L_tmp, max_NB, 4096 ) > 0 ) { st->count_WB = add( st->count_WB, 1 ); + move16(); } } ELSE @@ -678,22 +695,23 @@ void bw_detect_fx( L_tmp = L_msu( L_tmp, mean_NB, 4096 ); test(); test(); - if ( L_tmp < 0 && !( EQ_16( mean_WB, -1 ) && EQ_16( mean_NB, -1 ) ) ) + IF( L_tmp < 0 && !( EQ_16( mean_WB, -1 ) && EQ_16( mean_NB, -1 ) ) ) { st->count_WB = sub( st->count_WB, 1 ); + move16(); } } - test(); /*if( max_SWB > BWD_LT_THRESH * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH * st->lt_mean_NB_fx )*/ test(); IF( L_msu( L_deposit_h( max_SWB ), BWD_LT_THRESH_FX, st->lt_mean_WB_fx ) > 0 && L_msu( L_deposit_h( max_WB ), BWD_LT_THRESH_FX, st->lt_mean_NB_fx ) > 0 ) { /*if( 2 * max_SWB > max_WB )*/ L_tmp = L_mult( 8192, max_SWB ); /* 2.0 in Q12 x Q11 -> Q24*/ - if ( L_msu( L_tmp, max_WB, 4096 ) > 0 ) + IF( L_msu( L_tmp, max_WB, 4096 ) > 0 ) { st->count_SWB = add( st->count_SWB, 1 ); + move16(); } } ELSE @@ -703,9 +721,10 @@ void bw_detect_fx( L_tmp = L_msu( L_tmp, mean_WB, 4096 ); test(); test(); - if ( L_tmp < 0 && !( EQ_16( mean_SWB, -1 ) && EQ_16( mean_WB, -1 ) ) ) + IF( L_tmp < 0 && !( EQ_16( mean_SWB, -1 ) && EQ_16( mean_WB, -1 ) ) ) { st->count_SWB = sub( st->count_SWB, 1 ); + move16(); } } @@ -716,9 +735,10 @@ void bw_detect_fx( { /*if( 2 * max_FB > max_SWB )*/ L_tmp = L_mult( 8192, max_FB ); /* 2.0 in Q12 x Q11 -> Q24*/ - if ( L_msu( L_tmp, max_SWB, 4096 ) > 0 ) + IF( L_msu( L_tmp, max_SWB, 4096 ) > 0 ) { st->count_FB = add( st->count_FB, 1 ); + move16(); } } ELSE @@ -727,9 +747,10 @@ void bw_detect_fx( L_tmp = L_mult( 12288, mean_FB ); /* 3.0 in Q12 x Q11 -> Q24*/ test(); test(); - if ( L_msu( L_tmp, mean_SWB, 4096 ) < 0 && !( EQ_16( mean_FB, -1 ) && EQ_16( mean_SWB, -1 ) ) ) + IF( L_msu( L_tmp, mean_SWB, 4096 ) < 0 && !( EQ_16( mean_FB, -1 ) && EQ_16( mean_SWB, -1 ) ) ) { st->count_FB = sub( st->count_FB, 1 ); + move16(); } } } @@ -887,12 +908,12 @@ void bw_detect_fx( /* verify that maximum encoded bandwidth (specified on the command line) is not exceeded */ - IF( GT_16( st->input_bwidth, st->max_bwidth ) ) + if ( GT_16( st->input_bwidth, st->max_bwidth ) ) { st->input_bwidth = st->max_bwidth; move16(); } - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { set_bw_fx( -1, -1, st, st->codec_mode ); } @@ -1022,7 +1043,7 @@ void set_bw_fx( BREAK; } } - if ( EQ_16( n, FRAME_SIZE_NB ) ) + IF( EQ_16( n, FRAME_SIZE_NB ) ) { assert( !"Bitrate not supported: not part of EVS" ); } diff --git a/lib_enc/cng_enc.c b/lib_enc/cng_enc.c index dde1a574a..ea957da8c 100644 --- a/lib_enc/cng_enc.c +++ b/lib_enc/cng_enc.c @@ -47,13 +47,6 @@ #include "prot_fx.h" #include "ivas_rom_com_fx.h" -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ - -#define MAX_DELTA_CNG 1 -#define ENER_MID_DEAD_ZONE 0.01 /* dead-zone width around mid points between quantization levels */ - /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ @@ -169,10 +162,10 @@ static void shb_CNG_encod_ivas_fx( Word16 tmp, tmp1, tmp2, scale, exp1, exp2, ener_mid_dec_thr_e; tmp = BASOP_Util_Divide1616_Scale( st->hTdCngEnc->last_idx_ener, 22938, &scale ); // 0.7 in Q15 ->exp 0 - scale = scale + ( 15 - 0 ); + scale = add( scale, ( 15 - 0 ) ); tmp = sub( tmp, shl( 6, sub( Q15, scale ) ) ); tmp1 = BASOP_Util_Divide1616_Scale( tmp, 3277, &exp1 ); - exp1 = exp1 + ( scale - 0 ); + exp1 = add( exp1, ( scale - 0 ) ); ener_mid_dec_thr_fx = shr( mult( tmp1, 9864 ), 1 ); // exp = exp @@ -346,7 +339,7 @@ static Word16 shb_DTX_ivas_fx( move16(); move16(); } - IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 ) ) // 12 in Q8 + IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12 in Q8*/ ) ) { allow_cn_step = 1; move16(); @@ -355,7 +348,7 @@ static Word16 shb_DTX_ivas_fx( /* Also allow step if shb energy has dropped 12 dB */ test(); test(); - IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GT_16( sub( hTdCngEnc->mov_shb_cng_ener_fx, log_shb_ener_fx ), 3072 ) ) + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GT_16( sub( hTdCngEnc->mov_shb_cng_ener_fx, log_shb_ener_fx ), 3072 /*12 in Q8*/ ) ) { allow_cn_step = 1; move16(); @@ -365,16 +358,20 @@ static Word16 shb_DTX_ivas_fx( { hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; + move16(); + move16(); } ELSE { tmp = sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ); /* Q8 */ - tmp = mult( tmp, 29491 ); /* Q8 */ + tmp = mult( tmp, 29491 /* .9f in Q15*/ ); /* Q8 */ hTdCngEnc->mov_wb_cng_ener_fx = add( hTdCngEnc->mov_wb_cng_ener_fx, tmp ); /* Q8 */ + move16(); tmp = sub( log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ); - tmp = mult( tmp, 8192 ); /* Q8 */ + tmp = mult( tmp, 8192 /* .25f in Q15*/ ); /* Q8 */ hTdCngEnc->mov_shb_cng_ener_fx = add( hTdCngEnc->mov_shb_cng_ener_fx, tmp ); /* Q8 */ + move16(); } hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); @@ -383,10 +380,11 @@ static Word16 shb_DTX_ivas_fx( move16(); move16(); - test(); - test(); IF( EQ_32( st->core_brate, SID_2k40 ) ) { + test(); + test(); + test(); IF( st->hDtxEnc->first_CNG == 0 ) { update = 1; @@ -443,6 +441,5 @@ static Word16 shb_DTX_ivas_fx( move16(); } - test(); return ( update ); } diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 44ce22cc9..71f03277a 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -50,10 +50,14 @@ void CNG_enc_fx( Word16 m1; Word16 res[L_FRAME16k]; Word16 step_inv = 0; + move16(); Word16 hi, lo; Word16 maxl = 0; + move16(); Word16 num_bits = 0; + move16(); Word16 step = 0; + move16(); Word16 *pt_res; const Word16 *pt_sp; Word16 enr; @@ -64,9 +68,11 @@ void CNG_enc_fx( Word32 L_tmp1; Word16 exp; Word16 m = 0; + move16(); Word16 tmp[HO_HIST_SIZE * M]; Word16 ll, s_ptr; Word16 tmpv, maxv, scale, att = 1; + move16(); Word16 lsf_tmp[M]; Word32 C[M]; Word32 max_val[2]; @@ -77,9 +83,12 @@ void CNG_enc_fx( Word16 max_dev; Word16 dist; Word16 max_idx1[2] = { 0, 0 }; + move16(); + move16(); Word16 fft_io[L_FRAME16k]; Word16 *ptR, *ptI; Word32 enr1 = 0; + move32(); Word32 env[NUM_ENV_CNG]; Word32 min1; Word16 min1_idx; @@ -90,21 +99,24 @@ void CNG_enc_fx( Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; Word16 force_cn_step = 0; + move16(); Word16 tmp_loop; Word16 st_lp_sp_enr; DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; + move16(); Word16 lp_ener_thr_scale; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Temp variables for floating point functions */ lp_ener_thr_scale = 8; /* 4.0f*/ /*IVAS_CODE Q2 */ move16(); - if ( NE_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode != EVS_MONO ) { lp_ener_thr_scale = 7; /* 3.5f;*/ move16(); @@ -163,8 +175,9 @@ void CNG_enc_fx( test(); test(); test(); - IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16( hTdCngEnc->lp_sp_enr_fx, 1536 ) && - GT_16( sub( sp_enr, hTdCngEnc->lp_sp_enr_fx ), 1024 ) && GT_16( sp_enr, 1536 ) ) + test(); + IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16( hTdCngEnc->lp_sp_enr_fx, 1536 /*6.0f in Q8*/ ) && + GT_16( sub( sp_enr, hTdCngEnc->lp_sp_enr_fx ), 1024 /*4.0f in Q8*/ ) && GT_16( sp_enr, 1536 /*6.0f in Q8*/ ) ) { hTdCngEnc->lp_sp_enr_fx = sp_enr; move16(); @@ -174,10 +187,12 @@ void CNG_enc_fx( ELSE { hTdCngEnc->lp_sp_enr_fx = round_fx( L_mac( L_mult( 29491 /* 0.9, Q15 */, hTdCngEnc->lp_sp_enr_fx ), 3277 /* 0.1, Q15 */, sp_enr ) ); /* Q8 (8+15+1-16) */ + move16(); } } /* update the pointer to circular buffer of old LSP vectors */ hTdCngEnc->cng_hist_ptr = add( hTdCngEnc->cng_hist_ptr, 1 ); + move16(); if ( EQ_16( hTdCngEnc->cng_hist_ptr, DTX_HIST_SIZE ) ) { hTdCngEnc->cng_hist_ptr = 0; @@ -203,7 +218,7 @@ void CNG_enc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; + ftmp_fx = 964; /*(6400/(M+1))X2.56 */ move16(); /*QX2.56 */ tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -211,7 +226,7 @@ void CNG_enc_fx( ELSE { lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; + ftmp_fx = 1205; /*(8000/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -225,7 +240,7 @@ void CNG_enc_fx( L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536 */ } - C[i] = Mpy_32_16_1( L_tmp, 1928 ); + C[i] = Mpy_32_16_1( L_tmp, 1928 /*.0588235f Q15*/ ); move32(); /*QX6.5536 */ IF( GT_32( C[i], max_val[0] ) ) @@ -251,6 +266,7 @@ void CNG_enc_fx( FOR( i = 0; i < M; i++ ) { L_tmp = 0; + move32(); FOR( j = 0; j < hDtxEnc->cng_hist_size; j++ ) { L_tmp = L_add( L_tmp, L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[j * M + i] ) ); /*Q15 */ @@ -260,6 +276,7 @@ void CNG_enc_fx( tmpv = div_s( 1, sub( hDtxEnc->cng_hist_size, 2 ) ); /*Q15 */ L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ lsp_new[i] = extract_l( L_tmp ); /*Q15 */ + move16(); } max_idx1[0] = max_idx[0]; move16(); @@ -280,7 +297,7 @@ void CNG_enc_fx( test(); test(); IF( ( ( hDtxEnc->cng_cnt == 0 ) && - GT_16( hTdCngEnc->lp_sp_enr_fx, 1536 ) && + GT_16( hTdCngEnc->lp_sp_enr_fx, 1536 /* 6.0, Q8 */ ) && ( LT_16( add( st_lp_sp_enr, 1024 /* 4.0, Q8 */ ), sp_enr ) ) && ( hDtxEnc->first_CNG != 0 ) && ( hTdCngEnc->old_enr_index >= 0 ) && @@ -297,12 +314,12 @@ void CNG_enc_fx( Copy( st_fx->lsp_old_fx, hDtxEnc->lspCNG_fx, M ); /* Average the CNG spectral envelope in case of the very first CNG frame */ - IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode != EVS_MONO ) { FOR( i = 0; i < M; i++ ) { /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ - lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 ), lsp_new[i], 16384 ); + lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 ), lsp_new[i], 16384 /*.5 Q15*/ ); move16(); } } @@ -372,7 +389,8 @@ void CNG_enc_fx( test(); test(); test(); - IF( EQ_16( st_fx->element_mode, EVS_MONO ) && ( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !hDtxEnc->first_CNG || GE_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) ) + test(); + IF( st_fx->element_mode == EVS_MONO && ( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !hDtxEnc->first_CNG || GE_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) ) { IF( GT_32( hDtxEnc->last_active_brate, ACELP_16k40 ) ) { @@ -382,11 +400,13 @@ void CNG_enc_fx( ELSE { hDtxEnc->CNG_mode = get_cng_mode( hDtxEnc->last_active_brate ); + move16(); } } /* If first sid after active burst update LSF history from circ buffer */ hTdCngEnc->burst_ho_cnt = s_min( hTdCngEnc->burst_ho_cnt, hTdCngEnc->ho_circ_size ); + move16(); hTdCngEnc->act_cnt = 0; move16(); s_ptr = add( sub( hTdCngEnc->ho_circ_ptr, hTdCngEnc->burst_ho_cnt ), 1 ); @@ -399,6 +419,7 @@ void CNG_enc_fx( FOR( ll = hTdCngEnc->burst_ho_cnt; ll > 0; ll-- ) { hTdCngEnc->ho_hist_ptr = add( hTdCngEnc->ho_hist_ptr, 1 ); + move16(); if ( EQ_16( hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_ptr = 0; @@ -422,9 +443,11 @@ void CNG_enc_fx( Copy( &( hTdCngEnc->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngEnc->ho_lsp_hist_fx[hTdCngEnc->ho_hist_ptr * M] ), M ); Copy32( &( hTdCngEnc->ho_ener_circ_fx[s_ptr] ), &( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 1 ); hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + move32(); Copy32( &( hTdCngEnc->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngEnc->ho_env_hist_fx[hTdCngEnc->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); hTdCngEnc->ho_hist_size = add( hTdCngEnc->ho_hist_size, 1 ); + move16(); if ( GT_16( hTdCngEnc->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_size = HO_HIST_SIZE; @@ -458,9 +481,10 @@ void CNG_enc_fx( #endif test(); test(); - IF( ( hDtxEnc->first_CNG > 0 || EQ_16( st_fx->element_mode, EVS_MONO ) ) && L_tmp1 > 0 ) + IF( ( hDtxEnc->first_CNG > 0 || st_fx->element_mode == EVS_MONO ) && L_tmp1 > 0 ) { *allow_cn_step = s_or( *allow_cn_step, 1 ); + move16(); } } test(); @@ -481,7 +505,7 @@ void CNG_enc_fx( L_enr = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ weights = W_DTX_HO_FX[0]; /* Q15 */ - + move16(); m = 1; move16(); FOR( k = 1; k < hTdCngEnc->ho_hist_size; k++ ) @@ -531,7 +555,7 @@ void CNG_enc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; + ftmp_fx = 964; /*(6400/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -539,7 +563,7 @@ void CNG_enc_fx( ELSE { lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; + ftmp_fx = 1205; /*(8000/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -615,6 +639,8 @@ void CNG_enc_fx( dist = 0; /*Q15 */ max_dev = 0; /*Q15 */ + move16(); + move16(); FOR( i = 0; i < M; i++ ) { dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15 */ @@ -731,16 +757,17 @@ void CNG_enc_fx( IF( EQ_16( st_fx->bwidth, WB ) && hDtxEnc->CNG_mode >= 0 ) { ftmp_fx = HO_ATT_FX[hDtxEnc->CNG_mode]; + move16(); } ELSE { - ftmp_fx = 19661; + ftmp_fx = 19661; /*0.6f in Q15*/ move16(); } - att = mult( ftmp_fx, 5461 ); /* Q15 */ - L_tmp = L_mult( att, 8 ); /* Q16 */ - tmp1 = extract_l( L_shr( L_tmp, 2 ) ); /* Q14 */ + att = mult( ftmp_fx, 5461 /*1/6f in Q15*/ ); /* Q15 */ + L_tmp = L_mult( att, 8 ); /* Q16 */ + tmp1 = extract_l( L_shr( L_tmp, 2 ) ); /* Q14 */ tmp1 = add( 16384, tmp1 ); att = div_s( 16374, tmp1 ); /* Q15 */ @@ -919,6 +946,7 @@ void CNG_enc_fx( enr = round_fx( L_tmp ); /* Q8 */ } /* decrease the energy in case of WB input */ + test(); IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { // PMT("CNG IVAS_SCE and IVAS_CPE_DFT code missing") @@ -1011,6 +1039,7 @@ void CNG_enc_fx( /* substract by 2 not done to leave Energy in Q2 */ lo = L_Extract_lc( L_tmp, &hi ); hTdCngEnc->Enew_fx = Pow2( add( hi, 4 ), lo ); /* Q6 */ + move32(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ @@ -1098,6 +1127,7 @@ void CNG_enc_fx( FOR( i = 0; i < NUM_ENV_CNG; i++ ) { q_env[i] = L_deposit_l( CNG_details_codebook_fx[min1_idx][i] ); + move32(); } } /* Update hangover memory during CNG */ @@ -1106,6 +1136,7 @@ void CNG_enc_fx( { /* update the pointer to circular buffer of old LSP vectors */ hTdCngEnc->ho_hist_ptr = add( hTdCngEnc->ho_hist_ptr, 1 ); + move16(); if ( EQ_16( hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_ptr = 0; @@ -1139,6 +1170,7 @@ void CNG_enc_fx( Copy32( env, &( hTdCngEnc->ho_env_hist_fx[( hTdCngEnc->ho_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); } hTdCngEnc->ho_hist_size = add( hTdCngEnc->ho_hist_size, 1 ); + move16(); if ( GT_16( hTdCngEnc->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngEnc->ho_hist_size = HO_HIST_SIZE; @@ -1167,6 +1199,7 @@ void CNG_enc_fx( move16(); push_indice_fx( hBstr, IND_SID_TYPE, 0, 1 ); + test(); IF( LT_32( st_fx->input_Fs, 32000 ) && NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); @@ -1193,6 +1226,7 @@ void CNG_enc_fx( ELSE { hDtxEnc->cng_cnt = add( hDtxEnc->cng_cnt, 1 ); + move16(); } return; @@ -1419,7 +1453,7 @@ void CNG_enc_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; + ftmp_fx = 964; /*(6400/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -1427,7 +1461,7 @@ void CNG_enc_ivas_fx( ELSE { lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; + ftmp_fx = 1205; /*(8000/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -1467,6 +1501,7 @@ void CNG_enc_ivas_fx( FOR( i = 0; i < M; i++ ) { L_tmp = 0; + move32(); FOR( j = 0; j < hDtxEnc->cng_hist_size; j++ ) { L_tmp = L_add( L_tmp, L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[j * M + i] ) ); /*Q15 */ @@ -1476,6 +1511,7 @@ void CNG_enc_ivas_fx( tmpv = div_s( 1, sub( hDtxEnc->cng_hist_size, 2 ) ); /*Q15 */ L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ lsp_new[i] = extract_l( L_tmp ); /*Q15 */ + move16(); } max_idx1[0] = max_idx[0]; move16(); @@ -1518,7 +1554,7 @@ void CNG_enc_ivas_fx( FOR( i = 0; i < M; i++ ) { /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ - lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 ), lsp_new[i], 16384 ); + lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 /*.5f Q15*/ ), lsp_new[i], 16384 /*.5f Q15*/ ); move16(); } } @@ -1574,7 +1610,7 @@ void CNG_enc_ivas_fx( FOR( i = 0; i < M; i++ ) { /* AR low-pass filter */ - hDtxEnc->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); + hDtxEnc->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i] ), 32768 /*1f Q15*/ - CNG_ISF_FACT_FX, lsp_new[i] ); move16(); /* Q15 (15+15+1-16) */ } } @@ -1585,6 +1621,7 @@ void CNG_enc_ivas_fx( test(); test(); test(); + test(); IF( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !hDtxEnc->first_CNG || GE_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) ) { IF( GT_32( hDtxEnc->last_active_brate, ACELP_16k40 ) ) @@ -1595,6 +1632,7 @@ void CNG_enc_ivas_fx( ELSE { hDtxEnc->CNG_mode = get_cng_mode( hDtxEnc->last_active_brate ); + move16(); } } @@ -1688,7 +1726,7 @@ void CNG_enc_ivas_fx( L_ener = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ weights = W_DTX_HO_FX[0]; /* Q15 */ - + move16(); m = 1; move16(); FOR( k = 1; k < hTdCngEnc->ho_hist_size; k++ ) @@ -1738,7 +1776,7 @@ void CNG_enc_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; + ftmp_fx = 964; /*(6400/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -1746,7 +1784,7 @@ void CNG_enc_ivas_fx( ELSE { lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; + ftmp_fx = 1205; /*(8000/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -1815,9 +1853,9 @@ void CNG_enc_ivas_fx( } L_tmp = L_sub( L_tmp, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15 */ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15 */ - L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ - lsp_tmp[i] = extract_l( L_tmp ); /*Q15 */ + tmpv = div_s( 1, sub( m, 2 ) ); /*Q15 */ /*Q15 */ + L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ /*Q15 */ + lsp_tmp[i] = extract_l( L_tmp ); /*Q15 */ /*Q15 */ move16(); } } @@ -1851,7 +1889,7 @@ void CNG_enc_ivas_fx( FOR( i = 0; i < M; i++ ) { /* AR low-pass filter */ - hDtxEnc->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); /* Q15 */ + hDtxEnc->lspCNG_fx[i] = add( mult_r( 26214 /*.8f Q15*/, lsp_tmp[i] ), mult_r( 6554 /*.2f Q15*/, lsp_new[i] ) ); /* Q15 */ move16(); } } @@ -1909,7 +1947,7 @@ void CNG_enc_ivas_fx( { E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); exp = sub( Q14, norm_s( Aq[0] ) ); - Scale_sig( Aq, M, sub( Q12, exp ) ); + Scale_sig( Aq, M, sub( Q12, exp ) ); // Q12 } tmp_loop = shr( st_fx->L_frame, 6 ); @@ -1943,7 +1981,7 @@ void CNG_enc_ivas_fx( } ELSE { - ftmp_fx = 19661; + ftmp_fx = 19661; /*.6f in Q15*/ move16(); } @@ -2130,6 +2168,7 @@ void CNG_enc_ivas_fx( enr = round_fx( L_tmp ); /* Q8 */ } /* decrease the energy in case of WB input */ + test(); IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { enr = add( enr, mult( hTdCngEnc->CNG_att_fx, FAC_LOG2_BY10_Q16 ) ); /* Q8 (Q7 + Q16 - Q15)*/ @@ -2154,7 +2193,7 @@ void CNG_enc_ivas_fx( ELSE { att = 384; - move16(); /*Q8*/ + move16(); /*1.5f Q8*/ } enr = sub( enr, att ); } @@ -2220,6 +2259,7 @@ void CNG_enc_ivas_fx( /* substract by 2 not done to leave Energy in Q2 */ lo = L_Extract_lc( L_tmp, &hi ); hTdCngEnc->Enew_fx = Pow2( add( hi, 4 ), lo ); /* Q6 */ + move32(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ @@ -2272,7 +2312,7 @@ void CNG_enc_ivas_fx( } /* codebook search */ - min1 = 1310588928; /* Q17 */ + min1 = 1310588928; /* 9999.0f Q17 */ move32(); min1_idx = 0; move16(); @@ -2425,6 +2465,7 @@ void swb_CNG_enc_fx( ) { Word16 shb_SID_updt_fx = 0; + move16(); TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; test(); @@ -2534,10 +2575,11 @@ static void shb_CNG_encod_fx( #ifndef IVAS_CODE hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_CNG_ENV1].nb_bits ); hBstr->ind_list[IND_CNG_ENV1].nb_bits = -1; + move16(); + move16(); #else delete_indice( hBstr, IND_CNG_ENV1 ); #endif - move16(); #ifdef IVAS_CODE if ( st->element_mode == IVAS_CPE_DFT ) { @@ -2550,6 +2592,8 @@ static void shb_CNG_encod_fx( } hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); hTdCngEnc->ho_sid_bw = L_or( hTdCngEnc->ho_sid_bw, 0x1L ); + move32(); + move32(); } ELSE { @@ -2587,11 +2631,13 @@ static Word16 shb_DTX_fx( Word16 fra; Word16 att; /*Q8*/ Word16 allow_cn_step_fx = 0; + move16(); DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif shb_new_speech_fx = shb_old_speech_fx + ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4; Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); @@ -2666,7 +2712,7 @@ static Word16 shb_DTX_fx( move16(); } - if ( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 ) ) + if ( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12.0f Q8*/ ) ) { allow_cn_step_fx = 1; move16(); @@ -2688,15 +2734,16 @@ static Word16 shb_DTX_fx( ELSE { tmp = sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ); /* Q8 */ - tmp = mult( tmp, 29491 ); /* Q8 */ + tmp = mult( tmp, 29491 /*.9f in Q15*/ ); /* Q8 */ hTdCngEnc->mov_wb_cng_ener_fx = add( hTdCngEnc->mov_wb_cng_ener_fx, tmp ); /* Q8 */ - + move16(); tmp = sub( log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ); - tmp = mult( tmp, 8192 ); /* Q8 */ + tmp = mult( tmp, 8192 /*.25f in Q15*/ ); /* Q8 */ hTdCngEnc->mov_shb_cng_ener_fx = add( hTdCngEnc->mov_shb_cng_ener_fx, tmp ); /* Q8 */ + move16(); } hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); - + move16(); update_fx = 0; move16(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) @@ -2715,10 +2762,11 @@ static Word16 shb_DTX_fx( update_fx = 1; move16(); hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 ); + move16(); } ELSE { - IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 ) ) + IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 /*3.0f in Q8*/ ) ) { update_fx = 1; move16(); @@ -2777,14 +2825,14 @@ static Word16 shb_DTX_fx( *---------------------------------------------------------------------*/ void calculate_hangover_attenuation_gain_fx( Encoder_State *st, /* i : encoder state structure */ - Word16 *att, /* o : attenuation factor */ + Word16 *att, /* o : attenuation factor Q15 */ const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { Word16 offset; TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; - *att = 32767; + *att = 32767; // 1.0f in Q15 move16(); /* smoothing in case of CNG */ @@ -2793,7 +2841,7 @@ void calculate_hangover_attenuation_gain_fx( test(); test(); test(); - IF( hTdCngEnc->burst_ho_cnt > 0 && ( vad_hover_flag != 0 ) && ( NE_16( st->bwidth, NB ) || GT_16( st->element_mode, EVS_MONO ) ) ) /* corresponds to line 504 in FLT acelp_core_enc.c */ + IF( hTdCngEnc->burst_ho_cnt > 0 && ( vad_hover_flag != 0 ) && ( NE_16( st->bwidth, NB ) || st->element_mode > EVS_MONO ) ) /* corresponds to line 504 in FLT acelp_core_enc.c */ { #ifdef IVAS_CODE if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) @@ -2804,6 +2852,7 @@ void calculate_hangover_attenuation_gain_fx( #endif { offset = 5; + move16(); test(); if ( EQ_16( st->bwidth, WB ) && st->hDtxEnc->CNG_mode >= 0 ) { @@ -2811,7 +2860,7 @@ void calculate_hangover_attenuation_gain_fx( move16(); } assert( hTdCngEnc->burst_ho_cnt > 0 ); - *att = CNG_burst_att_fx[offset][sub( hTdCngEnc->burst_ho_cnt, 1 )]; /*Q15*/ + *att = CNG_burst_att_fx[offset][hTdCngEnc->burst_ho_cnt - 1]; /*Q15*/ move16(); } } @@ -2821,20 +2870,20 @@ void calculate_hangover_attenuation_gain_fx( void calculate_hangover_attenuation_gain_ivas_fx( Encoder_State *st, /* i : encoder state structure */ - Word16 *att, /* o : attenuation factor */ + Word16 *att, /* o : attenuation factor Q15 */ const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { Word16 lim, result_e; - *att = 32767; + *att = 32767; // 1.0f in Q15 move16(); test(); test(); test(); test(); - IF( st->hTdCngEnc != NULL && ( vad_hover_flag != 0 ) && GT_16( st->hTdCngEnc->burst_ho_cnt, 0 ) && ( NE_16( st->bwidth, NB ) || GT_16( st->element_mode, EVS_MONO ) ) ) + IF( st->hTdCngEnc != NULL && ( vad_hover_flag != 0 ) && GT_16( st->hTdCngEnc->burst_ho_cnt, 0 ) && ( NE_16( st->bwidth, NB ) || st->element_mode > EVS_MONO ) ) { test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index d93398997..cbe006f53 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -30,10 +30,10 @@ void acelp_2t32_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + const Word16 dn[], /* i : corr. between target and h[]. Qx*/ + const Word16 h[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + Word16 y[] /* o : filtered fixed codebook excitation Q9*/ ) { Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1, index; @@ -50,6 +50,7 @@ void acelp_2t32_fx( Word16 rrixiy[MSIZE]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* * Compute rrixix[][] needed for the codebook search. @@ -57,12 +58,9 @@ void acelp_2t32_fx( /* Init pointers to last position of rrixix[] */ p0 = &rrixix[0][NB_POS_FCB_2T - 1]; - move16(); p1 = &rrixix[1][NB_POS_FCB_2T - 1]; - move16(); ptr_h1 = h; - move16(); L_cor = L_deposit_h( 1 ); FOR( i = 0; i < NB_POS_FCB_2T; i++ ) { @@ -85,9 +83,7 @@ void acelp_2t32_fx( } p0 = rrixix[0]; - move16(); p1 = rrixix[1]; - move16(); FOR( i = 0; i < NB_POS_FCB_2T; i++ ) { @@ -108,46 +104,41 @@ void acelp_2t32_fx( pos2 = MSIZE - 2; move16(); ptr_hf = h + 1; - move16(); FOR( k = 0; k < NB_POS_FCB_2T; k++ ) { /* Init pointers to last position of diagonals */ p1 = &rrixiy[pos]; - move16(); p0 = &rrixiy[pos2]; - move16(); ptr_h1 = h; - move16(); ptr_h2 = ptr_hf; - move16(); - L_cor = L_mult( *ptr_h1++, *ptr_h2++ ); + L_cor = L_mult( *ptr_h1++, *ptr_h2++ ); // Q(12+12+1) FOR( i = k; i < NB_POS_FCB_2T - 1; i++ ) { #ifdef BASOP_NOGLOB - *p1 = round_fx_o( L_cor, &Overflow ); + *p1 = round_fx_o( L_cor, &Overflow ); // Q(25-16) L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); #else *p1 = round_fx( L_cor ); L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); #endif #ifdef BASOP_NOGLOB - *p0 = round_fx_o( L_cor, &Overflow ); + *p0 = round_fx_o( L_cor, &Overflow ); // Q(9) L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); #else *p0 = round_fx( L_cor ); L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); #endif - p1 -= ( NB_POS_FCB_2T + 1 ); move16(); - p0 -= ( NB_POS_FCB_2T + 1 ); move16(); + p1 -= ( NB_POS_FCB_2T + 1 ); + p0 -= ( NB_POS_FCB_2T + 1 ); } #ifdef BASOP_NOGLOB - *p1 = round_fx_o( L_cor, &Overflow ); + *p1 = round_fx_o( L_cor, &Overflow ); // Q9 #else *p1 = round_fx( L_cor ); #endif @@ -155,7 +146,6 @@ void acelp_2t32_fx( move16(); pos2--; ptr_hf += STEP; - move16(); } /*----------------------------------------------------------------* @@ -168,18 +158,18 @@ void acelp_2t32_fx( /* FIR high-pass filtering */ IF( i == 0 ) { - L_tmp = L_msu( L_tmp, dn[1], 11469 ); + L_tmp = L_msu( L_tmp, dn[1], 11469 /*.3f Q15*/ ); } ELSE IF( EQ_16( i, L_SUBFR - 1 ) ) { L_tmp = L_deposit_h( dn[i] ); - L_tmp = L_msu( L_tmp, dn[i - 1], 11469 ); + L_tmp = L_msu( L_tmp, dn[i - 1], 11469 /*.3f Q15*/ ); } ELSE { L_tmp = L_deposit_h( dn[i] ); - L_tmp = L_msu( L_tmp, dn[i - 1], 11469 ); - L_tmp = L_msu( L_tmp, dn[i + 1], 11469 ); + L_tmp = L_msu( L_tmp, dn[i - 1], 11469 /*.3f Q15*/ ); + L_tmp = L_msu( L_tmp, dn[i + 1], 11469 /*.3f Q15*/ ); } /* pre-selection of polarities */ @@ -232,11 +222,8 @@ void acelp_2t32_fx( *----------------------------------------------------------------*/ p0 = rrixix[0]; - move16(); p1 = rrixix[1]; - move16(); p2 = rrixiy; - move16(); psk = -1; move16(); alpk = 1; @@ -279,7 +266,6 @@ void acelp_2t32_fx( } } p1 -= NB_POS_FCB_2T; - move16(); IF( pos >= 0 ) { @@ -293,8 +279,8 @@ void acelp_2t32_fx( i0 = shr( ix, 1 ); i1 = shr( iy, 1 ); - sign0 = shl( pol[ix], 9 ); - sign1 = shl( pol[iy], 9 ); + sign0 = shl( pol[ix], 9 ); // Q9 + sign1 = shl( pol[iy], 9 ); // Q9 /*-------------------------------------------------------------------* * Build the codeword, the filtered codeword and index of codevector. @@ -327,12 +313,13 @@ void acelp_2t32_fx( FOR( i = ix; i < L_SUBFR; i++ ) { - y[i] = mult_r( sign0, h[i - ix] ); + y[i] = mult_r( sign0, h[i - ix] ); // Q9 move16(); } FOR( i = iy; i < L_SUBFR; i++ ) { - y[i] = round_fx( L_mac( L_deposit_h( y[i] ), sign1, h[i - iy] ) ); + y[i] = round_fx( L_mac( L_deposit_h( y[i] ), sign1, h[i - iy] ) ); // Q9 + move16(); } { /* write index to array of indices */ @@ -343,10 +330,10 @@ void acelp_2t32_fx( void acelp_2t32_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + const Word16 dn[], /* i : corr. between target and h[]. Qx*/ + const Word16 h[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9 */ + Word16 y[] /* o : filtered fixed codebook excitation Q9 */ ) { Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1, index; @@ -371,9 +358,7 @@ void acelp_2t32_ivas_fx( /* Init pointers to last position of rrixix[] */ p0 = &rrixix[0][NB_POS_FCB_2T - 1]; - move16(); p1 = &rrixix[1][NB_POS_FCB_2T - 1]; - move16(); ptr_h1 = h; move16(); @@ -399,9 +384,7 @@ void acelp_2t32_ivas_fx( } p0 = rrixix[0]; - move16(); p1 = rrixix[1]; - move16(); FOR( i = 0; i < NB_POS_FCB_2T; i++ ) { @@ -422,42 +405,37 @@ void acelp_2t32_ivas_fx( pos2 = MSIZE - 2; move16(); ptr_hf = h + 1; - move16(); FOR( k = 0; k < NB_POS_FCB_2T; k++ ) { /* Init pointers to last position of diagonals */ p1 = &rrixiy[pos]; - move16(); p0 = &rrixiy[pos2]; - move16(); ptr_h1 = h; - move16(); ptr_h2 = ptr_hf; - move16(); - L_cor = L_mult( *ptr_h1++, *ptr_h2++ ); + L_cor = L_mult( *ptr_h1++, *ptr_h2++ ); // Q25 FOR( i = k; i < NB_POS_FCB_2T - 1; i++ ) { #ifdef BASOP_NOGLOB - *p1 = round_fx_o( L_cor, &Overflow ); + *p1 = round_fx_o( L_cor, &Overflow ); // Q9 L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); #else *p1 = round_fx( L_cor ); L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); #endif #ifdef BASOP_NOGLOB - *p0 = round_fx_o( L_cor, &Overflow ); + *p0 = round_fx_o( L_cor, &Overflow ); // Q9 L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); #else *p0 = round_fx( L_cor ); L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ ); #endif - p1 -= ( NB_POS_FCB_2T + 1 ); move16(); - p0 -= ( NB_POS_FCB_2T + 1 ); move16(); + p1 -= ( NB_POS_FCB_2T + 1 ); + p0 -= ( NB_POS_FCB_2T + 1 ); } #ifdef BASOP_NOGLOB @@ -467,7 +445,7 @@ void acelp_2t32_ivas_fx( #endif pos -= NB_POS_FCB_2T; move16(); - pos2--; + pos2 = sub( pos2, 1 ); ptr_hf += STEP; move16(); } @@ -482,18 +460,18 @@ void acelp_2t32_ivas_fx( /* FIR high-pass filtering */ IF( i == 0 ) { - L_tmp = L_msu( L_tmp, dn[1], 11469 ); + L_tmp = L_msu( L_tmp, dn[1], 11469 /*.3f Q15*/ ); } ELSE IF( EQ_16( i, L_SUBFR - 1 ) ) { L_tmp = L_deposit_h( dn[i] ); - L_tmp = L_msu( L_tmp, dn[i - 1], 11469 ); + L_tmp = L_msu( L_tmp, dn[i - 1], 11469 /*.3f Q15*/ ); } ELSE { L_tmp = L_deposit_h( dn[i] ); - L_tmp = L_msu( L_tmp, dn[i - 1], 11469 ); - L_tmp = L_msu( L_tmp, dn[i + 1], 11469 ); + L_tmp = L_msu( L_tmp, dn[i - 1], 11469 /*.3f Q15*/ ); + L_tmp = L_msu( L_tmp, dn[i + 1], 11469 /*.3f Q15*/ ); } /* pre-selection of polarities */ @@ -546,11 +524,8 @@ void acelp_2t32_ivas_fx( *----------------------------------------------------------------*/ p0 = rrixix[0]; - move16(); p1 = rrixix[1]; - move16(); p2 = rrixiy; - move16(); psk = -1; move16(); alpk = 1; @@ -593,7 +568,6 @@ void acelp_2t32_ivas_fx( } } p1 -= NB_POS_FCB_2T; - move16(); IF( pos >= 0 ) { @@ -607,8 +581,8 @@ void acelp_2t32_ivas_fx( i0 = shr( ix, 1 ); i1 = shr( iy, 1 ); - sign0 = shl( pol[ix], 9 ); - sign1 = shl( pol[iy], 9 ); + sign0 = shl( pol[ix], 9 ); // Q9 + sign1 = shl( pol[iy], 9 ); // Q9 /*-------------------------------------------------------------------* * Build the codeword, the filtered codeword and index of codevector. @@ -641,12 +615,13 @@ void acelp_2t32_ivas_fx( FOR( i = ix; i < L_SUBFR; i++ ) { - y[i] = mult_r( sign0, h[i - ix] ); + y[i] = mult_r( sign0, h[i - ix] ); // Q9 move16(); } FOR( i = iy; i < L_SUBFR; i++ ) { - y[i] = round_fx( L_mac( L_deposit_h( y[i] ), sign1, h[i - iy] ) ); + y[i] = round_fx( L_mac( L_deposit_h( y[i] ), sign1, h[i - iy] ) ); // Q9 + move16(); } { /* write index to array of indices */ @@ -665,10 +640,10 @@ void acelp_2t32_ivas_fx( void acelp_1t64_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[], /* o : filtered fixed codebook excitation */ + const Word16 dn[], /* i : corr. between target and h[]. Qx*/ + const Word16 h[], /* i : impulse response of weighted synthesis filter Q12 */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9 */ + Word16 y[], /* o : filtered fixed codebook excitation Q9 */ const Word16 L_subfr /* i : subframe length */ ) { @@ -681,12 +656,12 @@ void acelp_1t64_fx( IF( dn[pos] < 0 ) { - sgn = -512; + sgn = -512; //-1 in Q9 move16(); } ELSE { - sgn = 512; + sgn = 512; // 1 in Q9 move16(); } @@ -704,12 +679,12 @@ void acelp_1t64_fx( { IF( sgn > 0 ) { - y[i] = shr_r( h[i - pos], 3 ); + y[i] = shr_r( h[i - pos], 3 ); // Q9 move16(); } ELSE { - y[i] = negate( shr_r( h[i - pos], 3 ) ); + y[i] = negate( shr_r( h[i - pos], 3 ) ); // Q9 move16(); } } @@ -734,10 +709,10 @@ void acelp_1t64_fx( void acelp_1t64_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[], /* o : filtered fixed codebook excitation */ + const Word16 dn[], /* i : corr. between target and h[]. Qx */ + const Word16 h[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + Word16 y[], /* o : filtered fixed codebook excitation Q9*/ const Word16 L_subfr /* i : subframe length */ ) { @@ -773,12 +748,12 @@ void acelp_1t64_ivas_fx( { IF( sgn > 0 ) { - y[i] = shr_r( h[i - pos], 3 ); + y[i] = shr_r( h[i - pos], 3 ); // Q9 move16(); } ELSE { - y[i] = negate( shr_r( h[i - pos], 3 ) ); + y[i] = negate( shr_r( h[i - pos], 3 ) ); // Q9 move16(); } } diff --git a/lib_enc/cod4t64_fast.c b/lib_enc/cod4t64_fast.c index e40766bec..f0402cfca 100644 --- a/lib_enc/cod4t64_fast.c +++ b/lib_enc/cod4t64_fast.c @@ -60,7 +60,7 @@ *---------------------------------------------------------------------*/ /*! r: return index (N+1 bits) */ -static Word16 quant_1p_N1_L_subfr( +static Word16 quant_1p_N1_L_subfr_fx( const Word16 nb_pos, /* i : number of positions */ const Word16 pos, /* i : position of the pulse */ const Word16 N /* i : number of bits for position */ @@ -72,7 +72,7 @@ static Word16 quant_1p_N1_L_subfr( index = s_and( pos, mask ); - if ( s_and( pos, nb_pos ) != 0 ) + IF( s_and( pos, nb_pos ) != 0 ) { index = add( index, shl( 1, N ) ); } @@ -83,9 +83,10 @@ static Word16 find_best_pulse_fx( const Word16 L_subfr, const Word16 nb_tracks, const Word16 track, - const Word32 dn[], - const Word16 sign[], - Word16 *s ) + const Word32 dn[], // Qx + const Word16 sign[], // Q0 + Word16 *s // Q0 +) { Word16 m, i; Word32 temp, max_val; @@ -370,7 +371,7 @@ void acelp_fast_fx( { h[i] = H[i]; move16(); - h_inv[i] = -H[i]; + h_inv[i] = negate( H[i] ); move16(); } @@ -594,7 +595,7 @@ void acelp_fast_fx( move16(); s64 = 0; - + move64(); FOR( i = track; i < L_subfr; i += nb_tracks ) { dn[i] = L_shr( L_msu( L_mult0( Gd, dn_orig[i] ), G, *alp_pos0 ), 6 ); // Q_dn @@ -641,6 +642,7 @@ void acelp_fast_fx( { Gn = add( Gn, i_mult( s[1], shr( dn_orig[m[1]], 1 ) ) ); // Q_dn -1 Gd32 = Gd; + move16(); Gd32 = L_add( Gd32, L_add( alp[0], L_mult0( i_mult( shl( s[0], 1 ), s[1] ), alp[m[0] - m[1]] ) ) ); // Q6 G = Gn; // Q_dn - 1 move16(); @@ -672,6 +674,7 @@ void acelp_fast_fx( { Gn = add( Gn, i_mult( s[2], shr( dn_orig[m[2]], 1 ) ) ); // Q_dn-1 Gd32 = Gd; + move16(); Gd32 = L_add( Gd32, L_add( L_add( alp[0], L_mult0( i_mult( shl( s[0], 1 ), s[2] ), alp[m[0] - m[2]] ) ), L_mult0( i_mult( shl( s[1], 1 ), s[2] ), alp[m[1] - m[2]] ) ) ); // Q6 G = Gn; // Q_dn-1 move16(); @@ -711,12 +714,14 @@ void acelp_fast_fx( { Gn = add( Gn, i_mult( s[3], shr( dn_orig[m[3]], 1 ) ) ); // Q_dn-1 Gd32 = Gd; + move16(); Gd32 = L_add( Gd32, L_add( L_add( L_add( alp[0], L_mult0( i_mult( shl( s[0], 1 ), s[3] ), alp[m[0] - m[3]] ) ), L_mult0( i_mult( shl( s[1], 1 ), s[3] ), alp[m[1] - m[3]] ) ), L_mult0( i_mult( shl( s[2], 1 ), s[3] ), alp[m[2] - m[3]] ) ) ); // Q6 - G = Gn; // Q_dn-1 - G1 = i_mult( G, s[1] ); // Q_dn-1 - G2 = i_mult( G, s[2] ); // Q_dn-1 - G3 = i_mult( G, s[3] ); // Q_dn-1 - G = i_mult( G, s[0] ); // Q_dn-1 + G = Gn; + move16(); // Q_dn-1 + G1 = i_mult( G, s[1] ); // Q_dn-1 + G2 = i_mult( G, s[2] ); // Q_dn-1 + G3 = i_mult( G, s[3] ); // Q_dn-1 + G = i_mult( G, s[0] ); // Q_dn-1 IF( EQ_16( cdk_index, 6 ) ) { @@ -814,9 +819,9 @@ void acelp_fast_fx( crit_den = W_extract_h( W_shl( s64, exp1 ) ); // 2*q_H + exp1 - 32 q_crit_den = add( shl( q_H, 1 ), sub( exp1, 32 ) ); - L_tmp1 = Mpy_32_32( crit_num, crit_den_max ); + L_tmp1 = Mpy_32_32( crit_num, crit_den_max ); // q_crit_num+q_crit_den_max-31 exp = sub( add( q_crit_num, q_crit_den_max ), 31 ); - L_tmp2 = Mpy_32_32( crit_den, crit_num_max ); + L_tmp2 = Mpy_32_32( crit_den, crit_num_max ); // q_crit_den+q_crit_num_max-31 exp1 = sub( add( q_crit_den, q_crit_num_max ), 31 ); IF( GT_16( exp, exp1 ) ) @@ -984,7 +989,7 @@ void acelp_fast_fx( j = i_mult( q, NPMAXPT ); IF( NE_16( ind_stream[j], -1 ) ) { - idx = quant_1p_N1_L_subfr( nb_pos, ind_stream[j], bits_track ); + idx = quant_1p_N1_L_subfr_fx( nb_pos, ind_stream[j], bits_track ); push_indice( hBstr, IND_ALG_CDBK_4T64, idx, add( bits_track, 1 ) ); } } @@ -1001,7 +1006,7 @@ void acelp_fast_fx( } ELSE { - idx = quant_1p_N1_L_subfr( nb_pos, ind_stream[j], bits_track ); + idx = quant_1p_N1_L_subfr_fx( nb_pos, ind_stream[j], bits_track ); push_indice( hBstr, IND_ALG_CDBK_4T64, idx, add( bits_track, 1 ) ); } } diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c index 92db2139b..44cde6f27 100644 --- a/lib_enc/cod4t64_fx.c +++ b/lib_enc/cod4t64_fx.c @@ -57,10 +57,10 @@ static Word32 pre_process_fx( const Word16 v[], Word16 sector_6p[], Word32 secto Word16 acelp_4t64_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 dn[], /* i : corr. between target and h[]. */ + Word16 dn[], /* i : corr. between target and h[]. */ const Word16 cn[], /* i : residual after long term prediction Q_new*/ const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ - Word16 R[], /* i : autocorrelation values */ + Word16 R[], /* i : autocorrelation values */ const Word16 acelpautoc, /* i : autocorrealtion flag */ Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ Word16 y[], /* o : filtered fixed codebook excitation Q9*/ @@ -100,9 +100,9 @@ Word16 acelp_4t64_fx( case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; /*1 in Q13*/ + move16(); /* coeff FOR sign setting */ config.nb_pulse = 6; move16(); config.fixedpulses = 0; @@ -117,9 +117,9 @@ Word16 acelp_4t64_fx( case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; /*1 in Q13*/ + move16(); /* coeff FOR sign setting */ config.nb_pulse = 8; move16(); config.fixedpulses = 2; @@ -135,8 +135,8 @@ Word16 acelp_4t64_fx( case 43: /* EVS pulse indexing: 43 bits, 10 pulses, 4 tracks */ case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; /*1 in Q13*/ move16(); config.nb_pulse = 10; move16(); @@ -155,8 +155,8 @@ Word16 acelp_4t64_fx( case 50: /* EVS pulse indexing: 50 bits, 12 pulses, 4 tracks */ case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; /*1 in Q13*/ move16(); config.nb_pulse = 12; move16(); @@ -175,8 +175,8 @@ Word16 acelp_4t64_fx( case 62: /* EVS pulse indexing: 62 bits, 16 pulses, 4 tracks */ case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */ config.nbiter = 3; - move16(); /* 3x36x16=1728 loops */ - config.alp = 6554; + move16(); /* 3x36x16=1728 loops */ + config.alp = 6554; /*.8f in Q13*/ move16(); config.nb_pulse = 16; move16(); @@ -198,8 +198,8 @@ Word16 acelp_4t64_fx( case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */ config.nbiter = 3; - move16(); /* 3x35x16=1680 loops */ - config.alp = 6144; + move16(); /* 3x35x16=1680 loops */ + config.alp = 6144; /*.75f in Q13*/ move16(); config.nb_pulse = 18; move16(); @@ -223,8 +223,8 @@ Word16 acelp_4t64_fx( case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */ config.nbiter = 2; - move16(); /* 2x53x16=1696 loop */ - config.alp = 4096; + move16(); /* 2x53x16=1696 loop */ + config.alp = 4096; /*.5f in Q13*/ move16(); config.nb_pulse = 24; move16(); @@ -255,7 +255,7 @@ Word16 acelp_4t64_fx( case 87: /* EVS pulse indexing: 87 bits, 26 pulses, 4 tracks */ config.nbiter = 1; move16(); - config.alp = 4096; + config.alp = 4096; /*.5f in Q13*/ move16(); config.nb_pulse = 26; move16(); @@ -472,10 +472,10 @@ Word16 acelp_4t64_fx( Word16 acelp_4t64_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 dn[], /* i : corr. between target and h[]. */ + Word16 dn[], /* i : corr. between target and h[]. */ const Word16 cn[], /* i : residual after long term prediction Q_new*/ const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ - Word16 R[], /* i : autocorrelation values */ + Word16 R[], /* i : autocorrelation values */ const Word16 acelpautoc, /* i : autocorrealtion flag */ Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ Word16 y[], /* o : filtered fixed codebook excitation Q9*/ @@ -515,9 +515,9 @@ Word16 acelp_4t64_ivas_fx( case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; /*1 in Q13*/ + move16(); /* coeff FOR sign setting */ config.nb_pulse = 6; move16(); config.fixedpulses = 0; @@ -532,9 +532,9 @@ Word16 acelp_4t64_ivas_fx( case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ + move16(); /* 4x20x16=1280 loops */ + config.alp = 8192; /*1 in Q13*/ + move16(); /* coeff FOR sign setting */ config.nb_pulse = 8; move16(); config.fixedpulses = 2; @@ -550,8 +550,8 @@ Word16 acelp_4t64_ivas_fx( case 43: /* EVS pulse indexing: 43 bits, 10 pulses, 4 tracks */ case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; /*1 in Q13*/ move16(); config.nb_pulse = 10; move16(); @@ -570,8 +570,8 @@ Word16 acelp_4t64_ivas_fx( case 50: /* EVS pulse indexing: 50 bits, 12 pulses, 4 tracks */ case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */ config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; + move16(); /* 4x26x16=1664 loops */ + config.alp = 8192; /*1 in Q13*/ move16(); config.nb_pulse = 12; move16(); @@ -590,8 +590,8 @@ Word16 acelp_4t64_ivas_fx( case 62: /* EVS pulse indexing: 62 bits, 16 pulses, 4 tracks */ case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */ config.nbiter = 3; - move16(); /* 3x36x16=1728 loops */ - config.alp = 6554; + move16(); /* 3x36x16=1728 loops */ + config.alp = 6554; /*.8f in Q13*/ move16(); config.nb_pulse = 16; move16(); @@ -613,8 +613,8 @@ Word16 acelp_4t64_ivas_fx( case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */ config.nbiter = 3; - move16(); /* 3x35x16=1680 loops */ - config.alp = 6144; + move16(); /* 3x35x16=1680 loops */ + config.alp = 6144; /*.75f in Q13*/ move16(); config.nb_pulse = 18; move16(); @@ -638,8 +638,8 @@ Word16 acelp_4t64_ivas_fx( case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */ config.nbiter = 2; - move16(); /* 2x53x16=1696 loop */ - config.alp = 4096; + move16(); /* 2x53x16=1696 loop */ + config.alp = 4096; /*.5f in Q13*/ move16(); config.nb_pulse = 24; move16(); @@ -670,7 +670,7 @@ Word16 acelp_4t64_ivas_fx( case 87: /* EVS pulse indexing: 87 bits, 26 pulses, 4 tracks */ config.nbiter = 1; move16(); - config.alp = 4096; + config.alp = 4096; /*.5f in Q13*/ move16(); config.nb_pulse = 26; move16(); @@ -709,7 +709,7 @@ Word16 acelp_4t64_ivas_fx( } config.codetrackpos = TRACKPOS_FIXED_FIRST; - move16(); + move32(); config.bits = nbbits; move16(); @@ -905,7 +905,7 @@ static Word32 fcb_encode_cl_fx( /* o: class index of t FOR( i = 0; i < pulse_num; i++ ) { - k = L_sub( k, PI_select_table[L_sub( temp1, buffer[i] )][temp2--] ); + k = L_sub( k, PI_select_table[temp1 - buffer[i]][temp2--] ); temp1 = L_sub( temp1, 1 ); } @@ -917,7 +917,7 @@ static Word32 fcb_encode_cl_fx( /* o: class index of t *encode fcb pulse index * *---------------------------------------------------------------------*/ static Word32 fcb_encode_PI_fx( /* o: return index of the pulse on a track */ - const Word16 v[], /* i: pulse on a track */ + const Word16 v[], /* i: pulse on a track Q9 */ const Word32 pulse_num /* i: number of the pulse on a track */ ) { @@ -935,7 +935,7 @@ static Word32 fcb_encode_PI_fx( /* o: return index of t /*encode the class and compute class offset*/ code_index = L_add( code_index, fcb_encode_class_fx( sector_p_num, pulse_num, pulse_pos_num ) ); - code_index = L_add( PI_offset[pulse_num][L_sub( L_add( pulse_num, 1L ), pulse_pos_num )], L_add( L_shl( code_index, extract_l( pulse_pos_num ) ), sign ) ); + code_index = L_add( PI_offset[pulse_num][( ( pulse_num + 1L ) - pulse_pos_num )], L_add( L_shl( code_index, extract_l( pulse_pos_num ) ), sign ) ); return code_index; } @@ -999,7 +999,7 @@ static Word32 fcb_encode_position_fx( /* o: return FOR( i = 0; i < pos_num; i++ ) { /*mmm1 -= PI_select_table_fx[sub(n,pos_vector[i]-1)][temp2--];*/ - mmm1 = L_sub( mmm1, PI_select_table[L_sub( n, add( pos_vector[i], 1 ) )][temp2--] ); + mmm1 = L_sub( mmm1, PI_select_table[n - ( pos_vector[i] + 1 )][temp2--] ); } } ELSE @@ -1008,7 +1008,7 @@ static Word32 fcb_encode_position_fx( /* o: return FOR( i = 0; i < pos_num; i++ ) { /*mmm1 -= PI_select_table_fx[n-pos_vector[i]-1][temp2--];*/ - mmm1 = L_sub( mmm1, PI_select_table[L_sub( n, add( pos_vector[i], 1 ) )][temp2--] ); + mmm1 = L_sub( mmm1, PI_select_table[n - ( pos_vector[i] + 1 )][temp2--] ); n = L_sub( n, 1 ); } } @@ -1232,7 +1232,7 @@ static Word32 quant_4p_4N_fx( /* o : return 4*N bits Word16 posA[4], posB[4]; Word32 index; - n_1 = (Word16) ( N - 1 ); + n_1 = sub( N, 1 ); move16(); nb_pos = shl( 1, n_1 ); /* nb_pos = (1< it doesn't need to be operated by Basic Operators */ - n_1 = (Word16) ( N - 1 ); - move16(); + n_1 = sub( N, 1 ); nb_pos = shl( 1, n_1 ); /* nb_pos = (1< 1, Q0 */ + move32(); IF( v[k] > 0 ) { sign = L_shl( sign, 1 ); @@ -1492,6 +1494,7 @@ static Word32 pre_process_fx( /* o: return sign value } } *pulse_pos_num = L_deposit_l( j ); +move32(); return sign; } @@ -1510,7 +1513,7 @@ return sign; *--------------------------------------------------------------------------*/ Word16 E_ACELP_code43bit_fx( - const Word16 code[], + const Word16 code[], /*Q9*/ UWord32 *ps, Word16 *p, UWord16 idxs[] ) @@ -1522,8 +1525,9 @@ Word16 E_ACELP_code43bit_fx( Word32 L_tmp; Word32 joint_index; static const Word32 joint_offset = 3611648; /*offset for 3 pulses per track*/ + move32(); Word16 saved_bits = 0; - + move16(); FOR( track = 0; track < 2; track++ ) { ps[track] = fcb_encode_PI_fx( code + track, 3 ); @@ -1535,19 +1539,19 @@ Word16 E_ACELP_code43bit_fx( FOR( track = 2; track < NB_TRACK_FCB_4T; track++ ) { i = j = i_mult2( track, NPMAXPT ); - move16(); + FOR( k = track; k < 64; k += 4 ) { IF( code[k] ) { tmp = shr( k, 2 ); - if ( code[k] < 0 ) + IF( code[k] < 0 ) { tmp = add( tmp, 16 ); } ind[j] = tmp; move16(); - IF( GT_16( abs_s( code[k] ), 512 ) ) + IF( GT_16( abs_s( code[k] ), 512 /*Q9*/ ) ) { ind[j + 1] = tmp; move16(); @@ -1580,6 +1584,8 @@ Word16 E_ACELP_code43bit_fx( idxs[0] = extract_l( L_add( L_shl( ps[2], 9 ), ps[3] ) ); idxs[1] = extract_l( L_add( L_shl( joint_index, 2 ), L_shr( ps[2], 7 ) ) ); idxs[2] = extract_l( L_shr( joint_index, 14 ) ); - + move16(); + move16(); + move16(); return saved_bits; } diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index e11f068b6..8950b423b 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -22,19 +22,19 @@ *-------------------------------------------------------------------*/ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision */ - const Word16 A[], /* i : coefficients 4xAz[M+1] */ - const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] */ - const Word16 speech[], /* i : speech[-M..lg] */ + const Word16 A[], /* i : coefficients 4xAz[M+1] Qx*/ + const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] Q12*/ + const Word16 speech[], /* i : speech[-M..lg] Qx*/ Word16 *prm, /* o : acelp parameters */ - Word16 stab_fac, + Word16 stab_fac, /*Q15 */ Encoder_State *st, PLC_ENC_EVS_HANDLE hPlc_Ext, const Word16 target_bits, /* i/o: coder memory state */ const Word16 Q_new, const Word16 shift, Word16 *pitch_buf, /* o : pitch values for each subfr.*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc /* o : excitation for SWB TBE */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 *bwe_exc /* o : excitation for SWB TBE Qx */ ) { #ifndef SIMPLIFY_CODE_BE @@ -73,13 +73,17 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * Word16 code2[L_SUBFR]; Word16 y22[L_SUBFR]; /* Filtered adaptive excitation */ Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ Word16 dummy = 0; + move16(); ACELP_config *acelp_cfg; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif acelp_cfg = &( st->acelp_cfg ); @@ -109,8 +113,9 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * move16(); move16(); move16(); + move16(); L_frame = st->L_frame; - + move16(); /*------------------------------------------------------------------------* * Previous frame is TCX (for non-EVS modes)(deactivated permanently) * @@ -126,11 +131,10 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * Q_new_p5 = add( Q_new, 5 ); /* Reset phase dispersion */ - IF( GT_16( st->last_core, ACELP_CORE ) ) + IF( st->last_core > ACELP_CORE ) { move16(); move16(); - move16(); hLPDmem->dm_fx.prev_gain_code = 0; set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); @@ -138,8 +142,6 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * } /* set excitation memory*/ - move16(); - move16(); exc = exc_buf + L_EXC_MEM; Copy( hLPDmem->old_exc, exc_buf, L_EXC_MEM ); *( exc + st->L_frame ) = 0; @@ -193,8 +195,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * * - find synthesis speech * * - update states of weighting filter * *------------------------------------------------------------------------*/ - move16(); - move16(); + p_A = A; p_Aq = Aq; @@ -292,7 +293,10 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ - + move16(); + move16(); + move16(); + move16(); /*----------------------------------------------------------------------* * Add Gaussian excitation * @@ -334,6 +338,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * IF( st->Opt_RF_ON ) { hRF->rf_tilt_buf[i_subfr / L_SUBFR] = hLPDmem->tilt_code; + move16(); } /*-----------------------------------------------------------------* * Update memory of the weighting filter @@ -354,6 +359,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * #else hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ #endif + move16(); BASOP_SATURATE_WARNING_ON_EVS; /*-------------------------------------------------------* @@ -398,7 +404,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * exc2[i] = round_fx( L_shl( Ltmp, 1 ) ); BASOP_SATURATE_WARNING_ON_EVS #endif - + move16(); Ltmp2 = Mpy_32_16_1( gain_code, code[i] ); #ifdef BASOP_NOGLOB Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); @@ -416,6 +422,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * BASOP_SATURATE_WARNING_ON_EVS exc[i + i_subfr] = round_fx( Ltmp ); #endif + move16(); } #endif /*-----------------------------------------------------------------* @@ -454,8 +461,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * /*----------------------------------------------------------* * Update * *----------------------------------------------------------*/ - move16(); - move16(); + p_A += ( M + 1 ); p_Aq += ( M + 1 ); @@ -499,7 +505,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * tmp = hLPDmem->syn[M]; E_UTIL_deemph2( sub( Q_new, 1 ), syn, st->preemph_fac, L_frame, &tmp ); - if ( st->hTcxEnc != NULL ) + IF( st->hTcxEnc != NULL ) { bufferCopyFx( syn + L_frame - ( L_frame / 2 ), hTcxEnc->Txnq, shr( L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_Txnq*/, 0 /*Q_syn*/, 0 /*Q_Txnq*/ ); } @@ -511,6 +517,6 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * /*Update MODE1*/ Copy( p_Aq, st->old_Aq_12_8_fx, M + 1 ); st->old_Es_pred_fx = Es_pred; - + move16(); return 0; } diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index 72cfb8e96..370ac69f7 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -55,9 +55,7 @@ * *-------------------------------------------------------------------*/ -#define SIMILAR_TNS_THRESHOLD ( 0.04f ) #define SIMILAR_TNS_THRESHOLD_FX_IN_Q15 ( 1311 ) -#define TNS_GAIN_THRESHOLD_FOR_WHITE ( 3.0f ) #define TNS_GAIN_THRESHOLD_FOR_WHITE_FX_IN_Q7 ( 384 ) void TNSAnalysisStereo_fx( Encoder_State **sts, /* i : encoder state handle */ @@ -132,7 +130,7 @@ void TNSAnalysisStereo_fx( * Temporal Noise Shaping analysis * *-----------------------------------------------------------*/ - IF( hTcxEnc->transform_type[k] == TCX_5 ) + IF( EQ_16( hTcxEnc->transform_type[k], TCX_5 ) ) { /* rearrange LF sub-window lines prior to TNS analysis & filtering */ tcx5TnsGrouping_fx( shr( L_frame, 2 ), shr( L_spec, 1 ), spectrum_fx ); @@ -141,9 +139,9 @@ void TNSAnalysisStereo_fx( /* WMOPS: All initializations are either for safety or static (tables) and thus not to be counted */ ResetTnsData( &hTcxEnc->tnsData[k] ); - if ( st->hTcxCfg->pCurrentTnsConfig->maxOrder <= 0 ) + IF( st->hTcxCfg->pCurrentTnsConfig->maxOrder <= 0 ) { - break; + BREAK; } CalculateTnsFilt_fx( st->hTcxCfg->pCurrentTnsConfig, spectrum_fx, &hTcxEnc->tnsData[k], NULL ); @@ -216,7 +214,7 @@ void TNSAnalysisStereo_fx( sts[0]->hTcxCfg->pCurrentTnsConfig = &sts[0]->hTcxCfg->tnsConfig[sts[0]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[0]->last_core == ACELP_CORE )]; sts[1]->hTcxCfg->pCurrentTnsConfig = &sts[1]->hTcxCfg->tnsConfig[sts[1]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[1]->last_core == ACELP_CORE )]; - FOR( iFilter = sub( sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { STnsFilter *pFilter[2]; struct TnsParameters const *pTnsParameters[2]; @@ -229,8 +227,8 @@ void TNSAnalysisStereo_fx( * both filters for the decision */ - meanPredictionGain_fx = mac_r( L_mult( pFilter[0]->predictionGain, 16384 ), pFilter[1]->predictionGain, 16384 ); // Q7 - maxPredictionGain_fx = s_max( maxPredictionGain_fx, meanPredictionGain_fx ); // Q7 + meanPredictionGain_fx = mac_r( L_mult( pFilter[0]->predictionGain, 16384 /*0.5f Q15*/ ), pFilter[1]->predictionGain, 16384 /*0.5f Q15*/ ); // Q7 + maxPredictionGain_fx = s_max( maxPredictionGain_fx, meanPredictionGain_fx ); // Q7 test(); test(); @@ -244,7 +242,7 @@ void TNSAnalysisStereo_fx( } test(); IF( LT_16( abs_s( sub( pFilter[0]->predictionGain, pFilter[1]->predictionGain ) ), mult( SIMILAR_TNS_THRESHOLD_FX_IN_Q15, meanPredictionGain_fx ) ) && - ( sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters ) ) + ( EQ_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) ) { Word16 maxAvgSqrCoef_fx = s_max( pFilter[0]->avgSqrCoef, pFilter[1]->avgSqrCoef ); // Q15 @@ -259,7 +257,9 @@ void TNSAnalysisStereo_fx( test(); IF( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( meanLtpGain_fx, 19660 /* 0.6 in Q15*/ ) ) { - ++sts[0]->hTcxEnc->tnsData[k].nFilters; + + sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, this may result in crash later. Changing the filter type here so the order is taken here in further section */ IF( pFilter[0]->order != 0 ) @@ -272,7 +272,8 @@ void TNSAnalysisStereo_fx( pFilter[0]->filterType = TNS_FILTER_ON_ZERO; move16(); } - ++sts[1]->hTcxEnc->tnsData[k].nFilters; + sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); IF( pFilter[1]->order != 0 ) { pFilter[1]->filterType = TNS_FILTER_ON; @@ -291,7 +292,8 @@ void TNSAnalysisStereo_fx( IF( GE_16( maxEnergyChange_fx, pTnsParameters[0]->minEnergyChange ) ) { - ++sts[0]->hTcxEnc->tnsData[k].nFilters; + sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, this may result in crash later. Changing the filter type here so the order is taken here in further section */ IF( pFilter[0]->order != 0 ) @@ -304,7 +306,8 @@ void TNSAnalysisStereo_fx( pFilter[0]->filterType = TNS_FILTER_ON_ZERO; move16(); } - ++sts[1]->hTcxEnc->tnsData[k].nFilters; + sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); IF( pFilter[1]->order != 0 ) { pFilter[1]->filterType = TNS_FILTER_ON; @@ -329,8 +332,12 @@ void TNSAnalysisStereo_fx( { pFilter[0]->filterType = TNS_FILTER_ON_ZERO; pFilter[1]->filterType = TNS_FILTER_ON_ZERO; - ++sts[0]->hTcxEnc->tnsData[k].nFilters; - ++sts[1]->hTcxEnc->tnsData[k].nFilters; + move16(); + move16(); + sts[0]->hTcxEnc->tnsData[k].nFilters = add( sts[0]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); + sts[1]->hTcxEnc->tnsData[k].nFilters = add( sts[1]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); } ELSE IF( NE_16( sts[0]->hTcxEnc->tnsData[k].nFilters, sts[1]->hTcxEnc->tnsData[k].nFilters ) ) /* sanity check */ { @@ -361,7 +368,7 @@ void TNSAnalysisStereo_fx( IF( EQ_16( tmpIntValue, 1 ) ) /* the TNS coefficients are sufficiently similar to equalize the two filters */ { - FOR( i = sub( maxOrder, 1 ); i >= 0; i-- ) + FOR( i = maxOrder - 1; i >= 0; i-- ) { IF( LT_16( abs_s( pFilter[0]->coefIndex[i] ), abs_s( pFilter[1]->coefIndex[i] ) ) ) { @@ -438,7 +445,7 @@ void TNSAnalysisStereo_fx( move16(); sts[1]->hTcxEnc->fUseTns[k] = 0; move16(); - FOR( iFilter = sub( sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { sts[0]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; move16(); @@ -463,7 +470,7 @@ void TNSAnalysisStereo_fx( move16(); sts[1]->hTcxEnc->fUseTns[k] = 0; move16(); - FOR( iFilter = sub( sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { ClearTnsFilterCoefficients( sts[0]->hTcxEnc->tnsData[k].filter + iFilter ); ClearTnsFilterCoefficients( sts[1]->hTcxEnc->tnsData[k].filter + iFilter ); @@ -478,9 +485,9 @@ void TNSAnalysisStereo_fx( /* individual decision for each channel */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - if ( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( EQ_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { - continue; + CONTINUE; } Word8 isTCX10; @@ -511,7 +518,7 @@ void TNSAnalysisStereo_fx( move16(); sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )]; - FOR( iFilter = sub( sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { STnsFilter *pFilter; struct TnsParameters const *pTnsParameters; @@ -524,9 +531,10 @@ void TNSAnalysisStereo_fx( { test(); test(); - IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( sts[ch]->hTcxEnc->tcxltp_gain, 19660 ) ) + IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( sts[ch]->hTcxEnc->tcxltp_gain, 19660 /*.6f in Q15*/ ) ) { - ++sts[ch]->hTcxEnc->tnsData[k].nFilters; + sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, this may result in crash later. Changing the filter type here so the order is taken here in further section */ IF( pFilter->order != 0 ) @@ -546,7 +554,8 @@ void TNSAnalysisStereo_fx( IF( GE_16( maxEnergyChange_fx, pTnsParameters->minEnergyChange ) ) { - ++sts[ch]->hTcxEnc->tnsData[k].nFilters; + sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, this may result in crash later. Changing the filter type here so the order is taken here in further section */ IF( pFilter->order != 0 ) @@ -571,7 +580,8 @@ void TNSAnalysisStereo_fx( { pFilter->filterType = TNS_FILTER_ON_ZERO; move16(); - ++sts[ch]->hTcxEnc->tnsData[k].nFilters; + sts[ch]->hTcxEnc->tnsData[k].nFilters = add( sts[ch]->hTcxEnc->tnsData[k].nFilters, 1 ); + move16(); } ELSE { @@ -599,7 +609,7 @@ void TNSAnalysisStereo_fx( move16(); sts[ch]->hTcxEnc->tnsData[k].nFilters = 0; move16(); - FOR( iFilter = sub( sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { ClearTnsFilterCoefficients( sts[ch]->hTcxEnc->tnsData[k].filter + iFilter ); sts[ch]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; @@ -615,9 +625,9 @@ void TNSAnalysisStereo_fx( /* we have the decision, set filter data accordingly */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - if ( EQ_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + IF( EQ_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { - continue; + CONTINUE; } IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) @@ -637,7 +647,7 @@ void TNSAnalysisStereo_fx( { sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][( k == 0 ) && ( sts[ch]->last_core == ACELP_CORE )]; - FOR( iFilter = sub( sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { STnsFilter *pFilter; pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter; @@ -662,9 +672,9 @@ void TNSAnalysisStereo_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; - if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { - continue; + CONTINUE; } IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) @@ -683,6 +693,7 @@ void TNSAnalysisStereo_fx( test(); test(); test(); + test(); IF( bWhitenedDomain && ( ch > 0 ) && /* test for identical TNS filter data in both channels */ sts[0]->hTcxCfg->fIsTNSAllowed && sts[0]->hTcxEnc->fUseTns[k] && sts[1]->hTcxCfg->fIsTNSAllowed && sts[1]->hTcxEnc->fUseTns[k] ) @@ -701,7 +712,7 @@ void TNSAnalysisStereo_fx( IF( equalFilterData ) { - FOR( iFilter = sub( st->hTcxCfg->pCurrentTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = st->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { const Word16 *pDataCh0 = (const Word16 *) &sts[0]->hTcxEnc->tnsData[k].filter[iFilter]; const Word16 *pDataCh1 = (const Word16 *) &sts[1]->hTcxEnc->tnsData[k].filter[iFilter]; @@ -711,18 +722,20 @@ void TNSAnalysisStereo_fx( test(); WHILE( ( i >= 0 ) && EQ_16( pDataCh0[i], pDataCh1[i] ) ) { + test(); i = sub( i, 1 ); } - if ( i >= 0 ) + IF( i >= 0 ) { equalFilterData = 0; move16(); - break; + BREAK; } } IF( equalFilterData ) { st->hTcxEnc->tnsData[k].nFilters = i_mult( st->hTcxEnc->tnsData[k].nFilters, -1 ); /* signals common TNS */ + move16(); } } } @@ -747,7 +760,7 @@ void TNSAnalysisStereo_fx( } st->hTcxEnc->tnsData[k].tnsOnWhitenedSpectra = st->hTcxEnc->bTnsOnWhithenedSpectra[k]; - + move16(); EncodeTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], param_core[ch] + k * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, tnsSize[ch] + k, tnsBits[ch] + k ); } diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 890f98e12..7a08226e6 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1075,6 +1075,13 @@ void ShapeSpectrum_ivas_fx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; move32(); move32(); + Word32 total_brate = st->total_brate; + move32(); + if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + total_brate = st->element_brate; + move32(); + } /*-----------------------------------------------------------* * Init * @@ -1110,7 +1117,7 @@ void ShapeSpectrum_ivas_fx( tcxGetNoiseFillingTilt( A, M, L_frame, - ( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ), + ( GE_32( total_brate, ACELP_13k20 ) && st->rf_mode == 0 ), &hTcxEnc->noiseTiltFactor ); /* Calculate Spectrum Flatness Measure for the TCX Concealment */ @@ -1121,7 +1128,7 @@ void ShapeSpectrum_ivas_fx( } test(); - IF( LE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) + IF( LE_32( total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) { max_low_pre = 0; move32(); @@ -1171,8 +1178,7 @@ void ShapeSpectrum_ivas_fx( FOR( i = L_frame; i < L_spec; i++ ) { W_tmp = W_mult0_32_32( spectrum[i], sns_int_scf[hTcxCfg->psychParamsCurrent->nBands - 1] ); - W_tmp = W_shr( W_tmp, Q16 ); - spectrum[i] = W_extract_l( W_tmp ); + spectrum[i] = W_extract_h( W_shl( W_tmp, Q16 ) ); move32(); } *spectrum_e = sub( 31 - 1, q_spectrum ); // As the output spectrum from sns_shape_spectrum_fx has Q = q_spectrum + 1 @@ -1198,7 +1204,7 @@ void ShapeSpectrum_ivas_fx( /* reduce the peaks in the IGF region, to make life of the core-coder easier... */ test(); - IF( LE_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) + IF( LE_32( total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) { Word16 sf_width; Word16 dist_low, dist_high; @@ -5182,7 +5188,7 @@ void InternalTCXDecoder_fx( /* DCT */ Q = sub( 31, *spectrum_e ); - edct_fx( spectrum_fx, tmp_buf, L_frame, &Q ); + edct_ivas_fx( spectrum_fx, tmp_buf, L_frame, &Q ); /* scale by sqrt(L / NORM_MDCT_FACTOR) */ tmp1 = mult_r( shl( L_frame, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR Q15*/ ); /* 4Q11 */ diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 0ad43487a..a53e0199c 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -769,8 +769,8 @@ void core_signal_analysis_high_bitrate_ivas_fx( move16(); IF( Q_exp != 0 ) { - Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); // *Q_new - Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); // *Q_new + Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, sub( Q_exp, sub( Q15, st->exp_buf_speech_enc_pe ) ) ); // *Q_new + Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); // *Q_new } IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) @@ -1072,7 +1072,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( Word16 Q; Q = q_out_wtda; - edct_fx( tcx20Win_32, hTcxEnc->spectrum_fx[frameno], L_subframe, &Q ); + edct_ivas_fx( tcx20Win_32, hTcxEnc->spectrum_fx[frameno], L_subframe, &Q ); hTcxEnc->spectrum_e[frameno] = sub( 31, Q ); move16(); diff --git a/lib_enc/find_tilt.c b/lib_enc/find_tilt.c index c5e16ed22..cd1d69770 100644 --- a/lib_enc/find_tilt.c +++ b/lib_enc/find_tilt.c @@ -68,7 +68,7 @@ void find_tilt_ivas_fx( Word32 hp_E[], /* o : energy in HF Q_new*/ const Word16 codec_mode, /* i : MODE1 or MODE2 */ const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ , Word16 Opt_vbr_mode ) { diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c index 972c40242..3415ac189 100644 --- a/lib_enc/find_uv.c +++ b/lib_enc/find_uv.c @@ -512,18 +512,17 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); test(); - test(); #ifdef BASOP_NOGLOB if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ + ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ #else if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index edef59ba2..c6f62d921 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -590,7 +590,7 @@ ivas_error pre_proc_ivas( IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) ) { /* update signal buffers */ - Copy( new_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame, L_FRAME ); + Copy_Scale_sig( new_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame, L_FRAME, sub( sub( Q15, st->exp_buf_speech_enc_pe ), sub( *Q_new, Q1 ) ) ); Copy( st->buf_speech_enc + L_FRAME32k, st->buf_speech_enc + st->L_frame, L_FRAME ); test(); @@ -626,8 +626,6 @@ ivas_error pre_proc_ivas( Copy( &old_wsp_fx[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); st->exp_old_wsp = e_old_wsp; move16(); - st->exp_buf_speech_enc_pe = sub( Q15, *Q_new - 1 ); - move16(); /* set the pointer of the current frame for the ACELP core */ IF( EQ_16( st->L_frame, L_FRAME ) ) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 66e8b9fcf..acaee9dea 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1526,7 +1526,8 @@ ivas_error pre_proc_front_ivas_fx( * Find spectral tilt * UC and VC frame selection *-----------------------------------------------------------------*/ - find_tilt_ivas_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, q_fr_bands, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); + find_tilt_ivas_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, q_fr_bands, + &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, q_inp_12k8, q_fr_bands ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 630fcf38e..bd2f19ade 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -113,6 +113,7 @@ ivas_error ivas_cpe_enc_fx( Word32 band_energies_LR_fx[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN (Q_buffer + QSCALE - band_ener_guardbits) */ Word16 Q_buffer[2]; Word16 orig_input_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 Q_orig_inp[CPE_CHANNELS]; Word16 Etot_last_fx[CPE_CHANNELS]; Word32 tmp, input_Fs; Word16 max_bwidth, ivas_format; @@ -407,7 +408,10 @@ ivas_error ivas_cpe_enc_fx( { Scale_sig( sts[n]->input_fx, input_frame, sub( -1, sts[n]->q_inp ) ); sts[n]->q_inp = -1; + move16(); Copy( sts[n]->input_fx, orig_input_fx[n], input_frame ); + Q_orig_inp[n] = sts[n]->q_inp; + move16(); IF( hCPE->hStereoICBWE != NULL ) { @@ -1090,7 +1094,8 @@ ivas_error ivas_cpe_enc_fx( for ( n = 0; n < CPE_CHANNELS; n++ ) { Copy( orig_input_fx[n], sts[n]->old_input_signal_fx, input_frame ); - sts[n]->q_old_inp = sts[n]->q_inp; + sts[n]->q_old_inp = Q_orig_inp[n]; + move16(); } } else if ( hCPE->element_mode == IVAS_CPE_DFT ) diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 2b8bded71..6ef980166 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -3497,7 +3497,8 @@ void noise_est_ivas_fx( /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ /* 32 bit state update */ Ltmp = L_sub( tmpN[i], hNoiseEst->bckr_fx[i] ); /*Q_new+Q_SCALE*/ - Ltmp = Mult_32_16( Ltmp, updt_step ); /* Q_new+Q_SCALE+15+1 -16*/ + Ltmp = Mult_32_16( Ltmp, updt_step ); + /* Q_new+Q_SCALE+15+1 -16*/ hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); move32(); } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 2001f2966..dc4b85c7a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -228,7 +228,7 @@ Word16 ffr_getSfWord32( void find_tilt_ivas_fx( const Word32 fr_bands[], /* i : energy in frequency bands Q_new*/ const Word32 bckr[], /* i : per band background noise energy estimate Q_new*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q_bckr*/ const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new - 2*/ -- GitLab From a3d2db91b38b658d798c1c0bac95f4d465eeabb5 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 23 Dec 2024 11:00:51 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_enc/analy_sp_fx.c | 2 +- lib_enc/find_tilt.c | 2 +- lib_enc/find_uv.c | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index e025bee07..d2e34b012 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -555,7 +555,7 @@ void ivas_analy_sp_fx( /* 10.0*log((float)tmp) */ /* 10.0*logf(2) in Q28 = 1860652798 */ - move16(); + move16(); } } diff --git a/lib_enc/find_tilt.c b/lib_enc/find_tilt.c index cd1d69770..c5e16ed22 100644 --- a/lib_enc/find_tilt.c +++ b/lib_enc/find_tilt.c @@ -68,7 +68,7 @@ void find_tilt_ivas_fx( Word32 hp_E[], /* o : energy in HF Q_new*/ const Word16 codec_mode, /* i : MODE1 or MODE2 */ const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ , Word16 Opt_vbr_mode ) { diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c index 3415ac189..1d88484d8 100644 --- a/lib_enc/find_uv.c +++ b/lib_enc/find_uv.c @@ -514,15 +514,15 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); #ifdef BASOP_NOGLOB if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ + ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ #else if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ -- GitLab