From 0da5f29bef3fefb7071cec64d16bf0ce913ec319 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:37:01 +0530 Subject: [PATCH 1/2] Q info updates, encoder cleanup --- lib_com/arith_coder.c | 162 ++-- lib_com/arith_coder_fx.c | 124 ++-- lib_com/basop_com_lpc.c | 79 +- lib_com/basop_lsf_tools.c | 64 +- lib_com/basop_proto_func.h | 61 +- lib_com/basop_tcx_utils.c | 89 ++- lib_com/bitalloc.c | 209 +++--- lib_com/bitalloc_fx.c | 165 +++-- lib_com/core_com_config.c | 296 ++++---- lib_com/deemph.c | 54 +- lib_com/delay_comp.c | 24 +- lib_com/dlpc_bfi_fx.c | 26 +- lib_com/enhancer_fx.c | 78 +- lib_com/est_tilt_fx.c | 20 +- lib_com/fd_cng_com.c | 45 +- lib_com/fd_cng_com_fx.c | 102 +-- lib_com/ivas_prot_fx.h | 52 +- lib_com/ivas_sba_config.c | 13 +- lib_com/ivas_sns_com_fx.c | 71 +- lib_com/ivas_spar_com.c | 1099 ++++++++++++++-------------- lib_com/ivas_spar_com_quant_util.c | 76 +- lib_com/ivas_stat_com.h | 2 +- lib_com/ivas_stereo_dft_com.c | 17 +- lib_com/ivas_stereo_eclvq_com_fx.c | 15 +- lib_com/log2.c | 10 +- lib_com/log2.h | 14 +- lib_com/logqnorm_fx.c | 30 +- lib_com/low_rate_band_att_fx.c | 8 +- lib_com/lpc_tools.c | 16 +- lib_com/lpc_tools_fx.c | 54 +- lib_com/lsf_dec_bfi_fx.c | 10 +- lib_com/lsf_msvq_ma_fx.c | 6 +- lib_com/lsf_tools.c | 96 +-- lib_com/lsf_tools_fx.c | 237 +++--- lib_com/lsp_conv_poly_fx.c | 4 +- lib_com/modif_fs.c | 187 ++--- lib_com/modif_fs_fx.c | 34 +- lib_com/mslvq_com_fx.c | 8 + lib_com/nelp_fx.c | 4 +- lib_com/parameter_bitmaping.c | 3 + lib_com/prot.h | 14 +- lib_com/prot_fx.h | 222 +++--- lib_dec/fd_cng_dec_fx.c | 2 +- lib_dec/hq_core_dec_fx.c | 2 +- lib_enc/core_enc_init.c | 2 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_spar_encoder.c | 6 +- lib_enc/ivas_spar_md_enc.c | 4 + 48 files changed, 2028 insertions(+), 1890 deletions(-) diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c index bba7ab973..ce16e7a7b 100644 --- a/lib_com/arith_coder.c +++ b/lib_com/arith_coder.c @@ -65,11 +65,11 @@ Word16 expfp_evs( assert( x <= 0 ); - L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) ); + L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) ); /* Q16 */ /* split into integer and fractional parts */ - xi = round_fx( L_tmp ); - xf = extract_l( L_tmp ); + xi = round_fx( L_tmp ); /* Q0 */ + xf = extract_l( L_tmp ); /* Q16 */ BASOP_SATURATE_WARNING_OFF; xf = negate( xf ); @@ -81,13 +81,13 @@ Word16 expfp_evs( + ((xf*xf) / (2*65536)) + ((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536) + ((((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)*xf) / (4*65536)); */ - y = L_mac0( 65536, xf, 1 ); - tmp = shr( mult( xf, xf ), 2 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( 65536, xf, 1 ); /* Q16 */ + tmp = shr( mult( xf, xf ), 2 ); /* Q15 */ + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( tmp, xf ), 3 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ /* Integer part */ b0 = s_and( xi, 1 ); @@ -105,7 +105,7 @@ Word16 expfp_evs( y = Mpy_32_16_1( y, 22513 ); /* exp(-8) in -11Q26 */ /* scaling: -1*b0 - 2*b1 -5*b2 -11*b3 */ - y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) ); + y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) ); /* Q16 */ /* zero for xi >= 16 */ if ( shr( xi, 4 ) > 0 ) @@ -157,44 +157,44 @@ void powfp_odd2_evs( maxk = sub( 15, norm_s( exp ) ); assert( maxk < 12 ); - pows[0] = base; + pows[0] = base; /* Q15 */ move16(); FOR( k = 0; k < maxk; k++ ) { - pows[k + 1] = mult_r( pows[k], pows[k] ); + pows[k + 1] = mult_r( pows[k], pows[k] ); /* Q15 */ move16(); } - k = sub( k, 1 ); + k--; h = shl( 1, k ); /* highest bit of exp2 */ - out2 = base; + out2 = base; /* Q15 */ move16(); - out = mult_r( out, pows[add( k, 1 )] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ + out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */ if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[add( k, 1 )] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); - FOR( k = sub( k, 1 ); k >= 0; k-- ) + FOR( k = k - 1; k >= 0; k-- ) { if ( s_and( exp, h ) != 0 ) { - out = mult_r( out, pows[k + 1] ); + out = mult_r( out, pows[k + 1] ); /* Q15 */ } if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); } } - *pout1 = out2; + *pout1 = out2; /* Q15 */ move16(); - *pout2 = out; + *pout2 = out; /* Q15 */ move16(); return; @@ -256,8 +256,8 @@ void tcx_arith_scale_envelope_ivas( L_tmp = L_sub( L_tmp, L_shr( L_mult0( target_bits, 30199 ), 11 ) ); /* Q15; 30199 -> 0.00045f (Q26) */ L_tmp = L_add( L_tmp, 39322 ); /* Q15; 39322 -> 1.2f (Q15) */ L_tmp = Mpy_32_16_1( L_tmp, target_bits ); /* Q0 */ - assert( L_tmp < 32768 ); - target_bits = extract_l( L_tmp ); + assert( LE_32( L_tmp, 32768 ) ); + target_bits = extract_l( L_tmp ); /* Q0 */ /* Calculate inverse envelope and find initial scale guess based on mean */ mean = L_deposit_l( 0 ); @@ -271,22 +271,22 @@ void tcx_arith_scale_envelope_ivas( #ifndef BASOP_NOGLOB tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 ); #else /* BASOP_NOGLOB */ - tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 ); + tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 ); /* exp(tmp2) */ #endif /* BASOP_NOGLOB */ ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ move32(); - mean = L_add( mean, ienv[k] ); + mean = L_add( mean, ienv[k] ); /* Q16 */ } tmp = norm_s( L_frame ); - tmp2 = div_s( 8192, shl( L_frame, tmp ) ); + tmp2 = div_s( 8192, shl( L_frame, tmp ) ); /* Q15 */ tmp = shl( tmp2, sub( tmp, 7 ) ); mean = L_shr( Mpy_32_16_1( mean, tmp ), 6 ); /* Q16 */ /* Rate dependent compensation to get closer to the target on average */ /* mean = powf(mean, (float)L_frame / target_bits * 0.357f); */ - tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); - tmp = mult_r( tmp, FL2WORD16( 0.357f ) ); - mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); + tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); /* exp(tmp2) */ + tmp = mult_r( tmp, 11698 /*0.357f Q15*/ ); + mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* exp(mean_e) */ /* Find first-guess scaling coefficient "scale" such that if "mean" is the * mean of the envelope, then the mean bit-consumption is approximately @@ -294,22 +294,22 @@ void tcx_arith_scale_envelope_ivas( * log2(2*e*mean*scale + 0.15 + 0.035/(mean*scale)) * L_frame = target_bits */ /* a = 2*2.71828183f*mean*mean; */ - tmp = round_fx( mean ); - a = L_mult( mult_r( tmp, FL2WORD16_SCALE( 2.71828183f, 2 ) ), tmp ); + tmp = round_fx( mean ); /* Q15 - mean_e */ + a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); /* 2 * mean_e + 3 */ a_e = add( shl( mean_e, 1 ), 3 ); /* b = (0.15f - powf(2.0f, target_bits/(float)L_frame)) * mean; */ - tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); + tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); /* exp(tmp2) */ tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) ); - b_e = BASOP_Util_Add_MantExp( FL2WORD16( 0.15f ), 0, negate( tmp ), tmp2, &b ); - b = mult_r( b, round_fx( mean ) ); + b_e = BASOP_Util_Add_MantExp( 4915 /*0.15f in Q15*/, 0, negate( tmp ), tmp2, &b ); + b = mult_r( b, round_fx( mean ) ); /* exp(b_e + mean_e) */ b_e = add( b_e, mean_e ); /* scale = (-b + sqrtf(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ #ifndef BASOP_NOGLOB tmp = round_fx( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ) ); #else - tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ), &Overflow ); + tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, -4588 /*-4.0f*0.035f Q15*/ ), a_e, &tmp2 ), &Overflow ); /* Q15 - a_e */ #endif IF( tmp <= 0 ) @@ -328,34 +328,34 @@ void tcx_arith_scale_envelope_ivas( } tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); - scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); + scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); /* exp(tmp) */ #ifndef BASOP_NOGLOB scale = shl( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */ #else - scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ + scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ #endif /* iscale = 1.0f / scale; */ iscale_e = 0; move16(); - iscale = Inv16( s_max( 1, scale ), &iscale_e ); + iscale = Inv16( s_max( 1, scale ), &iscale_e ); /* exp(iscale_e) */ lob = 0; move16(); hib = 0; move16(); - max_iter = 2; + max_iter = 2; /* Q0 */ move16(); if ( low_complexity ) { - max_iter = 1; + max_iter = 1; /* Q0 */ move16(); } FOR( iter = 0; iter < max_iter; iter++ ) { - statesi = 0x7FFF; + statesi = 0x7FFF; /* 1 in Q15 */ move16(); bits = 0; move16(); @@ -364,65 +364,65 @@ void tcx_arith_scale_envelope_ivas( { s = Mpy_32_16_1( ienv[k], scale ); /* Q16 */ - IF( L_sub( s, FL2WORD32_SCALE( 0.08f, 15 ) ) <= 0 ) + IF( L_sub( s, 5243l /*0.08f Q16*/ ) <= 0 ) { /* If s = 0.08, the expected bit-consumption is log2(1.0224). Below 0.08, the bit-consumption estimate function becomes inaccurate, so use log2(1.0224) for all values below 0.08. */ /* round(state * 1.0224 * 32768) */ - statesi = mult_r( statesi, FL2WORD16_SCALE( 1.0224, 1 ) ); + statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); /* Q14 */ tmp = norm_s( statesi ); - statesi = shl( statesi, tmp ); - bits = add( bits, sub( 1, tmp ) ); + statesi = shl( statesi, tmp ); /* Q15 */ + bits = add( bits, sub( 1, tmp ) ); /* Q0 */ } - ELSE IF( L_sub( s, FL2WORD32_SCALE( 255.0, 15 ) ) <= 0 ) + ELSE IF( L_sub( s, 16711680l /*255.0 Q16*/ ) <= 0 ) { /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */ - L_tmp = L_shl( Mpy_32_16_1( s, FL2WORD16_SCALE( 5.436564f, 3 ) ), 3 ); - L_tmp = L_add( L_tmp, FL2WORD32_SCALE( 0.15f, 15 ) ); - L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( FL2WORD16( 0.035f ), iscale ) ), iscale_e ) ); + L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); /* Q16 */ + L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); /* Q16 */ + L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */ tmp = norm_l( L_tmp ); #ifndef BASOP_NOGLOB statesi = mult_r( statesi, round_fx( L_shl( L_tmp, tmp ) ) ); -#else /* BASOP_NOGLOB */ - statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) ); -#endif /* BASOP_NOGLOB */ - bits = add( bits, sub( 15, tmp ) ); +#else /* BASOP_NOGLOB */ + statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) ); /* */ +#endif /* BASOP_NOGLOB */ + bits = add( bits, sub( 15, tmp ) ); /* Q0 */ tmp = norm_s( statesi ); statesi = shl( statesi, tmp ); - bits = sub( bits, tmp ); + bits = sub( bits, tmp ); /* Q0 */ } ELSE { /* for large envelope values, s > 255, bit consumption is approx log2(2*e*s) * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */ /* a = 5.436564f * s; */ - L_tmp = Mpy_32_16_1( s, FL2WORD16_SCALE( 5.436564f * 1.4142f, 3 ) ); /* Q13 */ - bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); + L_tmp = Mpy_32_16_1( s, 31492 /*5.436564f * 1.4142f Q12*/ ); /* Q13 */ + bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); /* Q0 */ } } IF( sub( bits, target_bits ) <= 0 ) { /* Bits leftover => scale is too small */ - lob = scale; + lob = scale; /* Q0 */ move16(); - lob_bits = bits; + lob_bits = bits; /* Q0 */ move16(); IF( hib > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); - scale = add( mult_r( sub( lob, hib ), adjust ), hib ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); /* Q0 */ } ELSE { /* Initial scale adaptation */ /* adjust = 1.05f * target_bits / (float)bits; scale *= adjust; */ - adjust = mult_r( FL2WORD16_SCALE( 1.05f, 1 ), target_bits ); - adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); + adjust = mult_r( 17203 /*1.05f Q14*/, target_bits ); /* Q15 */ + adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); /* exp(tmp) */ scale = shl( mult_r( scale, adjust ), add( 1, tmp ) ); } } @@ -431,13 +431,13 @@ void tcx_arith_scale_envelope_ivas( /* Ran out of bits => scale is too large */ hib = scale; move16(); - hib_bits = bits; + hib_bits = bits; /* Q0 */ move16(); IF( lob > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); - scale = add( mult_r( sub( lob, hib ), adjust ), hib ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); /* Q0 */ } ELSE { /* Initial scale adaptation */ @@ -449,13 +449,13 @@ void tcx_arith_scale_envelope_ivas( FOR( k = 0; k < L_frame; k++ ) { - s_env[k] = 0; + s_env[k] = 0; /* Q15 - e */ move16(); } } ELSE { - adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); + adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); /* Q15 */ } scale = mult_r( scale, adjust ); } @@ -476,10 +476,10 @@ void tcx_arith_scale_envelope_ivas( } ELSE { - iscale = Inv16( scale, &iscale_e ); + iscale = Inv16( scale, &iscale_e ); /* exp(iscale_e) */ } } - L_frame = L_spec_core; + L_frame = L_spec_core; /* Q0 */ move16(); tmp = getScaleFactor32( env, L_frame ); @@ -495,9 +495,9 @@ void tcx_arith_scale_envelope_ivas( FOR( k = 0; k < L_frame; k++ ) { - L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); - L_tmp = L_min( L_tmp, a ); - s_env[k] = round_fx( L_tmp ); + L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); /* Q31 - e */ + L_tmp = L_min( L_tmp, a ); /* Q31 - e */ + s_env[k] = round_fx( L_tmp ); /* Q15 - e */ move16(); } @@ -519,13 +519,13 @@ void tcx_arith_scale_envelope_ivas( *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope_ivas( - const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ - const Word16 L_frame, /* i : number of spectral lines */ - const Word16 L_spec, /* i : length of the coded spectrum */ - const Word16 preemph_fac, /* i : pre-emphasis factor */ - const Word16 gamma_w, /* i : A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor */ - Word32 env[] /* o : shaped signal envelope */ + const Word16 A_ind[], /* i : LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i : number of spectral lines Q0*/ + const Word16 L_spec, /* i : length of the coded spectrum Q0*/ + const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o : shaped signal envelope Q16*/ ) { Word16 k; @@ -545,7 +545,7 @@ void tcx_arith_render_envelope_ivas( /* Compute weighted signal envelope in perceptual domain */ FOR( k = 0; k < FDNS_NPTS; k++ ) { - signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); + signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); /* exp(signal_env_e + gainlpc_e) */ move16(); signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] ); move16(); @@ -554,7 +554,7 @@ void tcx_arith_render_envelope_ivas( /* Adaptive low frequency emphasis */ FOR( k = 0; k < L_frame; k++ ) { - env[k] = 0x10000; + env[k] = 0x10000; /* 1 in Q16 */ move32(); } @@ -565,7 +565,7 @@ void tcx_arith_render_envelope_ivas( FOR( k = L_frame; k < L_spec; ++k ) { - env[k] = env[k - 1]; + env[k] = env[k - 1]; /* Q16 */ move32(); } diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 64cc81d04..58ab13175 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -21,11 +21,11 @@ Word32 expfp( /* o: Q31 */ assert( x > 0 ); - L_tmp = L_shl( L_deposit_h( x ), x_e ); + L_tmp = L_shl( L_deposit_h( x ), x_e ); /* Q31 */ /* split into integer and fractional parts */ - xi = round_fx( L_tmp ); - xf = extract_l( L_tmp ); + xi = round_fx( L_tmp ); /* Q15 */ + xf = extract_l( L_tmp ); /* Q31 */ BASOP_SATURATE_WARNING_OFF_EVS; xf = negate( xf ); @@ -37,13 +37,13 @@ Word32 expfp( /* o: Q31 */ + ((xf*xf) / (2*65536)) + ((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536) + ((((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)*xf) / (4*65536)); */ - y = L_mac0( 65536, xf, 1 ); + y = L_mac0( 65536, xf, 1 ); /* Q16 */ tmp = shr( mult( xf, xf ), 2 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( tmp, xf ), 3 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ /* Integer part */ b0 = s_and( xi, 1 ); @@ -51,19 +51,19 @@ Word32 expfp( /* o: Q31 */ b2 = s_and( xi, 4 ); b3 = s_and( xi, 8 ); - if ( b0 != 0 ) + IF( b0 != 0 ) { y = Mpy_32_16_1( y, 24109 ); /* exp(-1) in -1Q16 */ } - if ( b1 != 0 ) + IF( b1 != 0 ) { y = Mpy_32_16_1( y, 17739 ); /* exp(-2) in -2Q17 */ } - if ( b2 != 0 ) + IF( b2 != 0 ) { y = Mpy_32_16_1( y, 19205 ); /* exp(-4) in -5Q20 */ } - if ( b3 != 0 ) + IF( b3 != 0 ) { y = Mpy_32_16_1( y, 22513 ); /* exp(-8) in -11Q26 */ } @@ -104,9 +104,9 @@ void powfp_odd2( assert( exp >= 0 ); - out = base; + out = base; /* Q15 */ move16(); - out2 = 0x7FFF; + out2 = 0x7FFF; /* 1 in Q15 */ move16(); IF( exp != 0 ) { @@ -114,11 +114,11 @@ void powfp_odd2( maxk = sub( 15, norm_s( exp ) ); assert( maxk < 12 ); - pows[0] = base; + pows[0] = base; /* Q15 */ move16(); FOR( k = 0; k < maxk; k++ ) { - pows[k + 1] = mult_r( pows[k], pows[k] ); + pows[k + 1] = mult_r( pows[k], pows[k] ); /* Q15 */ move16(); } k = sub( k, 1 ); @@ -127,31 +127,31 @@ void powfp_odd2( move16(); out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */ - if ( s_and( exp2, h ) != 0 ) + IF( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); FOR( k = sub( k, 1 ); k >= 0; k-- ) { - if ( s_and( exp, h ) != 0 ) + IF( s_and( exp, h ) != 0 ) { - out = mult_r( out, pows[k + 1] ); + out = mult_r( out, pows[k + 1] ); /* Q15 */ } - if ( s_and( exp2, h ) != 0 ) + IF( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); } } - *pout1 = out2; + *pout1 = out2; /* Q15 */ move16(); - *pout2 = out; + *pout2 = out; /* Q15 */ move16(); } @@ -223,13 +223,13 @@ void tcx_arith_scale_envelope( tmp = norm_l( env[k] ); tmp2 = sub( 15, tmp ); #ifdef BASOP_NOGLOB - tmp = Inv16( round_fx_o( L_shl_o( env[k], tmp, &Overflow ), &Overflow ), &tmp2 ); + tmp = Inv16( round_fx_o( L_shl_o( env[k], tmp, &Overflow ), &Overflow ), &tmp2 ); /* exp(tmp2) */ #else tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 ); #endif ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ move32(); - mean = L_add( mean, ienv[k] ); + mean = L_add( mean, ienv[k] ); /* Q16 */ } tmp = norm_s( L_frame ); tmp = shl( div_s( 8192, shl( L_frame, tmp ) ), sub( tmp, 7 ) ); @@ -237,9 +237,9 @@ void tcx_arith_scale_envelope( /* Rate dependent compensation to get closer to the target on average */ /* mean = (float)pow(mean, (float)L_frame / (float)target_bits * 0.357f); */ - tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); + tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); /* exp(tmp2) */ tmp = mult_r( tmp, 11698 /*0.357f Q15*/ ); - mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); + mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* exp(mean_e) */ /* Find first-guess scaling coefficient "scale" such that if "mean" is the * mean of the envelope, then the mean bit-consumption is approximately @@ -247,15 +247,15 @@ void tcx_arith_scale_envelope( * log2(2*e*mean*scale + 0.15 + 0.035/(mean*scale)) * L_frame = target_bits */ /* a = 2*2.71828183f*mean*mean; */ - tmp = round_fx( mean ); - a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); + tmp = round_fx( mean ); /* Q15 - mean_e */ + a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); /* 2 * mean_e + 3 */ a_e = add( shl( mean_e, 1 ), 3 ); /* b = (0.15f - (float)pow(2.0f, target_bits/(float)L_frame)) * mean; */ - tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); + tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); /* exp(tmp2) */ tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) ); b_e = BASOP_Util_Add_MantExp( 4915 /*0.15f Q15*/, 0, negate( tmp ), tmp2, &b ); - b = mult_r( b, round_fx( mean ) ); + b = mult_r( b, round_fx( mean ) ); /* exp(b_e + mean_e) */ b_e = add( b_e, mean_e ); /* scale = (-b + (float)sqrt(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ @@ -272,7 +272,7 @@ void tcx_arith_scale_envelope( tmp = Sqrt16( tmp, &tmp2 ); } - tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); + tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); /* exp(scale) */ scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); #ifdef BASOP_NOGLOB scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ @@ -283,7 +283,7 @@ void tcx_arith_scale_envelope( /* iscale = 1.0f / scale; */ iscale_e = 0; move16(); - iscale = Inv16( s_max( 1, scale ), &iscale_e ); + iscale = Inv16( s_max( 1, scale ), &iscale_e ); /* exp(isacle_e) */ lob = 0; move16(); @@ -300,7 +300,7 @@ void tcx_arith_scale_envelope( FOR( iter = 0; iter < max_iter; iter++ ) { - statesi = 0x7FFF; + statesi = 0x7FFF; /* 1 in Q15 */ move16(); bits = 0; move16(); @@ -314,17 +314,17 @@ void tcx_arith_scale_envelope( /* If s = 0.08, the expected bit-consumption is log2(1.0224). Below 0.08, the bit-consumption estimate function becomes inaccurate, so use log2(1.0224) for all values below 0.08. */ /* round(state * 1.0224 * 32768) */ - statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); + statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); /* Q14 */ tmp = norm_s( statesi ); - statesi = shl( statesi, tmp ); - bits = add( bits, sub( 1, tmp ) ); + statesi = shl( statesi, tmp ); /* Q15 */ + bits = add( bits, sub( 1, tmp ) ); /* Q0 */ } ELSE IF( LE_32( s, 16711680l /*255.0 Q16*/ ) ) { /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */ - L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); - L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); - L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); + L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); /* Q16 */ + L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); /* Q16 */ + L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */ tmp = norm_l( L_tmp ); #ifdef BASOP_NOGLOB @@ -336,7 +336,7 @@ void tcx_arith_scale_envelope( tmp = norm_s( statesi ); statesi = shl( statesi, tmp ); - bits = sub( bits, tmp ); + bits = sub( bits, tmp ); /* Q0 */ } ELSE { @@ -344,20 +344,20 @@ void tcx_arith_scale_envelope( * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */ /* a = 5.436564f * s; */ L_tmp = Mpy_32_16_1( s, 31492 /*5.436564f * 1.4142f Q12*/ ); /* Q13 */ - bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); + bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); /* Q0 */ } } IF( LE_16( bits, target_bits ) ) /* Bits leftover => scale is too small */ { - lob = scale; + lob = scale; /* Q0 */ move16(); - lob_bits = bits; + lob_bits = bits; /* Q0 */ move16(); IF( hib > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } ELSE /* Initial scale adaptation */ @@ -365,7 +365,7 @@ void tcx_arith_scale_envelope( /* adjust = 1.05f * target_bits / (float)bits; scale *= adjust; */ adjust = mult_r( 17203 /*1.05f Q14*/, target_bits ); - adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); + adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); /* exp(tmp) */ scale = shl( mult_r( scale, adjust ), add( 1, tmp ) ); } } @@ -378,7 +378,7 @@ void tcx_arith_scale_envelope( IF( lob > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } ELSE @@ -392,7 +392,7 @@ void tcx_arith_scale_envelope( } ELSE { - adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); + adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); /* Q15 */ } scale = mult_r( scale, adjust ); } @@ -411,7 +411,7 @@ void tcx_arith_scale_envelope( iscale = Inv16( scale, &iscale_e ); } } - L_frame = L_spec_core; + L_frame = L_spec_core; /* Q0 */ move16(); tmp = getScaleFactor32( env, L_frame ); @@ -427,9 +427,9 @@ void tcx_arith_scale_envelope( FOR( k = 0; k < L_frame; k++ ) { - L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); - L_tmp = L_min( L_tmp, a ); - s_env[k] = round_fx( L_tmp ); + L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); /* Q31 - e */ + L_tmp = L_min( L_tmp, a ); /* Q31 - e */ + s_env[k] = round_fx( L_tmp ); /* Q15 - e */ move16(); } } @@ -447,13 +447,13 @@ void tcx_arith_scale_envelope( * and decoder remain synchronized. *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - const Word16 L_frame, /* i: number of spectral lines */ - const Word16 L_spec, - const Word16 preemph_fac, /* i: pre-emphasis factor */ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 L_spec, /* Q0 */ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ) { Word16 k; @@ -474,14 +474,14 @@ void tcx_arith_render_envelope( /* Compute weighted signal envelope in perceptual domain */ FOR( k = 0; k < FDNS_NPTS; k++ ) { - signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); + signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); /* exp(signal_env_e + gainlpc_e) */ move16(); signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] ); move16(); } /* Adaptive low frequency emphasis */ - set32_fx( env, 0x10000, L_frame ); + set32_fx( env, 0x10000 /* 1 in Q16 */, L_frame ); AdaptLowFreqDeemph( env, 15, 1, @@ -493,7 +493,7 @@ void tcx_arith_render_envelope( FOR( k = L_frame; k < L_spec; ++k ) { - env[k] = env[k - 1]; + env[k] = env[k - 1]; /* Q16 */ move32(); } } diff --git a/lib_com/basop_com_lpc.c b/lib_com/basop_com_lpc.c index 669b976e6..5de4fa5d3 100644 --- a/lib_com/basop_com_lpc.c +++ b/lib_com/basop_com_lpc.c @@ -67,32 +67,36 @@ * Returns: * void */ -void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ) +void basop_weight_a( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 gamma /* Q15 */ +) { Word16 i, fac; Word32 Amax; Word16 shift; - fac = gamma; - Amax = L_mult( 16384, a[0] ); + fac = gamma; /* Q15 */ + Amax = L_mult( 16384, a[0] ); /* Q27 */ FOR( i = 1; i < M; i++ ) { Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); - fac = mult_r( fac, gamma ); + fac = mult_r( fac, gamma ); /* Q15 */ } - Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); + Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); /* Q27 */ shift = norm_l( Amax ); fac = gamma; ap[0] = shl( a[0], sub( shift, 1 ) ); move16(); FOR( i = 1; i < M; i++ ) { - ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); + ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q12 */ move16(); - fac = mult_r( fac, gamma ); + fac = mult_r( fac, gamma ); /* Q15 */ } - ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); + ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); /* Q12 */ move16(); @@ -113,7 +117,11 @@ void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ) * Returns: * void */ -void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) +void basop_weight_a_inv( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma /* Q14 */ +) { Word16 i; static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924, /* Q14 */ @@ -130,7 +138,7 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) { FOR( i = 0; i <= M; i++ ) { - ap[i] = a[i]; + ap[i] = a[i]; /* Q12 */ move16(); } return; @@ -138,37 +146,37 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV ); - inv_gamma_tab = inv_gamma_tab_12k8; + inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */ move16(); if ( sub( inv_gamma, GAMMA16k_INV ) == 0 ) { - inv_gamma_tab = inv_gamma_tab_16k; + inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */ move16(); } Amax = L_mult( 16384, a[0] ); FOR( i = 1; i < 9; i++ ) { - Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); + Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */ } FOR( i = 9; i < 17; i++ ) { - Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); + Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */ } shift = norm_l( Amax ); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i < 9; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } shift = add( shift, 1 ); FOR( i = 9; i < 17; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } @@ -190,39 +198,45 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) * Returns: * void */ -void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma ) +void basop_E_LPC_a_add_tilt( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + Word16 gamma /* Q15 */ +) { Word16 i; Word32 Amax, Atmp[M + 2]; Word16 shift; - Amax = L_mult( 16384, a[0] ); + Amax = L_mult( 16384, a[0] ); /* Q27 */ FOR( i = 1; i <= M; i++ ) { - Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) ); + Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) ); /* Q27 */ move32(); - Amax = L_max( Amax, L_abs( Atmp[i] ) ); + Amax = L_max( Amax, L_abs( Atmp[i] ) ); /* Q27 */ } - Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); + Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); /* Q27 */ move32(); - Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); + Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); /* Q27 */ shift = norm_l( Amax ); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i <= M; i++ ) { - ap[i] = round_fx( L_shl( Atmp[i], shift ) ); + ap[i] = round_fx( L_shl( Atmp[i], shift ) ); /* Q11 + shift */ move16(); } - ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); + ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); /* Q12 */ move16(); return; } -static Word16 xsf_to_xsp( Word16 xsf ) +static Word16 xsf_to_xsp( + Word16 xsf /* Q2.56 */ +) { /* xsp = cos(xsf * 3.1415/6400); */ return getCosWord16R2( xsf ); @@ -244,7 +258,10 @@ static Word16 xsf_to_xsp( Word16 xsf ) * Returns: * void */ -void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ) +void basop_lsf2lsp( + const Word16 lsf[], /* Q2.56 */ + Word16 lsp[] /* Q15 */ +) { Word16 i; @@ -252,7 +269,7 @@ void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ) /* convert ISFs to the cosine domain */ FOR( i = 0; i < M; i++ ) { - *lsp++ = xsf_to_xsp( *lsf++ ); + *lsp++ = xsf_to_xsp( *lsf++ ); /* Q15 */ move16(); } diff --git a/lib_com/basop_lsf_tools.c b/lib_com/basop_lsf_tools.c index f378bcbaa..aac96ae5f 100644 --- a/lib_com/basop_lsf_tools.c +++ b/lib_com/basop_lsf_tools.c @@ -62,9 +62,10 @@ static Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 * void */ void basop_E_LPC_f_lsp_a_conversion( - const Word16 *lsp, - Word16 *a, - const Word16 m ) + const Word16 *lsp, /* Q15 */ + Word16 *a, /* Qx */ + const Word16 m /* Q0 */ +) { Word16 i, j, k; Word32 f1[NC_MAX + 1], f2[NC_MAX + 1]; @@ -83,8 +84,8 @@ void basop_E_LPC_f_lsp_a_conversion( Ovf = 0; move16(); - Ovf = E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, Ovf, 1 ); - Ovf2 = E_LPC_f_lsp_pol_get( &lsp[1], f2, nc, Ovf, 1 ); + Ovf = E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, Ovf, 1 ); /* Q0 */ + Ovf2 = E_LPC_f_lsp_pol_get( &lsp[1], f2, nc, Ovf, 1 ); /* Q0 */ IF( sub( Ovf2, Ovf ) != 0 ) { /* to ensure similar scaling for f1 and f2 in case @@ -99,9 +100,9 @@ void basop_E_LPC_f_lsp_a_conversion( k = sub( nc, 1 ); FOR( i = 0; i <= k; i++ ) { - f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); + f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); /* Q23 */ move32(); - f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] ); + f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] ); /* Q23 */ move32(); } @@ -113,8 +114,8 @@ void basop_E_LPC_f_lsp_a_conversion( t0 = L_deposit_l( 0 ); FOR( i = 1; i <= nc; i++ ) { - t0 = L_max( t0, L_abs( L_add( f1[i], f2[i] ) ) ); - t0 = L_max( t0, L_abs( L_sub( f1[i], f2[i] ) ) ); + t0 = L_max( t0, L_abs( L_add( f1[i], f2[i] ) ) ); /* Q23 */ + t0 = L_max( t0, L_abs( L_sub( f1[i], f2[i] ) ) ); /* Q23 */ } k = s_min( norm_l( t0 ), 6 ); a[0] = shl( 256, k ); @@ -129,12 +130,12 @@ void basop_E_LPC_f_lsp_a_conversion( FOR( i = 1; i <= nc; i++ ) { /* a[i] = 0.5*(f1[i] + f2[i]) */ - t0 = L_add( f1[i], f2[i] ); + t0 = L_add( f1[i], f2[i] ); /* Q23 */ t0 = L_shl( t0, k ); a[i] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ /* a[j] = 0.5*(f1[i] - f2[i]) */ - t0 = L_sub( f1[i], f2[i] ); + t0 = L_sub( f1[i], f2[i] ); /* Q23 */ t0 = L_shl( t0, k ); a[j] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ j--; @@ -153,14 +154,14 @@ void basop_E_LPC_f_lsp_a_conversion( void basop_reorder_lsf( Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ const Word16 min_dist, /* i : minimum required distance x2.56*/ - const Word16 n, /* i : LPC order */ - const Word32 Fs /* i : sampling frequency */ + const Word16 n, /* i : LPC order Q0*/ + const Word32 Fs /* i : sampling frequency Q0*/ ) { Word16 i, lsf_min, n_m_1; Word16 lsf_max; - lsf_min = min_dist; + lsf_min = min_dist; /* Q2.56 */ move16(); /*-----------------------------------------------------------------------* @@ -171,10 +172,10 @@ void basop_reorder_lsf( { if ( sub( lsf[i], lsf_min ) < 0 ) { - lsf[i] = lsf_min; + lsf[i] = lsf_min; /* Q2.56 */ move16(); } - lsf_min = add( lsf[i], min_dist ); + lsf_min = add( lsf[i], min_dist ); /* Q2.56 */ } /*-----------------------------------------------------------------------* @@ -183,17 +184,17 @@ void basop_reorder_lsf( lsf_max = round_fx( L_sub( L_shr( L_mult0( extract_l( L_shr( Fs, 1 ) ), 1311 ), 9 - 16 ), L_deposit_h( min_dist ) ) ); /* Q0 + Q9 , 1311 is 2.56 in Q9 */ - n_m_1 = sub( n, 1 ); + n_m_1 = sub( n, 1 ); /* Q0 */ IF( sub( lsf[n_m_1], lsf_max ) > 0 ) /* If danger of unstable filter in case of resonance in HF */ { FOR( i = n_m_1; i >= 0; i-- ) /* Reverify the minimum LSF gap in the reverse direction */ { if ( sub( lsf[i], lsf_max ) > 0 ) { - lsf[i] = lsf_max; + lsf[i] = lsf_max; /* Q2.56 */ move16(); } - lsf_max = sub( lsf[i], min_dist ); + lsf_max = sub( lsf[i], min_dist ); /* Q2.56 */ } } @@ -229,11 +230,12 @@ void basop_reorder_lsf( *-----------------------------------------------------------* */ static Word16 E_LPC_f_lsp_pol_get( - const Word16 lsp[], - Word32 f[], - const Word16 n, - const Word16 past_Ovf, - const Word16 isMODE1 ) + const Word16 lsp[], /* Q15 */ + Word32 f[], /* Q23 */ + const Word16 n, /* Q0 */ + const Word16 past_Ovf, /* Q0 */ + const Word16 isMODE1 /* Q0 */ +) { /* All computation in Q23 */ const Word16 *plsp; @@ -245,8 +247,8 @@ static Word16 E_LPC_f_lsp_pol_get( Word16 m2; #ifdef BASOP_NOGLOB Flag Overflow; -#endif /* BASOP_NOGLOB */ - +#endif /* BASOP_NOGLOB */ + move16(); // move for Ovf = 0 Q_out = 31 - 23; move16(); @@ -271,7 +273,7 @@ static Word16 E_LPC_f_lsp_pol_get( b = *plsp; move16(); m2 = shl( -2, sub( 15, Q_out ) ); - f[1] = L_mult( b, m2 ); + f[1] = L_mult( b, m2 ); /* Q23 */ move32(); FOR( i = 2; i <= n; i++ ) @@ -284,16 +286,16 @@ static Word16 E_LPC_f_lsp_pol_get( /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/ move32(); - f[i] = L_shl( L_sub( f[i - 2], Mpy_32_16_1( f[i - 1], b ) ), 1 ); + f[i] = L_shl( L_sub( f[i - 2], Mpy_32_16_1( f[i - 1], b ) ), 1 ); /* Q23 */ FOR( j = i - 1; j > 1; j-- ) { /*f[j] += b*f[j-1] + f[j-2];*/ move32(); - f[j] = L_add( f[j], L_sub( f[j - 2], L_shl( Mpy_32_16_1( f[j - 1], b ), 1 ) ) ); + f[j] = L_add( f[j], L_sub( f[j - 2], L_shl( Mpy_32_16_1( f[j - 1], b ), 1 ) ) ); /* Q23 */ } move32(); - f[1] = L_add( f[1], b32 ); + f[1] = L_add( f[1], b32 ); /* Q23 */ } @@ -305,7 +307,7 @@ static Word16 E_LPC_f_lsp_pol_get( #endif /* BASOP_NOGLOB */ /* If an overflow is detected, redo the computation with 1 bit less */ Ovf = add( Ovf, 1 ); - Ovf = E_LPC_f_lsp_pol_get( lsp, f, n, Ovf, isMODE1 ); + Ovf = E_LPC_f_lsp_pol_get( lsp, f, n, Ovf, isMODE1 ); /* Q0 */ } return Ovf; } diff --git a/lib_com/basop_proto_func.h b/lib_com/basop_proto_func.h index d8b9768a1..0580db98e 100644 --- a/lib_com/basop_proto_func.h +++ b/lib_com/basop_proto_func.h @@ -53,18 +53,59 @@ #define INT_FS_FX 12800 /* internal sampling frequency */ void basop_lsp2a_stab( const Word16 *lsp, Word16 *a ); -void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ); -void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ); -void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ); -void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma ); -void basop_reorder_lsf( Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 Fs ); -void basop_E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); +void basop_lsf2lsp( + const Word16 lsf[], /* Q2.56 */ + Word16 lsp[] /* Q15 */ +); + +void basop_weight_a( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 gamma /* Q15 */ +); + +void basop_weight_a_inv( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma /* Q14 */ +); +void basop_E_LPC_a_add_tilt( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + Word16 gamma /* Q14 */ +); +void basop_reorder_lsf( + Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ + const Word16 min_dist, /* i : minimum required distance x2.56*/ + const Word16 n, /* i : LPC order Q0*/ + const Word32 Fs /* i : sampling frequency Q0*/ +); +void basop_E_LPC_f_lsp_a_conversion( + const Word16 *lsp, /* Q15 */ + Word16 *a, /* Qx */ + const Word16 m /* Q0 */ +); /* tcx_utils.c */ -void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp ); - -void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] ); -void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] ); +void basop_lpc2mdct( + Word16 *lpcCoeffs, /* Q12 */ + Word16 lpcOrder, /* Q0 */ + Word16 *mdct_gains, /* Q12 */ + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, /* Q12 */ + Word16 *mdct_inv_gains_exp ); + +void basop_PsychAdaptLowFreqDeemph( + Word32 x[], /* Q16 */ + const Word16 lpcGains[], /* exp(lpcGains_e) */ + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] /* Qx */ +); +void basop_mdct_noiseShaping_interp( + Word32 x[], /* Q16 */ + Word16 lg, /* Q0 */ + Word16 gains[], /* exp(gain_exp) */ + Word16 gains_exp[] ); #endif diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c index 5730b2212..579711080 100644 --- a/lib_com/basop_tcx_utils.c +++ b/lib_com/basop_tcx_utils.c @@ -60,7 +60,13 @@ // return tmp; // } -void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp ) +void basop_lpc2mdct( + Word16 *lpcCoeffs, /* Q12 */ + Word16 lpcOrder, /* Q0 */ + Word16 *mdct_gains, /* Q12 */ + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, /* Q12 */ + Word16 *mdct_inv_gains_exp ) { Word32 RealData[FDNS_NPTS]; Word32 ImagData[FDNS_NPTS]; @@ -80,9 +86,9 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor /* pre-twiddle */ FOR( i = 0; i <= lpcOrder; i++ ) { - RealData[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); + RealData[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); /* Q28 */ move32(); - ImagData[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); + ImagData[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); /* Q28 */ move32(); ptwiddle += step; } @@ -103,7 +109,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor /*Get amplitude*/ - j = FDNS_NPTS - 1; + j = FDNS_NPTS - 1; /* Q0 */ k = 0; move16(); move16(); @@ -135,7 +141,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_gains != NULL ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /* exp(g_e) */ move16(); } @@ -147,7 +153,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_inv_gains != NULL ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /* exp(ig_e) */ move16(); } @@ -157,7 +163,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor move16(); } - k = add( k, 1 ); + k++; s = sub( norm_l( L_max( L_abs( RealData[j] ), L_abs( ImagData[j] ) ) ), 1 ); @@ -185,7 +191,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_gains != NULL ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /* exp(g_e) */ move16(); } @@ -197,7 +203,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_inv_gains != NULL ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /* exp(ig_e) */ move16(); } @@ -207,13 +213,17 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor move16(); } - j = sub( j, 1 ); - k = add( k, 1 ); + j--; + k++; } } -void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] ) +void basop_mdct_noiseShaping_interp( + Word32 x[], /* Q16 */ + Word16 lg, /* Q0 */ + Word16 gains[], /* exp(gain_exp) */ + Word16 gains_exp[] ) { Word16 i, j, jp, jn, k, l; Word16 g, pg, ng, e, tmp; @@ -251,16 +261,16 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.375f ) ), g, FL2WORD16( 0.625f ) ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 12288 /* 0.375 in Q15 */ ), g, 20480 /* 0.625 in Q15 */ ); /* exp(gains_exp) */ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.125f ) ), g, FL2WORD16( 0.875f ) ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 4096 /* 0.125 in Q15*/ ), g, 28672 /* 0.875 in Q15 */ ); /* exp(gains_exp) */ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /* Q16 */ move32(); /* common exponent for g and ng */ - g = gains[j]; + g = gains[j]; /* exp(gains_exp) */ move16(); tmp = sub( gains_exp[j], gains_exp[jn] ); if ( tmp > 0 ) @@ -269,19 +279,19 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, FL2WORD16( 0.875f ) ), ng, FL2WORD16( 0.125f ) ); - x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); + tmp = mac_r( L_mult( g, 28672 /* 0.875 in Q15 */ ), ng, 4096 /* 0.125 in Q15*/ ); /* exp(gains_exp) */ + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( g, FL2WORD16( 0.625f ) ), ng, FL2WORD16( 0.375f ) ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 20480 /* 0.625 in Q15 */ ), ng, 12288 /* 0.375 in Q15 */ ); /* exp(gains_exp) */ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /* Q16 */ move32(); jp = j; move16(); j = jn; move16(); - jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); + jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); /* Q0 */ } } ELSE IF( sub( k, 5 ) == 0 ) @@ -310,16 +320,16 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.40f ) ), g, FL2WORD16( 0.60f ) ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 13107 /* 0.4 in Q15 */ ), g, 19661 /* 0.6 in Q15 */ ); /* exp(gains_exp) */ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.20f ) ), g, FL2WORD16( 0.80f ) ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 6554 /* 0.2 in Q15 */ ), g, 26214 /* 0.8 in Q15 */ ); /* exp(gains_exp) */ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /* Q16 */ move32(); - x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], gains[j] ), gains_exp[j] ); + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], gains[j] ), gains_exp[j] ); /* Q16 */ move32(); /* common exponent for g and ng */ @@ -332,19 +342,19 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, FL2WORD16( 0.80f ) ), ng, FL2WORD16( 0.20f ) ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 26214 /* 0.8 in Q15 */ ), ng, 6554 /* 0.2 in Q15 */ ); /* exp(gains_exp) */ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( g, FL2WORD16( 0.60f ) ), ng, FL2WORD16( 0.40f ) ); - x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); + tmp = mac_r( L_mult( g, 19661 /* 0.6 in Q15 */ ), ng, 13107 /* 0.4 in Q15 */ ); /* exp(gains_exp) */ + x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); /* Q16 */ move32(); jp = j; move16(); j = jn; move16(); - jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); + jn = s_min( add( jn, 1 ), FDNS_NPTS - 1 ); /* Q0 */ } } ELSE /* no interpolation */ @@ -353,7 +363,7 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word { FOR( l = 0; l < k; l++ ) { - *x = L_shl( Mpy_32_16_1( *x, *gains ), *gains_exp ); + *x = L_shl( Mpy_32_16_1( *x, *gains ), *gains_exp ); /* Q16 */ move32(); x++; } @@ -366,7 +376,12 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word } -void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] ) +void basop_PsychAdaptLowFreqDeemph( + Word32 x[], /* Q16 */ + const Word16 lpcGains[], /* exp(lpcGains_e) */ + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] /* Qx */ +) { Word16 i; Word16 max_val, max_e, fac, min_val, min_e, tmp, tmp_e; @@ -424,14 +439,14 @@ void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const W /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ FOR( i = 31; i >= 0; i-- ) { - x[i] = Mpy_32_16_1( x[i], fac ); + x[i] = Mpy_32_16_1( x[i], fac ); /* Q16 */ move32(); if ( lf_deemph_factors != NULL ) { - lf_deemph_factors[i] = mult_r( lf_deemph_factors[i], fac ); + lf_deemph_factors[i] = mult_r( lf_deemph_factors[i], fac ); /* Qx */ move16(); } - fac = mult_r( fac, tmp ); + fac = mult_r( fac, tmp ); /* Q15 */ } } } diff --git a/lib_com/bitalloc.c b/lib_com/bitalloc.c index 7e1c92f9c..0daed8fc5 100644 --- a/lib_com/bitalloc.c +++ b/lib_com/bitalloc.c @@ -228,14 +228,14 @@ void bitalloc( /*! r: Integer (truncated) number of allocated bits */ int16_t BitAllocF( - int16_t *y, /* i : norm of sub-vectors */ - int32_t bit_rate, /* i : bitrate */ - int16_t B, /* i : number of available bits */ - int16_t N, /* i : number of sub-vectors */ - int16_t *R, /* o : bit-allocation indicator */ - int16_t *Rsubband, /* o : sub-band bit-allocation vector (Q3) */ - const int16_t hqswb_clas, /* i : hq swb class */ - const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ + Word16 *y, /* i : norm of sub-vectors Q0*/ + Word32 bit_rate, /* i : bitrate Q0*/ + Word16 B, /* i : number of available bits Q0*/ + Word16 N, /* i : number of sub-vectors Q0*/ + Word16 *R, /* o : bit-allocation indicator Q0*/ + Word16 *Rsubband, /* o : sub-band bit-allocation vector Q3*/ + const Word16 hqswb_clas, /* i : hq swb class Q0*/ + const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE Q0*/ ) { Word16 fac; @@ -256,18 +256,18 @@ int16_t BitAllocF( fac = 3; if ( L_sub( bit_rate, 32000 ) < 0 ) { - bs = 2; + bs = 2; /* Q0 */ } else { - bs = 3; + bs = 3; /* Q0 */ } - low_rate = 1; + low_rate = 1; /* Q0 */ - Nmin = N; + Nmin = N; /* Q0 */ if ( sub( Nmin, SFM_N ) > 0 ) { - Nmin = SFM_N; + Nmin = SFM_N; /* Q0 */ } /* Initial bits distribution */ @@ -278,13 +278,13 @@ int16_t BitAllocF( m_fx = 0; for ( i = 0; i < num_env_bands; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = 0; n = 0; - tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); + tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -303,7 +303,7 @@ int16_t BitAllocF( move32(); /*exp1 - 15*/ Rsubband_w32_fx[i] = L_shl( Rsubband_w32_fx[i], sub( 30, exp1 ) ); /*Q15*/ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q15*/ } else { @@ -319,14 +319,14 @@ int16_t BitAllocF( m_fx = 0; for ( i = 0; i < N; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = 0; n = 0; - tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); + tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -334,7 +334,7 @@ int16_t BitAllocF( exp1 = add( 29, sub( exp2, exp1 ) ); for ( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ if ( Rsubband_w32_fx[i] > 0 ) @@ -344,7 +344,7 @@ int16_t BitAllocF( move32(); /*exp1 - 15*/ Rsubband_w32_fx[i] = L_shl( Rsubband_w32_fx[i], sub( 30, exp1 ) ); /*Q15*/ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q15*/ } else { @@ -381,7 +381,7 @@ int16_t BitAllocF( { n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } else { @@ -409,14 +409,14 @@ int16_t BitAllocF( } else if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) <= 0 ) { - B = sub( B, Nb[i] ); - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + B = sub( B, Nb[i] ); /* Q0 */ + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } else { - n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + n = add( n, Nb[i] ); /* Q0 */ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } } } @@ -448,18 +448,18 @@ int16_t BitAllocF( { if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 0 ) { - Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); /* Q15 */ if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 0 ) { - n = add( n, Nb[i] ); + n = add( n, Nb[i] ); /* Q0 */ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } else { - B = sub( B, Nb[i] ); + B = sub( B, Nb[i] ); /* Q0 */ - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } } @@ -472,7 +472,7 @@ int16_t BitAllocF( { if ( Rsubband_w32_fx[i] > 0 ) { - B = add( B, Nb[i] ); + B = add( B, Nb[i] ); /* Q0 */ Rsubband_w32_fx[i] = 0; move32(); if ( B >= 0 ) @@ -489,12 +489,12 @@ int16_t BitAllocF( tmp = 0; for ( i = 0; i < N; i++ ) { - Rsubband[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); - tmp = add( tmp, Rsubband[i] ); + Rsubband[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); /* Q3 */ + tmp = add( tmp, Rsubband[i] ); /* Q3 */ } - B = Bits; - B_w16_fx = shl( B, 3 ); + B = Bits; /* Q0 */ + B_w16_fx = shl( B, 3 ); /* Q3 */ if ( sub( tmp, B_w16_fx ) > 0 ) { tmp = sub( tmp, B_w16_fx ); @@ -502,19 +502,19 @@ int16_t BitAllocF( { if ( sub( Rsubband[i], add( shl( Nb[i], 3 ), tmp ) ) >= 0 ) { - Rsubband[i] = sub( Rsubband[i], tmp ); + Rsubband[i] = sub( Rsubband[i], tmp ); /* Q3 */ BREAK; } } } else { - tmp = sub( tmp, B_w16_fx ); + tmp = sub( tmp, B_w16_fx ); /* Q3 */ for ( i = 0; i < N; i++ ) { if ( Rsubband[i] > 0 ) { - Rsubband[i] = sub( Rsubband[i], tmp ); + Rsubband[i] = sub( Rsubband[i], tmp ); /* Q3 */ BREAK; } } @@ -524,8 +524,8 @@ int16_t BitAllocF( tmp = 0; for ( i = 0; i < N; i++ ) { - tmp = add( tmp, Rsubband[i] ); - R[i] = shr( Rsubband[i], 3 ); + tmp = add( tmp, Rsubband[i] ); /* Q3 */ + R[i] = shr( Rsubband[i], 3 ); /* Q0 */ } return shr( tmp, 3 ); @@ -552,6 +552,9 @@ static void Bit_group_fx( Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; UWord32 lo; + move32(); + move32(); + move32(); /* initialization for bit allocation in one group*/ tmp = 6554; @@ -576,9 +579,9 @@ static void Bit_group_fx( FOR( i = 0; i < band_num; i++ ) { - y_index[i] = y[add( i, start_band )]; + y_index[i] = y[i + start_band]; /* Q0 */ move16(); - index[i] = i; + index[i] = i; /* Q0 */ move16(); } @@ -622,15 +625,15 @@ static void Bit_group_fx( y_index[j] = 0; move16(); } - R_temp_fx[j] = 2097152; - move16(); /*Q21 = 1 move16(); */ + R_temp_fx[j] = 2097152; /* 1 in Q21 */ + move16(); } i = sub( band_num, 1 ); norm_sum = 0; /*Q0 */ FOR( k = 0; k <= i; k++ ) { - norm_sum = add( norm_sum, y_index[k] ); + norm_sum = add( norm_sum, y_index[k] ); /* Q0 */ } FOR( j = 0; j < band_num; j++ ) @@ -653,7 +656,7 @@ static void Bit_group_fx( FOR( k = 0; k <= i; k++ ) { L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); - Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); + Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); /*Q(30-exp) */ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); move32(); /*Q21 */ @@ -665,7 +668,7 @@ static void Bit_group_fx( { R_temp_fx[i] = 0; move32(); - norm_sum = sub( norm_sum, y_index[i] ); + norm_sum = sub( norm_sum, y_index[i] ); /* Q0 */ i--; } ELSE @@ -683,8 +686,8 @@ static void Bit_group_fx( y_index[j] = 0; move16(); } - R_temp_fx[j] = 2097152; - move32(); /*Q21 = 1 */ + R_temp_fx[j] = 2097152; /* 1 in Q21 */ + move32(); } FOR( j = bit_band; j < band_num; j++ ) @@ -696,7 +699,7 @@ static void Bit_group_fx( norm_sum = 0; FOR( k = 0; k < bit_band; k++ ) { - norm_sum = add( norm_sum, y_index[k] ); + norm_sum = add( norm_sum, y_index[k] ); /* Q0 */ } i = bit_band; @@ -719,7 +722,7 @@ static void Bit_group_fx( FOR( k = 0; k < i; k++ ) { L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); - Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); + Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); /*Q(30-exp) */ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); move32(); /*Q21 */ } @@ -732,7 +735,7 @@ static void Bit_group_fx( { FOR( m = k; m < i; m++ ) { - norm_sum = sub( norm_sum, y_index[m] ); + norm_sum = sub( norm_sum, y_index[m] ); /* Q0 */ R_temp_fx[m] = 0; move32(); /*Q21 */ } @@ -758,7 +761,7 @@ static void Bit_group_fx( { j = index[k]; move16(); - Rsubband_fx[add( j, start_band )] = R_temp_fx[k]; + Rsubband_fx[j + start_band] = R_temp_fx[k]; /* Q21 */ move32(); } @@ -772,12 +775,12 @@ static void Bit_group_fx( *-------------------------------------------------------------------*/ /*! r: Integer (truncated) number of allocated bits */ -int16_t BitAllocWB( - int16_t *y, /* i : norm of sub-vectors */ - int16_t B, /* i : number of available bits */ - int16_t N, /* i : number of sub-vectors */ - int16_t *R, /* o : bit-allocation indicator */ - int16_t *Rsubband /* o : sub-band bit-allocation vector (Q3) */ +Word16 BitAllocWB( + Word16 *y, /* i : norm of sub-vectors Q0*/ + Word16 B, /* i : number of available bits Q0*/ + Word16 N, /* i : number of sub-vectors Q0*/ + Word16 *R, /* o : bit-allocation indicator Q0*/ + Word16 *Rsubband /* o : sub-band bit-allocation vector (Q3) Q3*/ ) { Word16 t_fx; @@ -791,18 +794,18 @@ int16_t BitAllocWB( Word32 Rsubband_buf[NB_SFM]; UWord16 lo; - BANDS = N; + BANDS = N; /* Q0 */ move16(); IF( sub( BANDS, SFM_N ) > 0 ) { - BANDS = SFM_N; + BANDS = SFM_N; /* Q0 */ move16(); } /* Init Rsubband to non-zero values for bands to be allocated bits */ FOR( k = 0; k < BANDS; k++ ) { Rsubband_buf[k] = 2097152; - move32(); /*Q21 */ + move32(); /*1 in Q21 */ } /* Calculate the norm sum and average of sub-band */ Rsum_sub_fx[0] = 0; @@ -857,7 +860,7 @@ int16_t BitAllocWB( R_diff_32_fx[1] = L_sub( Ravg_sub_32_fx[1], Ravg_sub_32_fx[2] ); move32(); /*Q16 */ - IF( L_sub( R_diff_32_fx[0], 393216 ) < 0 && L_sub( R_diff_32_fx[1], 245760 ) < 0 ) + IF( L_sub( R_diff_32_fx[0], 393216 /* 32 in Q16 */ ) < 0 && L_sub( R_diff_32_fx[1], 245760 /* 3.75 in Q16 */ ) < 0 ) { IF( Rsum_fx == 0 ) { @@ -878,47 +881,47 @@ int16_t BitAllocWB( B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } - L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B2 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B2, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B2, 1 ), Rsum_fx ) ) >= 0 ) { - B2 = add( B2, 1 ); + B2 = add( B2, 1 ); /* Q0 */ } - L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B3 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B3, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B3, 1 ), Rsum_fx ) ) >= 0 ) { - B3 = add( B3, 1 ); + B3 = add( B3, 1 ); /* Q0 */ } } - IF( L_sub( Ravg_sub_32_fx[2], 786432 ) > 0 ) + IF( L_sub( Ravg_sub_32_fx[2], 786432 /* 12 in Q16 */ ) > 0 ) { B_saved = 0; move16(); IF( sub( B1, 288 ) > 0 ) { - B_saved = sub( B1, 288 ); - B1 = 288; + B_saved = sub( B1, 288 ); /* Q0 */ + B1 = 288; /* Q0 */ move16(); } IF( sub( B2, 256 ) > 0 ) { - tmp = sub( B2, 256 ); - B_saved = add( B_saved, tmp ); - B2 = 256; + tmp = sub( B2, 256 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ + B2 = 256; /* Q0 */ move16(); } IF( sub( B3, 96 ) > 0 ) { - tmp = sub( B3, 96 ); - B_saved = add( B_saved, tmp ); - B3 = 96; + tmp = sub( B3, 96 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ + B3 = 96; /* Q0 */ move16(); } @@ -926,24 +929,24 @@ int16_t BitAllocWB( { IF( sub( B1, 288 ) == 0 ) { - tmp = shr( B_saved, 1 ); - B2 = add( B2, tmp ); - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B2 = add( B2, tmp ); /* Q0 */ + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = shr( B_saved, 1 ); - B1 = add( B1, tmp ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B1 = add( B1, tmp ); /* Q0 */ IF( sub( B2, 256 ) == 0 ) { - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = sub( B, B1 ); - B2 = sub( tmp, B3 ); + tmp = sub( B, B1 ); /* Q0 */ + B2 = sub( tmp, B3 ); /* Q0 */ } } } @@ -968,24 +971,24 @@ int16_t BitAllocWB( ELSE { exp = norm_s( Rsum_fx ); - tmp = shl( Rsum_fx, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ - L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + tmp = shl( Rsum_fx, exp ); /*Q(exp) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp) */ + L_tmp1 = L_mult( B, Rsum_sub_fx[0] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } - Mpy_32_16_ss( 1975684956, shl( B, 5 ), &L_tmp1, &lo ); - Mpy_32_16_ss( L_tmp1, shl( Rsum_sub_fx[1], 7 ), &L_tmp1, &lo ); - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); - B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */ + Mpy_32_16_ss( 1975684956 /* 0.92 in Q31 */, shl( B, 5 ), &L_tmp1, &lo ); /*Q(31+5-15=21) */ + Mpy_32_16_ss( L_tmp1, shl( Rsum_sub_fx[1], 7 ), &L_tmp1, &lo ); /*Q(21+7-15=13) */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(27-exp) */ + B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_shl( L_mult( B2, Rsum_fx ), 12 ) ) > 0 && L_sub( L_add( L_tmp1, 2 ), L_shl( L_mult( add( B2, 1 ), Rsum_fx ), 12 ) ) >= 0 ) { - B2 = add( B2, 1 ); + B2 = add( B2, 1 ); /* Q0 */ } - tmp = sub( B, B1 ); + tmp = sub( B, B1 ); /* Q0 */ B3 = sub( tmp, B2 ); } } @@ -1004,7 +1007,7 @@ int16_t BitAllocWB( Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx ); FOR( i = 0; i < BANDS; i++ ) { - Rsubband[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); + Rsubband[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); /* Q3 */ move16(); } diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index c20235e39..e7d7602d6 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -30,22 +30,22 @@ void bitalloc_fx( Word16 SFM_thr = SFM_G1G2; move16(); - N = sub( N, 1 ); + N = sub( N, 1 ); /* Q0 */ if ( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { - SFM_thr = 22; + SFM_thr = 22; /* Q0 */ move16(); } fac = 3; move16(); - K = sub( K, 2 ); + K = sub( K, 2 ); /* Q0 */ im = 1; move16(); - diff = sum; + diff = sum; /* Q0 */ move16(); - n = shr( sum, 3 ); + n = shr( sum, 3 ); /* Q0 */ FOR( i = 0; i < n; i++ ) { k = 0; @@ -55,14 +55,14 @@ void bitalloc_fx( FOR( m = 1; m < im; m++ ) { #ifdef BASOP_NOGLOB - v = sub_o( temp, y[m], &Overflow ); -#else /* BASOP_NOGLOB */ + v = sub_o( temp, y[m], &Overflow ); /* Q0 */ +#else /* BASOP_NOGLOB */ v = sub( temp, y[m] ); #endif temp = s_max( temp, y[m] ); if ( v < 0 ) { - k = m; + k = m; /* Q0 */ move16(); } } @@ -73,7 +73,7 @@ void bitalloc_fx( move16(); if ( LT_16( im, N ) ) { - im = add( im, 1 ); + im = add( im, 1 ); /* Q0 */ } } @@ -83,9 +83,9 @@ void bitalloc_fx( test(); IF( GE_16( sum, sfmsize[j] ) && LT_16( r[j], K ) ) { - y[k] = sub( y[k], fac ); + y[k] = sub( y[k], fac ); /* Q0 */ move16(); - r[j] = add( r[j], 1 ); + r[j] = add( r[j], 1 ); /* Q0 */ move16(); if ( GE_16( r[j], K ) ) @@ -93,7 +93,7 @@ void bitalloc_fx( y[k] = -32768; move16(); } - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ } ELSE { @@ -103,7 +103,7 @@ void bitalloc_fx( test(); if ( EQ_16( k, im ) && LT_16( im, N ) ) { - im = add( im, 1 ); + im = add( im, 1 ); /* Q0 */ } } @@ -113,9 +113,9 @@ void bitalloc_fx( BREAK; } - diff = sum; + diff = sum; /* Q0 */ move16(); - v = sub( N, 1 ); + v = sub( N, 1 ); /* Q0 */ IF( GT_16( k, v ) ) { @@ -125,7 +125,7 @@ void bitalloc_fx( { if ( LT_16( ii, N ) ) { - im = add( ii, 1 ); + im = add( ii, 1 ); /* Q0 */ } BREAK; } @@ -138,7 +138,7 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); test(); @@ -146,7 +146,7 @@ void bitalloc_fx( { r[j] = 1; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; @@ -167,7 +167,7 @@ void bitalloc_fx( { r[j] = 2; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; @@ -180,14 +180,14 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); IF( LT_16( j, SFM_G1 ) && r[j] == 0 ) { r[j] = 1; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; @@ -200,14 +200,14 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); IF( LT_16( j, SFM_G1 ) && EQ_16( r[j], 1 ) ) { - r[j] = 2; + r[j] = 2; /* Q0 */ move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; @@ -239,6 +239,7 @@ Word16 BitAllocF_fx( { Word16 fac; Word16 i, n, Nmin, Bits, bs, low_rate = 0; + move16(); Word16 m_fx; Word32 t_fx, B_fx; @@ -248,6 +249,7 @@ Word16 BitAllocF_fx( Word16 B_w16_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif set32_fx( Rsubband_w32_fx, 0, NB_SFM ); @@ -268,11 +270,11 @@ Word16 BitAllocF_fx( low_rate = 1; move16(); - Nmin = N; + Nmin = N; /* Q0 */ move16(); if ( GT_16( Nmin, SFM_N ) ) { - Nmin = SFM_N; + Nmin = SFM_N; /* Q0 */ move16(); } @@ -287,14 +289,14 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < num_env_bands; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[sub( num_env_bands, 1 )], shl( band_end_HQ[sub( num_env_bands, 1 )], 1 ) ); + tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -303,7 +305,7 @@ Word16 BitAllocF_fx( FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ IF( Rsubband_w32_fx[i] > 0 ) @@ -331,15 +333,15 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < N; i++ ) { - L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); + L_tmp1 = L_mac0( L_tmp1, Nb[i], y[i] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[sub( N, 1 )], shl( band_end_HQ[sub( N, 1 )], 1 ) ); + tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -347,7 +349,7 @@ Word16 BitAllocF_fx( exp1 = add( 29, sub( exp2, exp1 ) ); FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[sub( N, 1 )] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ IF( Rsubband_w32_fx[i] > 0 ) @@ -357,7 +359,7 @@ Word16 BitAllocF_fx( Rsubband_w32_fx[i] = L_shl( L_tmp3, sub( 30, exp1 ) ); /*Q15*/ move32(); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q0*/ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /*Q15*/ } ELSE { @@ -387,14 +389,14 @@ Word16 BitAllocF_fx( { IF( Rsubband_w32_fx[i] > 0 ) { - Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); /* Q15 */ move32(); IF( Rsubband_w32_fx[i] > 0 ) { n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } ELSE { @@ -404,7 +406,7 @@ Word16 BitAllocF_fx( } } } - Bits = B; + Bits = B; /* Q0 */ move16(); /* Impose bit-constraints to subbands with less than minimum bits*/ @@ -423,14 +425,14 @@ Word16 BitAllocF_fx( } ELSE IF( LE_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - B = sub( B, Nb[i] ); - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + B = sub( B, Nb[i] ); /* Q0 */ + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } ELSE { - n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + n = add( n, Nb[i] ); /* Q0 */ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } } } @@ -463,19 +465,19 @@ Word16 BitAllocF_fx( { IF( GT_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); + Rsubband_w32_fx[i] = L_msu( Rsubband_w32_fx[i], m_fx, Nb[i] ); /* Q15 */ move32(); IF( GT_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - n = add( n, Nb[i] ); + n = add( n, Nb[i] ); /* Q0 */ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } ELSE { - B = sub( B, Nb[i] ); + B = sub( B, Nb[i] ); /* Q0 */ - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } } @@ -488,7 +490,7 @@ Word16 BitAllocF_fx( { IF( Rsubband_w32_fx[i] > 0 ) { - B = add( B, Nb[i] ); + B = add( B, Nb[i] ); /* Q0 */ Rsubband_w32_fx[i] = L_deposit_l( 0 ); move32(); IF( B >= 0 ) @@ -506,9 +508,9 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < N; i++ ) { - Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); + Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); /* Q3 */ move16(); - tmp = add( tmp, Rsubband_fx[i] ); + tmp = add( tmp, Rsubband_fx[i] ); /* Q3 */ } B = Bits; @@ -520,7 +522,7 @@ Word16 BitAllocF_fx( { IF( GE_16( Rsubband_fx[i], add( shl( Nb[i], 3 ), tmp ) ) ) { - Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); + Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); /* Q3 */ move16(); BREAK; } @@ -533,7 +535,7 @@ Word16 BitAllocF_fx( { IF( Rsubband_fx[i] > 0 ) { - Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); + Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); /* Q3 */ move16(); BREAK; } @@ -545,8 +547,8 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < N; i++ ) { - tmp = add( tmp, Rsubband_fx[i] ); - R[i] = shr( Rsubband_fx[i], 3 ); + tmp = add( tmp, Rsubband_fx[i] ); /* Q3 */ + R[i] = shr( Rsubband_fx[i], 3 ); /* Q0 */ move16(); } return shr( tmp, 3 ); @@ -571,6 +573,9 @@ static void Bit_group_fx( Word16 factor_fx; Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; + move32(); + move32(); + move32(); /* initialization for bit allocation in one group*/ tmp = 6554; @@ -595,7 +600,7 @@ static void Bit_group_fx( FOR( i = 0; i < band_num; i++ ) { - y_index[i] = y[add( i, start_band )]; + y_index[i] = y[i + start_band]; /* Q0 */ move16(); index[i] = i; move16(); @@ -687,7 +692,7 @@ static void Bit_group_fx( R_temp_fx[i] = L_deposit_h( 0 ); move32(); norm_sum = sub( norm_sum, y_index[i] ); - i = sub( i, 1 ); + i--; } ELSE { @@ -767,7 +772,7 @@ static void Bit_group_fx( } ELSE { - R_sum_fx = L_add( R_sum_fx, R_temp_fx[k] ); + R_sum_fx = L_add( R_sum_fx, R_temp_fx[k] ); /* Q21 */ } } IF( EQ_32( R_sum_fx, R_sum_org_fx ) ) @@ -785,7 +790,7 @@ static void Bit_group_fx( { j = index[k]; move16(); - Rsubband_fx[add( j, start_band )] = R_temp_fx[k]; + Rsubband_fx[j + start_band] = R_temp_fx[k]; /* Q21 */ move32(); } @@ -898,7 +903,7 @@ Word16 BitAllocWB_fx( /* o : t move32(); /*Q16 */ test(); - IF( LT_32( R_diff_32_fx[0], 393216 ) && LT_32( R_diff_32_fx[1], 245760 ) ) + IF( LT_32( R_diff_32_fx[0], 393216 /* 32 in Q16 */ ) && LT_32( R_diff_32_fx[1], 245760 /* 3.75 in Q16 */ ) ) { IF( Rsum_fx == 0 ) { @@ -939,29 +944,29 @@ Word16 BitAllocWB_fx( /* o : t B3 = add( B3, 1 ); } } - IF( GT_32( Ravg_sub_32_fx[2], 786432 ) ) + IF( GT_32( Ravg_sub_32_fx[2], 786432 /* 12 in Q16 */ ) ) { B_saved = 0; move16(); IF( GT_16( B1, 288 ) ) { - B_saved = sub( B1, 288 ); + B_saved = sub( B1, 288 ); /* Q0 */ B1 = 288; move16(); } IF( GT_16( B2, 256 ) ) { - tmp = sub( B2, 256 ); - B_saved = add( B_saved, tmp ); + tmp = sub( B2, 256 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ B2 = 256; move16(); } IF( GT_16( B3, 96 ) ) { - tmp = sub( B3, 96 ); - B_saved = add( B_saved, tmp ); + tmp = sub( B3, 96 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ B3 = 96; move16(); } @@ -970,24 +975,24 @@ Word16 BitAllocWB_fx( /* o : t { IF( EQ_16( B1, 288 ) ) { - tmp = shr( B_saved, 1 ); - B2 = add( B2, tmp ); - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B2 = add( B2, tmp ); /* Q0 */ + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = shr( B_saved, 1 ); - B1 = add( B1, tmp ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B1 = add( B1, tmp ); /* Q0 */ IF( EQ_16( B2, 256 ) ) { - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = sub( B, B1 ); - B2 = sub( tmp, B3 ); + tmp = sub( B, B1 ); /* Q0 */ + B2 = sub( tmp, B3 ); /* Q0 */ } } } @@ -1020,7 +1025,7 @@ Word16 BitAllocWB_fx( /* o : t test(); if ( GT_32( L_tmp1, L_mult( B1, Rsum_fx ) ) && GE_32( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } L_tmp1 = Mult_32_16( 1975684956, shl( B, 5 ) ); /*Q(31+5-15=21) */ L_tmp1 = Mult_32_16( L_tmp1, shl( Rsum_sub_fx[1], 7 ) ); /*Q(21+7-15=13) */ @@ -1031,15 +1036,15 @@ Word16 BitAllocWB_fx( /* o : t { B2 = add( B2, 1 ); } - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } } } IF( LT_16( Rsum_sub_fx[2], 3 ) ) { - B2 = add( B2, B3 ); + B2 = add( B2, B3 ); /* Q0 */ B3 = 0; move16(); } @@ -1050,7 +1055,7 @@ Word16 BitAllocWB_fx( /* o : t Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx ); FOR( i = 0; i < BANDS; i++ ) { - Rsubband_fx[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); + Rsubband_fx[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); /* Q3 */ move16(); } diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index 77f904055..6c9c8fa32 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -53,8 +53,8 @@ /*! r: flag indicating a valid bitrate */ Word16 is_EVS_bitrate( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word16 *Opt_AMR_WB /* i : AMR-WB IO flag */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + Word16 *Opt_AMR_WB /* i : AMR-WB IO flag Q0*/ ) { Word16 j; @@ -109,7 +109,7 @@ Word16 is_EVS_bitrate( /*! r: codec mode */ Word16 get_codec_mode( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate Q0*/ ) { Word16 codec_mode; @@ -168,7 +168,7 @@ Word16 get_codec_mode( BREAK; } - return codec_mode; + return codec_mode; /*Q0*/ } @@ -178,11 +178,12 @@ Word16 get_codec_mode( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t getTcxonly_ivas( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const int16_t is_ism_format /* i : flag indicating ISM format */ + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t is_ism_format /* i : flag indicating ISM format */ ) { int16_t tcxonly = 0; @@ -230,13 +231,12 @@ int16_t getTcxonly_ivas( return tcxonly; } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 getTcxonly_ivas_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 is_ism_format /* i : flag indicating ISM format */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 is_ism_format /* i : flag indicating ISM format Q0*/ ) { Word16 tcxonly = 0; @@ -298,7 +298,7 @@ Word16 getTcxonly_ivas_fx( BREAK; } - return tcxonly; + return tcxonly; /*Q0*/ } #endif @@ -364,14 +364,14 @@ Word16 getTcxonly( #ifdef IVAS_CODE_SWITCHING } #endif - return tcxonly; + return tcxonly; /*Q0*/ } Word16 getTcxonly_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 is_ism_format /* i : flag indicating ISM format */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 is_ism_format /* i : flag indicating ISM format Q0*/ ) { Word16 tcxonly; @@ -435,7 +435,7 @@ Word16 getTcxonly_fx( BREAK; } - return tcxonly; + return tcxonly; /*Q0*/ } /*-------------------------------------------------------------------* @@ -445,9 +445,9 @@ Word16 getTcxonly_fx( *-------------------------------------------------------------------*/ Word16 getCtxHm( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_flag /* i : flag to signal the RF mode */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 rf_flag /* i : flag to signal the RF mode Q0*/ ) { Word16 ctx_hm; @@ -469,7 +469,7 @@ Word16 getCtxHm( move16(); } - return ctx_hm; + return ctx_hm; /*Q0*/ } /*-------------------------------------------------------------------* @@ -479,7 +479,7 @@ Word16 getCtxHm( *-------------------------------------------------------------------*/ Word16 getResq( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate Q0*/ ) { Word16 resq; @@ -492,7 +492,7 @@ Word16 getResq( move16(); } - return resq; + return resq; /*Q0*/ } /*-------------------------------------------------------------------* @@ -502,9 +502,9 @@ Word16 getResq( *-------------------------------------------------------------------*/ Word16 getTnsAllowed( - const Word32 total_brate, /* i : total bitrate */ - const Word16 igf, /* i : flag indicating IGF activity*/ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 igf, /* i : flag indicating IGF activity Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 tnsAllowed; @@ -530,7 +530,7 @@ Word16 getTnsAllowed( } } - return tnsAllowed; + return tnsAllowed; /*Q0*/ } /*-------------------------------------------------------------------* @@ -540,9 +540,9 @@ Word16 getTnsAllowed( *-------------------------------------------------------------------*/ Word16 getRestrictedMode( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ) { Word16 restrictedMode; @@ -569,7 +569,7 @@ Word16 getRestrictedMode( move16(); } - return restrictedMode; + return restrictedMode; /*Q0*/ } /*-------------------------------------------------------------------* @@ -577,7 +577,7 @@ Word16 getRestrictedMode( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED int16_t getMdctWindowLength( const int16_t fscale ) { @@ -587,14 +587,14 @@ int16_t getMdctWindowLength( return mdctWindowLength; } -#ifdef IVAS_FLOAT_FIXED +#else Word16 getMdctWindowLength_fx( - const Word16 fscale ) + const Word16 fscale /*Q0*/ ) { Word16 mdctWindowLength; mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); - return mdctWindowLength; + return mdctWindowLength; /*Q0*/ } #endif // IVAS_FLOAT_FIXED @@ -605,10 +605,10 @@ Word16 getMdctWindowLength_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED Word16 sr2fscale_fx( - const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate Q0*/ ) { - return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); + return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); /*Q0*/ } #endif @@ -678,12 +678,12 @@ int32_t getCoreSamplerateMode2_flt( } Word32 getCoreSamplerateMode2( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag Q0*/ + const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format Q0*/ ) { @@ -767,11 +767,11 @@ Word32 getCoreSamplerateMode2( assert( 0 ); } - return sr_core; + return sr_core; /*Q0*/ } Word16 getTcxBandwidth( - const Word16 bwidth /* i : audio bandwidth */ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { @@ -785,7 +785,7 @@ Word16 getTcxBandwidth( move16(); } - return tcxBandwidth; + return tcxBandwidth; /*Q15*/ } /*-------------------------------------------------------------------* @@ -908,10 +908,10 @@ int16_t getIgfPresent( } #else Word16 getIgfPresent_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 rf_mode /* i : flag to signal the RF mode */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 rf_mode /* i : flag to signal the RF mode Q0*/ ) { Word16 igfPresent; @@ -1008,7 +1008,7 @@ Word16 getIgfPresent_fx( move16(); } - return igfPresent; + return igfPresent; /*Q0*/ } #endif @@ -1053,10 +1053,10 @@ int16_t getCnaPresent( } Word16 getCnaPresent_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 flag_cna; @@ -1079,7 +1079,7 @@ Word16 getCnaPresent_fx( } } - return flag_cna; + return flag_cna; /*Q0*/ } /*-------------------------------------------------------------------* * getTcxLtp() @@ -1088,7 +1088,7 @@ Word16 getCnaPresent_fx( *-------------------------------------------------------------------*/ Word16 getTcxLtp( - const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate Q0*/ ) { Word16 tcxltp; @@ -1102,7 +1102,7 @@ Word16 getTcxLtp( move16(); } - return tcxltp; + return tcxltp; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1112,12 +1112,12 @@ Word16 getTcxLtp( *-------------------------------------------------------------------*/ Word16 initPitchLagParameters( - const Word32 sr_core, - Word16 *pit_min, - Word16 *pit_fr1, - Word16 *pit_fr1b, - Word16 *pit_fr2, - Word16 *pit_max ) + const Word32 sr_core, /*Q0*/ + Word16 *pit_min, /*Q0*/ + Word16 *pit_fr1, /*Q0*/ + Word16 *pit_fr1b, /*Q0*/ + Word16 *pit_fr2, /*Q0*/ + Word16 *pit_max /*Q0*/ ) { Word16 pit_res_max; @@ -1182,7 +1182,7 @@ Word16 initPitchLagParameters( move16(); } - return pit_res_max; + return pit_res_max; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1192,7 +1192,7 @@ Word16 initPitchLagParameters( *-------------------------------------------------------------------*/ Word16 getNumTcxCodedLines( - const Word16 bwidth /* i : audio bandwidth */ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 tcx_coded_lines; @@ -1224,7 +1224,7 @@ Word16 getNumTcxCodedLines( BREAK; } - return tcx_coded_lines; + return tcx_coded_lines; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1234,9 +1234,9 @@ Word16 getNumTcxCodedLines( *-------------------------------------------------------------------*/ Word16 getTcxLpcShapedAri( - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const Word16 element_mode /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 tcx_lpc_shaped_ari; @@ -1253,7 +1253,7 @@ Word16 getTcxLpcShapedAri( move16(); } - return tcx_lpc_shaped_ari; + return tcx_lpc_shaped_ari; /*Q0*/ } @@ -1399,7 +1399,7 @@ void init_tcx_cfg( hTcxCfg->tcx5SizeFB = NS2SA( input_Fs, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; - mdctWindowLength = getMdctWindowLength( fscale ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); mdctWindowLengthFB = (int16_t) ( mdctWindowLength * input_Fs / sr_core ); init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); @@ -1503,21 +1503,21 @@ void init_tcx_cfg( #ifdef IVAS_FLOAT_FIXED void init_tcx_cfg_ivas_fx( TCX_CONFIG_HANDLE hTcxCfg, - const Word32 total_brate, - const Word32 sr_core, - const Word32 input_Fs, - const Word16 L_frame, - const Word16 bwidth, - const Word16 L_frameTCX, - const Word16 fscale, - const Word16 preemph_fac, - const Word16 tcxonly, - const Word16 rf_mode, - const Word16 igf, - const Word16 infoIGFStopFreq, - const Word16 element_mode, - const Word16 ini_frame, - const Word16 MCT_flag ) + const Word32 total_brate, /*Q0*/ + const Word32 sr_core, /*Q0*/ + const Word32 input_Fs, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 bwidth, /*Q0*/ + const Word16 L_frameTCX, /*Q0*/ + const Word16 fscale, /*Q0*/ + const Word16 preemph_fac, /*Q15*/ + const Word16 tcxonly, /*Q0*/ + const Word16 rf_mode, /*Q0*/ + const Word16 igf, /*Q0*/ + const Word16 infoIGFStopFreq, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 ini_frame, /*Q0*/ + const Word16 MCT_flag /*Q0*/ ) { Word16 i; Word16 mdctWindowLength; @@ -1527,14 +1527,14 @@ void init_tcx_cfg_ivas_fx( hTcxCfg->preemph_fac = preemph_fac; move16(); - hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/ move16(); move16(); - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/ mdctWindowLengthFB = (Word16) ( mdctWindowLength * input_Fs / sr_core ); init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); @@ -1556,16 +1556,16 @@ void init_tcx_cfg_ivas_fx( hTcxCfg->tcxRateLoopOpt = 3; move16(); } - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/ move16(); /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/ move16(); /* TNS in TCX */ hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/ move16(); IF( hTcxCfg->fIsTNSAllowed ) @@ -1585,11 +1585,11 @@ void init_tcx_cfg_ivas_fx( } /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/ move16(); /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->resq = getResq( total_brate ); /*Q0*/ move16(); test(); if ( hTcxCfg->resq && !tcxonly ) @@ -1630,7 +1630,7 @@ void init_tcx_cfg_ivas_fx( { i = sub( i, 1 ); } - hTcxCfg->na_scale = scaleTcxTable[i].scale; + hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/ move16(); BREAK; } @@ -1652,14 +1652,14 @@ void init_tcx_cfg_ivas_fx( #ifdef IVAS_FLOAT_FIXED void init_tcx_window_cfg_fx( - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ - const Word32 sr_core, /* i : SR core */ - const Word32 input_Fs, /* i : input/output SR */ - const Word16 L_frame, /* i : L_frame at sr_core */ - const Word16 L_frameTCX, /* i : L_frame at i/o SR */ - const Word16 mdctWindowLength, /* i : window length at sr_core */ - const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ - const Word16 element_mode /* i : mode of CPE/SCE */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle Q0*/ + const Word32 sr_core, /* i : SR core Q0*/ + const Word32 input_Fs, /* i : input/output SR Q0*/ + const Word16 L_frame, /* i : L_frame at sr_core Q0*/ + const Word16 L_frameTCX, /* i : L_frame at i/o SR Q0*/ + const Word16 mdctWindowLength, /* i : window length at sr_core Q0*/ + const Word16 mdctWindowLengthFB, /* i : window length at i/o SR Q0*/ + const Word16 element_mode /* i : mode of CPE/SCE Q0*/ ) { /* Symmetric window = sine LD window*/ @@ -1675,7 +1675,7 @@ void init_tcx_window_cfg_fx( IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); /*Q15*/ } ELSE { @@ -1687,14 +1687,14 @@ void init_tcx_window_cfg_fx( mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, NS2SA_FX2( input_Fs, FRAME_SIZE_NS ) ); /*1.25ms transition window for ACELP->TCX*/ - hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); + hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); /*Q0*/ move16(); mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); - hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); /*Q0*/ move16(); IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); /*Q15*/ } ELSE { @@ -1702,8 +1702,8 @@ void init_tcx_window_cfg_fx( } /*Mid-OLA*/ /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ - hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); - hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); + hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); /*Q0*/ + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); /*Q0*/ move16(); move16(); assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" ); @@ -1711,7 +1711,7 @@ void init_tcx_window_cfg_fx( mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); /*Q15*/ } ELSE { @@ -1726,7 +1726,7 @@ void init_tcx_window_cfg_fx( /* save complexity by copying the small windows if they have the same length */ IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); /*Q15*/ } ELSE { @@ -1735,19 +1735,19 @@ void init_tcx_window_cfg_fx( IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/ } ELSE IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_min_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/ } ELSE { mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); } /* TCX Offset */ - hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); - hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); + hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); /*Q0*/ + hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); /*Q0*/ /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) ); hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) ); @@ -1761,22 +1761,22 @@ void init_tcx_window_cfg_fx( void init_tcx_cfg_fx( TCX_CONFIG_HANDLE hTcxCfg, - const Word32 total_brate, - const Word32 sr_core, - const Word32 input_Fs, - const Word16 L_frame, - const Word16 bwidth, - const Word16 L_frameTCX, - const Word16 fscale, - const Word16 preemph_fac, /*Q15*/ - const Word16 tcxonly, - const Word16 rf_mode, - const Word16 igf, - const Word16 infoIGFStopFreq, - const Word16 element_mode, - const Word16 ini_frame, - const Word16 MCT_flag, - const Word16 fscaleFB ) + const Word32 total_brate, /*Q0*/ + const Word32 sr_core, /*Q0*/ + const Word32 input_Fs, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 bwidth, /*Q0*/ + const Word16 L_frameTCX, /*Q0*/ + const Word16 fscale, /*Q0*/ + const Word16 preemph_fac, /*Q15*/ + const Word16 tcxonly, /*Q0*/ + const Word16 rf_mode, /*Q0*/ + const Word16 igf, /*Q0*/ + const Word16 infoIGFStopFreq, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 ini_frame, /*Q0*/ + const Word16 MCT_flag, /*Q0*/ + const Word16 fscaleFB /*Q0*/ ) { Word16 i; Word16 mdctWindowLength; @@ -1786,15 +1786,15 @@ void init_tcx_cfg_fx( hTcxCfg->preemph_fac = preemph_fac; move16(); - hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/ move16(); move16(); - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); - mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/ + mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); /*Q0*/ init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); /* SQ deadzone & memory quantization*/ hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ @@ -1814,16 +1814,16 @@ void init_tcx_cfg_fx( hTcxCfg->tcxRateLoopOpt = 3; move16(); } - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/ move16(); /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/ move16(); /* TNS in TCX */ hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/ move16(); IF( hTcxCfg->fIsTNSAllowed ) @@ -1843,11 +1843,11 @@ void init_tcx_cfg_fx( } /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/ move16(); /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->resq = getResq( total_brate ); /*Q0*/ move16(); test(); if ( hTcxCfg->resq && !tcxonly ) @@ -1888,7 +1888,7 @@ void init_tcx_cfg_fx( { i = sub( i, 1 ); } - hTcxCfg->na_scale = scaleTcxTable[i].scale; + hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/ move16(); BREAK; } diff --git a/lib_com/deemph.c b/lib_com/deemph.c index 9583a79d4..4e1093120 100644 --- a/lib_com/deemph.c +++ b/lib_com/deemph.c @@ -75,22 +75,22 @@ void deemph_fx_32( Word32 *signal, /* i/o: signal Qx*/ const Word16 mu, /* i : deemphasis factor Q15*/ const int16_t L, /* i : vector size */ - Word32 *mem /* i/o: memory (y[-1]) Qx*/ + Word32 *mem /* i/o: memory (y[-1]) Qx+shift*/ ) { Word16 i; - signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); + signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); /*Qx*/ move32(); FOR( i = 1; i < L; i++ ) { - signal[i] = L_add( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); - signal[i] = L_shl( signal[i], shift ); + signal[i] = L_add( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); /*Qx*/ + signal[i] = L_shl( signal[i], shift ); /*Qx+shift*/ move32(); move32(); } - *mem = signal[L - 1]; + *mem = signal[L - 1]; /*Qx+shift*/ move32(); return; @@ -132,10 +132,10 @@ void deemph_fx( move32(); #endif - L_tmp = L_deposit_h( signal[0] ); + L_tmp = L_deposit_h( signal[0] ); /*Qx+16*/ #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, *mem, mu, &Overflow ); - signal[0] = round_fx_o( L_tmp, &Overflow ); + L_tmp = L_mac_o( L_tmp, *mem, mu, &Overflow ); /*Qx+16*/ + signal[0] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ #else L_tmp = L_mac( L_tmp, *mem, mu ); signal[0] = round_fx( L_tmp ); @@ -144,18 +144,18 @@ void deemph_fx( FOR( i = 1; i < L; i++ ) { - L_tmp = L_deposit_h( signal[i] ); + L_tmp = L_deposit_h( signal[i] ); /*Qx+16*/ #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, signal[i - 1], mu, &Overflow ); - signal[i] = round_fx_o( L_tmp, &Overflow ); -#else /* BASOP_NOGLOB */ + L_tmp = L_mac_o( L_tmp, signal[i - 1], mu, &Overflow ); /*Qx+16*/ + signal[i] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ L_tmp = L_mac( L_tmp, signal[i - 1], mu ); signal[i] = round_fx( L_tmp ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); } - *mem = signal[L - 1]; + *mem = signal[L - 1]; /*Qx*/ move16(); } @@ -181,22 +181,22 @@ void Deemph2( #endif /* saturation can occur in L_mac() */ - L_tmp = L_mult( x[0], 16384 ); - x[0] = mac_r( L_tmp, *mem, mu ); + L_tmp = L_mult( x[0], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ + x[0] = mac_r( L_tmp, *mem, mu ); /*Qx-1*/ move16(); FOR( i = 1; i < L; i++ ) { - L_tmp = L_mult( x[i], 16384 ); + L_tmp = L_mult( x[i], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ #ifdef BASOP_NOGLOB - x[i] = mac_ro( L_tmp, x[i - 1], mu, &Overflow ); + x[i] = mac_ro( L_tmp, x[i - 1], mu, &Overflow ); /*Qx-1*/ #else x[i] = mac_r( L_tmp, x[i - 1], mu ); #endif move16(); } - *mem = x[L - 1]; + *mem = x[L - 1]; /*Qx-1*/ move16(); } @@ -229,15 +229,15 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W #endif /* signal[0] = signal[0] + mu * (*mem); */ - L_tmp = L_deposit_h( *mem ); + L_tmp = L_deposit_h( *mem ); /*Qx+16*/ IF( shift >= 0 ) { - shift = shr( -32768, shift ); + shift = shr( -32768, shift ); /*Q15 - shift*/ FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), x[i], shift, &Overflow ); - x[i] = round_fx_o( L_tmp, &Overflow ); + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), x[i], shift, &Overflow ); /*Qx-shift+16*/ + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ #else L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), x[i], shift ); x[i] = round_fx( L_tmp ); @@ -250,9 +250,9 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_o( x[i], shift, &Overflow ), -32768, &Overflow ); - x[i] = round_fx_o( L_tmp, &Overflow ); -#else /* BASOP_NOGLOB */ + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_o( x[i], shift, &Overflow ), -32768 /*1.0f in Q15*/, &Overflow ); /*Qx-shift+16*/ + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ +#else /* BASOP_NOGLOB */ L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), shr( x[i], shift ), -32768 ); x[i] = round_fx( L_tmp ); #endif @@ -260,7 +260,7 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W } } - *mem = x[L - 1]; + *mem = x[L - 1]; /*Qx-shift*/ move16(); return; diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index c1e1e869c..8e522ccd6 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -113,8 +113,8 @@ int32_t get_delay( } #else Word32 get_delay_fx( /* o : delay value in ms */ - const Word16 what_delay, /* i : what delay? (ENC or DEC) */ - const Word32 io_fs, /* i : input/output sampling frequency */ + const Word16 what_delay, /* i : what delay? (ENC or DEC) Q0*/ + const Word32 io_fs, /* i : input/output sampling frequency Q0*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -123,7 +123,7 @@ Word32 get_delay_fx( /* o : delay value in ms #endif ) { - Word32 delay; + Word32 delay; /*Q0*/ delay = 0; move32(); @@ -131,12 +131,12 @@ Word32 get_delay_fx( /* o : delay value in ms { IF( EQ_16( ivas_format, MONO_FORMAT ) ) /* EVS mono */ { - delay = ( DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS ); + delay = DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS; /*Q0*/ move32(); } ELSE { - delay = IVAS_ENC_DELAY_NS; + delay = IVAS_ENC_DELAY_NS; /*Q0*/ move32(); test(); if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) @@ -149,7 +149,7 @@ Word32 get_delay_fx( /* o : delay value in ms if ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { /* compensate for DirAC/SPAR filterbank delay */ - delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); + delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); /*Q0*/ } } ELSE @@ -158,18 +158,18 @@ Word32 get_delay_fx( /* o : delay value in ms { IF( EQ_32( io_fs, 8000 ) ) { - delay = DELAY_CLDFB_NS; + delay = DELAY_CLDFB_NS; /*Q0*/ move32(); } ELSE { - delay = DELAY_BWE_TOTAL_NS; + delay = DELAY_BWE_TOTAL_NS; /*Q0*/ move32(); } } ELSE /* IVAS */ { - delay = IVAS_DEC_DELAY_NS; + delay = IVAS_DEC_DELAY_NS; /*Q0*/ move32(); #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -180,7 +180,7 @@ Word32 get_delay_fx( /* o : delay value in ms if ( hCldfb != NULL ) { /* compensate for filterbank delay */ - delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); + delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); /*Q0*/ } #ifdef SPLIT_REND_WITH_HEAD_ROT } @@ -188,11 +188,11 @@ Word32 get_delay_fx( /* o : delay value in ms test(); if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ + delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ /*Q0*/ } } } - return delay; + return delay; /*Q0*/ } #endif diff --git a/lib_com/dlpc_bfi_fx.c b/lib_com/dlpc_bfi_fx.c index be4b27696..2d6b11268 100644 --- a/lib_com/dlpc_bfi_fx.c +++ b/lib_com/dlpc_bfi_fx.c @@ -10,20 +10,20 @@ void dlpc_bfi( const Word16 L_frame, - Word16 *lsf_q, /* o : quantized LSFs */ - const Word16 *lsfold, /* i : past quantized LSF */ - const Word16 last_good, /* i : last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ - Word16 mem_MA[], /* i/o: quantizer memory for MA model */ - Word16 mem_AR[], /* i/o: quantizer memory for AR model */ - Word16 *stab_fac, /* i : LSF stability factor */ - Word16 *lsf_adaptive_mean, /* i : LSF adaptive mean, updated when BFI==0 */ - Word16 numlpc, /* i : Number of division per superframe */ - Word16 lsf_cng[], + Word16 *lsf_q, /* o : quantized LSFs 14Q1*1.28*/ + const Word16 *lsfold, /* i : past quantized LSF 14Q1*1.28*/ + const Word16 last_good, /* i : last good received frame Q0*/ + const Word16 nbLostCmpt, /* i : counter of consecutive bad frames Q0*/ + Word16 mem_MA[], /* i/o: quantizer memory for MA model 14Q1*1.28*/ + Word16 mem_AR[], /* i/o: quantizer memory for AR model 14Q1*1.28*/ + Word16 *stab_fac, /* i : LSF stability factor Q15*/ + Word16 *lsf_adaptive_mean, /* i : LSF adaptive mean, updated when BFI==0 14Q1*1.28*/ + Word16 numlpc, /* i : Number of division per superframe Q0*/ + Word16 lsf_cng[], /*Q1*1.28*/ Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized LSFs */ - Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise */ - const Word16 *lsfBase, /* i : base for differential LSF coding */ + Word16 *lsf_q_cng, /* o : quantized LSFs 14Q1*1.28*/ + Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise 14Q1*1.28*/ + const Word16 *lsfBase, /* i : base for differential LSF coding Q1*1.28*/ Word8 tcxonly ) { diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 8211bb406..8d8bb2ef3 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -100,7 +100,7 @@ void enhancer_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -118,7 +118,7 @@ void enhancer_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -138,7 +138,7 @@ void enhancer_fx( /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q15*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -147,13 +147,13 @@ void enhancer_fx( IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ - L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 /*0.19.Q15*/ ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ - L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -199,9 +199,9 @@ void enhancer_fx( pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -215,13 +215,13 @@ void enhancer_fx( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x10000000L, voice_fac, 4915 /*0.15.Q15*/ ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ + tmp = mac_r( 0x10000000L /*0.125.Q31*/, voice_fac, 4096 ); /*Q15 */ } /*----------------------------------------------------------------- @@ -241,7 +241,6 @@ void enhancer_fx( pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); move16(); #endif - move16(); /* in Q_exc */ FOR( i = 1; i < L_SUBFR - 1; i++ ) { @@ -257,8 +256,8 @@ void enhancer_fx( tmp16 = msu_r( L_tmp, code[i - 1], tmp ); L_tmp = L_shl( L_mult( gain_code_hi, tmp16 ), sc ); pt_exc2[i] = msu_r( L_tmp, -32768, pt_exc2[i] ); -#endif move16(); /* in Q_exc */ +#endif } /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ @@ -272,12 +271,11 @@ void enhancer_fx( pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); move16(); #endif - move16(); /* in Q_exc */ test(); test(); IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q115*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -334,7 +332,7 @@ void enhancer_fx( void enhancer_ivas_fx( const Word16 codec_mode, /* i : flag indicating Codec Mode */ const Word32 core_brate, /* i : decoder bitrate */ - const int16_t cbk_index, /* i : */ + const Word16 cbk_index, /* i : */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 coder_type, /* i : coder type */ const Word16 i_subfr, /* i : subframe number */ @@ -379,7 +377,7 @@ void enhancer_ivas_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -443,7 +441,7 @@ void enhancer_ivas_fx( /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q14*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -452,13 +450,13 @@ void enhancer_ivas_fx( IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ - L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 /*0.19.Q15*/ ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ - L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -504,9 +502,9 @@ void enhancer_ivas_fx( pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -520,13 +518,13 @@ void enhancer_ivas_fx( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x13333333L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x13333333L /*0.150.Q31*/, voice_fac, 4915 /*0.150.Q15*/ ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ + tmp = mac_r( 0x10000000L /*0.125.Q31*/, voice_fac, 4096 ); /*Q15 */ } /*----------------------------------------------------------------- @@ -566,7 +564,7 @@ void enhancer_ivas_fx( test(); IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q14*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -624,7 +622,7 @@ void enhancer_ivas_fx2( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -642,7 +640,7 @@ void enhancer_ivas_fx2( i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -662,7 +660,7 @@ void enhancer_ivas_fx2( /* tmp = 0.5f * (1.0f - voice_fac) */ #ifdef BASOP_NOGLOB - tmp = msu_r_sat( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ + tmp = msu_r_sat( 0x40000000 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q15*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -671,13 +669,13 @@ void enhancer_ivas_fx2( IF( LT_32( norm_gain_code, *gc_threshold ) ) { - L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 ); /*Q16 */ - L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Madd_32_16( norm_gain_code, norm_gain_code, 6226 /*0.19.Q15*/ ); /*Q16 */ + L_tmp = L_min( L_tmp, *gc_threshold ); /*Q16 */ } ELSE { - L_tmp = Mult_32_16( norm_gain_code, 27536 ); /*Q16 */ - L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ + L_tmp = Mult_32_16( norm_gain_code, 27536 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -723,9 +721,9 @@ void enhancer_ivas_fx2( pit_sharp = shl( gain_pit, 1 ); /* saturation can occur here Q14 -> Q15 */ #endif /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -739,13 +737,13 @@ void enhancer_ivas_fx2( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x13333333L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x13333333L /*0.150.Q31*/, voice_fac, 4915 /*0.150.Q15*/ ); /*Q15 */ } ELSE { /* tmp = 0.125 * (1.0 + voice_fac) */ /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r( 0x10000000L, voice_fac, 4096 ); /*Q15 */ + tmp = mac_r( 0x10000000L /*0.125.Q31*/, voice_fac, 4096 /*0.125.Q15*/ ); /*Q15 */ } /*----------------------------------------------------------------- @@ -801,7 +799,7 @@ void enhancer_ivas_fx2( test(); IF( Opt_AMR_WB && ( EQ_32( core_brate, ACELP_8k85 ) || EQ_32( core_brate, ACELP_6k60 ) ) ) { - IF( GT_16( pit_sharp, 16384 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q15*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -979,7 +977,7 @@ Word16 E_UTIL_enhancer( #endif move16(); - FOR( i = 1; i < sub( L_subfr, 1 ); i++ ) + FOR( i = 1; i < L_subfr - 1; i++ ) { /* exc2[i] = exc2[i] + code[i] - tmp*(code[i+1]+code[i-1]); */ L_tmp = L_mult( code[i], 16384 ); diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 6f541c11f..d47a47191 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -93,7 +93,7 @@ Word16 est_tilt_fx( /* o : tilt of the code /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); /*Q15 */ + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ return tilt_code; } @@ -173,7 +173,7 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code /* find voice factor (1=voiced, -1=unvoiced) */ exp = div_s( abs_s( tmp ), ener1 ); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { exp = negate( exp ); } @@ -185,19 +185,19 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); /*Q15 */ + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ } - ELSE IF( flag_tilt == 1 ) + ELSE IF( EQ_16( flag_tilt, 1 ) ) { /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ // tilt_code = (float)(0.25f + (*voice_fac + 1.0f) * 0.125f); - tilt_code = mac_r( 12288L * 65536 - 0x8000, *voice_fac, 4096 ); /*Q15 */ + tilt_code = mac_r( 12288L /*0.375.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4096 /*0.125.Q15*/ ); /*Q15 */ } ELSE { /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/ // tilt_code = (float)(0.28f + (*voice_fac + 1.0f) * 0.14f); - tilt_code = mac_r( 13763L * 65536 - 0x8000, *voice_fac, 4588 ); /*Q15 */ + tilt_code = mac_r( 13763L /*0.42.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4588 /*0.14.Q15*/ ); /*Q15 */ } return tilt_code; @@ -249,7 +249,7 @@ Word16 Est_tilt2( /* o : tilt of the code /* find voice factor (1=voiced, -1=unvoiced) */ exp = div_s( abs_s( tmp ), ener1 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { exp = negate( exp ); } @@ -259,7 +259,7 @@ Word16 Est_tilt2( /* o : tilt of the code /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L * 65536 - 0x8000, *voice_fac, 8192 ); + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); return tilt_code; } @@ -289,7 +289,7 @@ void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation f IF( shift != 0 ) { - fac = shl( 0x4000, add( 1, shift ) ); + fac = shl( 0x4000 /*1.Q14*/, add( 1, shift ) ); /* energy of pitch excitation */ stmp = mult_r( exc[0 + i_subfr], fac ); /* remove fac bits */ ener_64 = W_mult0_16_16( stmp, stmp ); @@ -377,7 +377,7 @@ void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation f move16(); *tilt_code = add( 8192 /*0.25f Q15*/, mult_r( 8192 /*0.25f Q15*/, *voice_fac ) ); } - ELSE IF( flag_tilt == 1 ) + ELSE IF( EQ_16( flag_tilt, 1 ) ) { /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ move16(); diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index a03edf290..350391c26 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -967,9 +967,10 @@ void SynthesisSTFT_flt( *-------------------------------------------------------------------*/ void SynthesisSTFT_fx( - Word32 *fftBuffer, /* i : FFT bins */ + Word32 *fftBuffer, + /* i : FFT bins */ // Q15 Word32 *timeDomainOutput, - Word32 *olapBuffer, + Word32 *olapBuffer, // Qin const Word16 *olapWin, const Word16 tcx_transition, HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ @@ -988,7 +989,7 @@ void SynthesisSTFT_fx( test(); IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { - Copy32( olapBuffer + sub( i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ), ( M + 1 ) ), buf_fx, add( hFdCngCom->frameSize, M + 1 ) ); + Copy32( olapBuffer + sub( i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ), ( M + 1 ) ), buf_fx, add( hFdCngCom->frameSize, M + 1 ) ); // Qin set32_fx( olapBuffer, 0, hFdCngCom->fftlen ); } ELSE @@ -999,28 +1000,28 @@ void SynthesisSTFT_fx( IF( tcx_transition ) { - FOR( i = 0; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = 0; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = fftBuffer[i]; + olapBuffer[i] = fftBuffer[i]; // Q15 move32(); } } ELSE { - FOR( i = hFdCngCom->frameSize / 4; i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = hFdCngCom->frameSize / 4; i < ( 3 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( hFdCngCom->frameSize >> 2 ) )] ) ); move32(); } - FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); } } - FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( 3 * ( hFdCngCom->frameSize >> 2 ) ) )] ); move32(); } @@ -1054,7 +1055,7 @@ void SynthesisSTFT_fx( { FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[add( i, shr( hFdCngCom->frameSize, 2 ) )] ); + buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[( i + ( hFdCngCom->frameSize >> 2 ) )] ); move32(); } // v_multc(buf, (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); @@ -1072,13 +1073,8 @@ void SynthesisSTFT_fx( preemph_ivas_fx( buf_fx + 1, PREEMPH_FAC, add( M, hFdCngCom->frameSize ), &tmp_fx ); // residu(hFdCngCom->A_cng_flt, M, buf + 1 + M, hFdCngCom->exc_cng_flt, hFdCngCom->frameSize); - // floatToFixed_arr( hFdCngCom->A_cng_flt, hFdCngCom->A_cng, Q13, M + 1 ); // residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); residu_ivas_fx( hFdCngCom->A_cng, ( 15 - norm_s( hFdCngCom->A_cng[0] - 1 ) ), M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); - // for ( i = 0; i < hFdCngCom->frameSize; i++ ) - //{ - // hFdCngCom->exc_cng_flt[i] = fix_to_float( hFdCngCom->exc_cng_32fx[i], Q_in - 9 ); - // } return; } @@ -1152,9 +1148,10 @@ void SynthesisSTFT_dirac_flt( #endif #ifdef IVAS_FLOAT_FIXED void SynthesisSTFT_dirac_fx( - Word32 *fftBuffer, /* i : FFT bins */ + Word32 *fftBuffer, + /* i : FFT bins */ // hFdCngCom->fftBuffer_exp Word32 *timeDomainOutput, - Word32 *olapBuffer, + Word32 *olapBuffer, // Q_in const Word16 *olapWin, const Word16 samples_out, HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ @@ -1170,18 +1167,18 @@ void SynthesisSTFT_dirac_fx( Copy32( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); set32_fx( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/ - FOR( i = shr( hFdCngCom->frameSize, 2 ); i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = ( hFdCngCom->frameSize >> 2 ); i < ( 3 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( hFdCngCom->frameSize >> 2 ) )] ) ); move32(); } - FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); } - FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); @@ -1225,9 +1222,9 @@ void SynthesisSTFT_dirac_fx( { Copy32( olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) ); } - FOR( i = i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[( i - ( 3 * ( hFdCngCom->frameSize >> 2 ) ) )] ); move32(); } diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index e11d67d69..69228a482 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -364,7 +364,7 @@ void initPartitions( * Apply some dynamic range compression based on the log *-------------------------------------------------------------------*/ void compress_range( - Word32 *in, + Word32 *in, // Q(31 - in_exp) Word16 in_exp, Word16 *out, const Word16 len ) @@ -379,11 +379,11 @@ void compress_range( /* out = log2( 1 + in ) */ IF( in_exp >= 0 ) { - one_s = L_shr( 1073741824l /*0.5 Q31*/, in_exp ); + one_s = L_shr( 1073741824l /*0.5 Q31*/, in_exp ); // Q(31 - in_exp) in_exp32 = L_shl( L_deposit_l( add( in_exp, 1 ) ), WORD32_BITS - 1 - LD_DATA_SCALE ); FOR( i = 0; i < len; i++ ) { - in_s = L_add( L_shr( in[i], 1 ), one_s ); + in_s = L_add( L_shr( in[i], 1 ), one_s ); // Q(31 - in_exp) L_tmp = L_add( BASOP_Util_Log2( in_s ), in_exp32 ); if ( in_s == 0 ) { @@ -434,8 +434,8 @@ void compress_range( * Apply some dynamic range expansion to undo the compression *-------------------------------------------------------------------*/ void expand_range( - Word16 *in, - Word32 *out, + Word16 *in, // Q15 + Word32 *out, // Q(31 - out_exp) Word16 *out_exp, const Word16 len ) { @@ -451,7 +451,7 @@ void expand_range( move16(); FOR( i = 0; i < len; i++ ) { - maxVal = s_max( maxVal, in[i] ); + maxVal = s_max( maxVal, in[i] ); // Q15 } maxVal2 = maxVal; @@ -460,12 +460,12 @@ void expand_range( move16(); WHILE( maxVal >= 0 ) { - maxVal = sub( maxVal, 512 /*0.015625 Q15*/ ); + maxVal = sub( maxVal, 512 /*0.015625 Q15*/ ); // Q15 s = add( s, 1 ); } tmp = sub( maxVal2, maxVal ); - one_s = L_shr( 1073741824l /*0.5 Q31*/, sub( s, 1 ) ); + one_s = L_shr( 1073741824l /*0.5 Q31*/, sub( s, 1 ) ); // Q(31 - sub( s, 1 )) tmp32 = L_shr( 726941l /*0.0003385080526823181 Q31*/, s ); /* out = (2^(in) - 1) */ FOR( i = 0; i < len; i++ ) @@ -1766,7 +1766,7 @@ void minimum_statistics_fx( move16(); } } - if ( enc_dec == DEC && element_mode == IVAS_CPE_TD ) + IF( EQ_16( enc_dec, DEC ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { // v_multc(msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING); v_multc_att( msNoiseEst, 23142, msNoiseEst, NPART_SHAPING ); @@ -1812,7 +1812,7 @@ void apply_scale( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table */ + const SCALE_SETUP *scaleTable, /* i : Scale table Q7 */ const Word16 scaleTableSize /* i : Size of scale table */ ) { @@ -1874,7 +1874,7 @@ void apply_scale_ivas_fx( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table */ + const SCALE_SETUP *scaleTable, /* i : Scale table Q7 */ const Word16 scaleTableSize, /* i : Size of scale table */ Word16 *index ) { @@ -1922,7 +1922,7 @@ void bandcombinepow( IF( EQ_16( nband, npart ) ) { - Copy32( bandpow, partpow, nband ); + Copy32( bandpow, partpow, nband ); // Q(31 - exp_bandpow) smin = 0; move16(); } @@ -1973,13 +1973,13 @@ void bandcombinepow( * Scale partitions (with smoothing) *-------------------------------------------------------------------*/ void scalebands( - const Word32 *partpow, /* i : Power for each partition */ + const Word32 *partpow, /* i : Power for each partition Qx*/ Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ const Word16 npart, /* i : Number of partitions */ Word16 *midband, /* i : Central band of each partition */ const Word16 nFFTpart, /* i : Number of FFT partitions */ const Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ + Word32 *bandpow, /* o : Power for each band Qx*/ const Word16 flag_fft_en ) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; @@ -2008,7 +2008,7 @@ void scalebands( stopPart = nFFTpart; move16(); - WHILE( LT_16( startBand, nband ) ) + WHILE( startBand < nband ) { stopPartM1 = sub( stopPart, 1 ); test(); @@ -2026,15 +2026,15 @@ void scalebands( j = add( j, 1 ); /* inner partitions */ - IF( j < stopPart ) + IF( LT_16( j, stopPart ) ) { partpowLD64M1 = BASOP_Util_Log2( partpow[j - 1] ); } /* Debug values to check this variable is set. */ - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); - delta_cmp = 0x4000; + delta_cmp = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); @@ -2057,7 +2057,7 @@ void scalebands( WHILE( tmp > 0 ) { - tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); + tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); // Q31 delta_s = add( delta_s, 1 ); } delta_cmp = shl( 1, s_max( -15, sub( WORD16_BITS - 1, delta_s ) ) ); @@ -2067,7 +2067,7 @@ void scalebands( s1 = sub( delta_s, s ); #ifdef BASOP_NOGLOB - delta = round_fx_sat( L_shl_sat( tmp, s ) ); + delta = round_fx_sat( L_shl_sat( tmp, s ) ); // Q(14+s) #else delta = round_fx( L_shl( tmp, s ) ); #endif @@ -2088,19 +2088,19 @@ void scalebands( IF( GT_16( shr( delta, s ), delta_cmp ) ) { - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); } /* last half partition */ - val = partpow[stopPartM1]; + val = partpow[stopPartM1]; // Qx move32(); FOR( ; i <= part[stopPartM1]; i++ ) { val = L_shl( Mpy_32_16_1( val, delta ), s1 ); - bandpow[i] = val; + bandpow[i] = val; // Qx move32(); } } @@ -2115,13 +2115,13 @@ void scalebands( #ifdef IVAS_FLOAT_FIXED void scalebands_fx( - const Word32 *partpow, /* i : Power for each partition */ + const Word32 *partpow, /* i : Power for each partition Qx*/ Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ const Word16 npart, /* i : Number of partitions */ Word16 *midband, /* i : Central band of each partition */ const Word16 nFFTpart, /* i : Number of FFT partitions */ const Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ + Word32 *bandpow, /* o : Power for each band Qx*/ const Word16 flag_fft_en ) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; @@ -2162,7 +2162,7 @@ void scalebands_fx( FOR( i = startBand; i <= midband[j]; i++ ) { - bandpow[i] = partpow[j]; + bandpow[i] = partpow[j]; // Qx move32(); } j = add( j, 1 ); @@ -2174,9 +2174,9 @@ void scalebands_fx( } /* Debug values to check this variable is set. */ - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); - delta_cmp = 0x4000; + delta_cmp = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); @@ -2206,7 +2206,7 @@ void scalebands_fx( WHILE( tmp > 0 ) { - tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); + tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); // Q31 delta_s = add( delta_s, 1 ); } delta_cmp = shl( 1, s_max( -15, sub( WORD16_BITS - 1, delta_s ) ) ); @@ -2216,7 +2216,7 @@ void scalebands_fx( s1 = sub( delta_s, s ); #ifdef BASOP_NOGLOB - delta = round_fx_sat( L_shl_sat( tmp, s ) ); + delta = round_fx_sat( L_shl_sat( tmp, s ) ); // Q(14+s) #else delta = round_fx( L_shl( tmp, s ) ); #endif @@ -2229,7 +2229,7 @@ void scalebands_fx( bandpow[i] = L_shr( val, delta_s ); move32(); } - bandpow[i++] = partpow[j]; + bandpow[i++] = partpow[j]; // Qx move32(); partpowLD64M1 = partpowLD64; move32(); @@ -2237,14 +2237,14 @@ void scalebands_fx( IF( GT_16( shr( delta, s ), delta_cmp ) ) { - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); } /* last half partition */ - val = partpow[stopPartM1]; + val = partpow[stopPartM1]; // Qx move32(); FOR( ; i <= part[stopPartM1]; i++ ) { @@ -2263,7 +2263,7 @@ void scalebands_fx( val = 0; move32(); } - bandpow[i] = val; + bandpow[i] = val; // Qx move32(); } } @@ -2331,8 +2331,8 @@ static void getmidbands( FOR( j = 0; j < npart; j++ ) { #ifdef BASOP_NOGLOB - psize_norm[j] = shl_o( psize[j], shift, &Overflow ); -#else /* BASOP_NOGLOB */ + psize_norm[j] = shl_o( psize[j], shift, &Overflow ); // Q(15 - psize_norm_exp) +#else /* BASOP_NOGLOB */ psize_norm[j] = shl( psize[j], shift ); #endif move16(); @@ -2348,7 +2348,7 @@ static void getmidbands( *-------------------------------------------------------------------*/ void AnalysisSTFT( - const Word16 *timeDomainInput, /* i : pointer to time signal */ + const Word16 *timeDomainInput, /* i : pointer to time signal Q(Q)*/ Word16 Q, Word32 *fftBuffer, /* o : FFT bins */ Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ @@ -2418,7 +2418,7 @@ void AnalysisSTFT( * STFT analysis filterbank *-------------------------------------------------------------------*/ void AnalysisSTFT_fx( - const Word16 *timeDomainInput, + const Word16 *timeDomainInput, // Q(Q) Word16 Q, Word32 *fftBuffer, /* o : FFT bins */ Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ @@ -2528,7 +2528,7 @@ void SynthesisSTFT_enc_ivas_fx( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2543,7 +2543,7 @@ void SynthesisSTFT_enc_ivas_fx( } FOR( i = len3; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2620,7 +2620,7 @@ void SynthesisSTFT_enc_ivas_fx( void SynthesisSTFT( Word32 *fftBuffer, /* i : pointer to FFT bins */ Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal Qx*/ Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ const PWord16 *olapWin, /* i : pointer to overlap window */ Word16 tcx_transition, @@ -2666,7 +2666,7 @@ void SynthesisSTFT( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2744,7 +2744,7 @@ void SynthesisSTFT( void SynthesisSTFT_ivas_fx( Word32 *fftBuffer, /* i : pointer to FFT bins */ Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal Qx*/ Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ const PWord16 *olapWin, /* i : pointer to overlap window */ Word16 tcx_transition, @@ -2772,6 +2772,8 @@ void SynthesisSTFT_ivas_fx( /* Perform overlap-add */ /* Handle overlap in P/S domain for stereo */ + test(); + test(); IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { Copy( olapBuffer + 3 * hFdCngCom->frameSize / 4 - ( M + 1 ), buf, hFdCngCom->frameSize + M + 1 ); @@ -2790,7 +2792,7 @@ void SynthesisSTFT_ivas_fx( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); // Q(15 - fftBufferExp) move16(); } } @@ -3290,12 +3292,12 @@ void FdCng_exc( Word16 *lsp_old, Word16 first_CNG, Word16 *lspCNG, - Word16 *Aq, /* o: LPC coeffs */ - Word16 *lsp_new, /* o: lsp */ - Word16 *lsf_new, /* o: lsf */ - Word16 *exc, /* o: LP excitation */ - Word16 *exc2, /* o: LP excitation */ - Word16 *bwe_exc /* o: LP excitation for BWE */ + Word16 *Aq, /* o: LPC coeffs Q12*/ + Word16 *lsp_new, /* o: lsp Q15 */ + Word16 *lsf_new, /* o: lsf Qlog2(2.56) */ + Word16 *exc, /* o: LP excitation Q12 */ + Word16 *exc2, /* o: LP excitation Q12 */ + Word16 *bwe_exc /* o: LP excitation for BWE Q12*/ ) { Word16 i; diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 3123d4475..fea7eca61 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -299,17 +299,17 @@ void sns_compute_scf_fx( Word16 q ); void sns_interpolate_scalefactors_fx( - Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping */ - const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */ - Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ + Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping q16*/ + const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream Q16*/ + Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ ); void sns_shape_spectrum_fx( - Word32 spectrum[], /* i/o: spectrum to be shaped */ + Word32 spectrum[], /* i/o: spectrum to be shaped Input Q is q_spectrum and ouput Q is (q_spectrum-1)*/ Word16 *q_spectrum, /* i/o: Q of spectrum */ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ - const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ + const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors q_scf_int*/ const Word16 L_frame, /* i : frame length */ Word16 *length ); @@ -323,10 +323,10 @@ void stereo_tca_enc_fx( ); void ECSQ_dequantize_vector_fx( - const Word16 *input, - const Word32 global_gain, + const Word16 *input, /*qx*/ + const Word32 global_gain, /*q15*/ const Word16 N, - Word32 *output ); + Word32 *output /*qx*/ ); void ECSQ_init_instance_fx( ECSQ_instance *ecsq_inst, @@ -682,12 +682,12 @@ Word16 masa_sq_fx( ); void ivas_compute_spar_params_enc_fx( - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -698,18 +698,18 @@ void ivas_compute_spar_params_enc_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale, + Word32 *pWscale, /*q_Wscale*/ Word16 *q_Wscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ); void ivas_compute_spar_params_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -720,7 +720,7 @@ void ivas_compute_spar_params_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale_fx, + Word32 *pWscale_fx, /*q_pWscale*/ Word16 *q_pWscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ); @@ -1681,7 +1681,7 @@ void ivas_fine_gain_pred_fx( const Word16 *R, /* i : Bits per sub band Q3 */ const Word16 num_sfm, /* i : Number of sub bands */ Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *y, /* i/o: Quantized vector (int) Q0*/ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 core /* i : Core */ ); @@ -2006,10 +2006,10 @@ Word16 set_ACELP_flag_IVAS( void ivas_calc_c_p_coeffs_enc_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -2020,10 +2020,10 @@ void ivas_calc_c_p_coeffs_enc_fx( void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -4951,7 +4951,7 @@ void computeDiffuseness_fixed( void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, - Word32 *response, + Word32 *response_fx, /*Q_out*/ const Word16 ambisonics_order, Word16 Q_out ); @@ -5308,11 +5308,11 @@ ivas_error ivas_spar_md_enc_open_fx( ); void ivas_create_fullr_dmx_mat_fx( - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 q_dm_fv_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 in_chans, const Word16 start_band, @@ -5325,7 +5325,7 @@ void ivas_get_spar_md_from_dirac_fx( Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 const Word16 n_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ Word16 *q_mixer_mat_fx, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 3aebb59f5..424a95b5a 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -176,9 +176,11 @@ void ivas_sba_config_fx( *nSCE = 0; move16(); *nCPE = shr( *nchan_transport, 1 ); + move16(); IF( NE_16( i_mult( 2, ( *nCPE ) ), *nchan_transport ) ) { *nCPE = add( *nCPE, 1 ); + move16(); } *element_mode = IVAS_CPE_MDCT; move16(); @@ -302,7 +304,7 @@ Word16 ivas_sba_get_analysis_order_fx( sba_analysis_order = sba_order; move16(); - IF( LT_32( ivas_total_brate, SBA_MIN_BRATE_HOA ) ) + if ( LT_32( ivas_total_brate, SBA_MIN_BRATE_HOA ) ) { /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */ sba_analysis_order = SBA_FOA_ORDER; @@ -321,6 +323,7 @@ Word16 ivas_sba_get_analysis_order_fx( *-------------------------------------------------------------------*/ /*! r: number of Ambisonic channels */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_sba_get_nchan( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int16_t sba_planar /* i : SBA planar flag */ @@ -339,7 +342,7 @@ int16_t ivas_sba_get_nchan( return ( nb_channels ); } -#ifdef IVAS_FLOAT_FIXED +#else Word16 ivas_sba_get_nchan_fx( const Word16 sba_order, /* i : Ambisonic (SBA) order */ const Word16 sba_planar /* i : SBA planar flag */ @@ -398,7 +401,7 @@ Word16 ivas_sba_get_nchan_metadata_fx( return ( nb_channels ); } -#endif +#else int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ @@ -426,7 +429,7 @@ int16_t ivas_sba_get_nchan_metadata( return ( nb_channels ); } - +#endif /*-------------------------------------------------------------------* * ivas_sba_get_spar_hoa_ch_ind() @@ -565,7 +568,7 @@ void ivas_sba_get_spar_hoa_md_flag_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_sba_zero_vert_comp_fx( - Word32 *sba_data[], /* i : SBA signals */ + Word32 *sba_data[], /* i : SBA signals q_data */ const Word16 sba_order, /* i : SBA order */ const Word16 sba_planar, /* i : SBA planar flag */ const Word16 input_frame /* i : frame length */ diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index ff8fcd8aa..9a7a092b3 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -50,11 +50,11 @@ *-------------------------------------------------------------------*/ void sns_compute_scf_fx( - Word32 spectrum[], /* i : Spectrum (Q_in) */ + Word32 spectrum[], /* i : Spectrum Q_in */ const PsychoacousticParameters *pPsychParams, const Word16 L_frame, Word32 *scf, /* o : Scalefactors (Q16)*/ - Word16 q ) + Word16 Q_in ) { Word16 i, n, k; Word32 x[FDNS_NPTS], xs[FDNS_NPTS], mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS]; @@ -75,11 +75,11 @@ void sns_compute_scf_fx( move16(); const Word16 w_2 = 8192; // 0.25f ( 3.0f / 12.0f ) in Q15 move16(); - const Word16 w_3 = w_2; + const Word16 w_3 = w_2; // q15 move16(); - const Word16 w_4 = w_1; + const Word16 w_4 = w_1; // q15 move16(); - const Word16 w_5 = w_0; + const Word16 w_5 = w_0; // q15 move16(); assert( nBands == FDNS_NPTS ); @@ -138,7 +138,7 @@ void sns_compute_scf_fx( Word16 inv_bw; bw = (Word8) shr( L_frame, 6 ); move16(); - inv_bw = div_l( ONE_IN_Q16, bw ); // Q15 + inv_bw = div_l( ONE_IN_Q16 /*1 Q16*/, bw ); // Q15 FOR( i = 0; i < nBands; ++i ) { x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) @@ -149,8 +149,8 @@ void sns_compute_scf_fx( { FOR( i = 0; i < nBands; ++i ) { - Word16 inv_bw = div_l( ONE_IN_Q16, bandLengths[i] ); // Q15 - x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) + Word16 inv_bw = div_l( ONE_IN_Q16 /*1 Q16*/, bandLengths[i] ); // Q15 + x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) move32(); } } @@ -196,7 +196,7 @@ void sns_compute_scf_fx( move64(); FOR( Word16 ind = 0; ind < FDNS_NPTS; ind++ ) { - sum = W_add( sum, (Word64) xs[ind] ); // Q_in + (q_shift - 32) + sum = W_add( sum, W_deposit32_l( xs[ind] ) ); // Q_in + (q_shift - 32) } mean = W_extract_l( W_shr( sum, 6 ) ); // Q_in + (q_shift - 32) @@ -216,8 +216,8 @@ void sns_compute_scf_fx( FOR( i = 0; i < FDNS_NPTS; i++ ) { Word16 e_tmp = norm_l( xs[i] ); - Word16 f_tmp = Log2_norm_lc( L_shl( xs[i], e_tmp ) ); - e_tmp = sub( sub( 34, e_tmp ), q ); + Word16 f_tmp = Log2_norm_lc( L_shl( xs[i], e_tmp ) ); /*Q16*/ + e_tmp = sub( sub( 34, e_tmp ), Q_in ); /* Note: Mpy_32_16 is used temporarily for this computation, It needs to be replaced with appropriate BASOP. */ xl[i] = Mpy_32_16( e_tmp, f_tmp, 16384 ); /* Q16 */ move32(); @@ -264,7 +264,7 @@ void sns_compute_scf_fx( move64(); FOR( Word16 ind = 0; ind < SNS_NPTS; ind++ ) { - sum = W_add( sum, (Word64) xl4[ind] ); // Q16 + sum = W_add( sum, W_deposit32_l( xl4[ind] ) ); // Q16 } mean = W_extract_l( W_shr( sum, 4 ) ); // Q16 @@ -284,8 +284,8 @@ void sns_compute_scf_fx( *-------------------------------------------------------------------*/ void sns_interpolate_scalefactors_fx( - Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping*/ - const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */ + Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping q16*/ + const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream Q16*/ Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ ) { @@ -294,34 +294,34 @@ void sns_interpolate_scalefactors_fx( Word16 exp; /* Interpolation */ - scf_int[0] = scf[0]; - scf_int[1] = scf[0]; + scf_int[0] = scf[0]; // q16 + scf_int[1] = scf[0]; // q16 move32(); move32(); FOR( n = 0; n <= M - 2; n++ ) { - scf_int[add( n * 4, 2 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 4096 ); /* 4096 -> 1/8 in Q15 */ - scf_int[add( n * 4, 3 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 12288 ); /* 12288 -> 3/8 in Q15 */ - scf_int[add( n * 4, 4 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 20480 ); /* 20480 -> 5/8 in Q15 */ - scf_int[add( n * 4, 5 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 28672 ); /* 28672 -> 7/8 in Q15 */ + scf_int[n * 4 + 2] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 4096 /* 4096 -> 1/8 in Q15 */ ); // q16 + scf_int[n * 4 + 3] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 12288 /* 12288 -> 3/8 in Q15 */ ); // q16 + scf_int[n * 4 + 4] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 20480 /* 20480 -> 5/8 in Q15 */ ); // q16 + scf_int[n * 4 + 5] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 28672 /* 28672 -> 7/8 in Q15 */ ); // q16 move32(); move32(); move32(); move32(); } - scf_int[FDNS_NPTS - 2] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 4096 ); - scf_int[FDNS_NPTS - 1] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 12288 ); + scf_int[FDNS_NPTS - 2] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 4096 /* 4096 -> 1/8 in Q15 */ ); // q16 + scf_int[FDNS_NPTS - 1] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 12288 /* 12288 -> 3/8 in Q15 */ ); // q16 move32(); move32(); /* Inversion at encoder-side */ - IF( encoder_side == ENC ) + IF( encoder_side == ENC /*0*/ ) { FOR( n = 0; n < FDNS_NPTS; n++ ) { - scf_int[n] = L_negate( scf_int[n] ); + scf_int[n] = L_negate( scf_int[n] ); // q16 move32(); } } @@ -329,9 +329,9 @@ void sns_interpolate_scalefactors_fx( /* Linear domain */ FOR( n = 0; n < FDNS_NPTS; n++ ) { - L_tmp = BASOP_util_Pow2( scf_int[n], Q15, &exp ); + L_tmp = BASOP_util_Pow2( scf_int[n], 15 /*31-Q16*/, &exp ); // Q=31-exp exp = sub( 15, exp ); - scf_int[n] = L_shr( L_tmp, exp ); + scf_int[n] = L_shr( L_tmp, exp ); // q16 move32(); } @@ -346,11 +346,11 @@ void sns_interpolate_scalefactors_fx( *-------------------------------------------------------------------*/ void sns_shape_spectrum_fx( - Word32 spectrum[], /* i/o: spectrum to be shaped */ + Word32 spectrum[], /* i/o: spectrum to be shaped Input Q is q_spectrum and ouput Q is (q_spectrum-1)*/ Word16 *q_spectrum, /* i/o: Q of spectrum */ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ - const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ + const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors q_scf_int*/ const Word16 L_frame, /* i : frame length */ Word16 *length ) { @@ -364,7 +364,7 @@ void sns_shape_spectrum_fx( IF( bandLengths == NULL ) { - bw = divide3216( shl( L_frame, 1 ), nBands ); + bw = divide3216( shl( L_frame, 1 ), nBands ); // q0 /* Shape spectrum */ k = 0; @@ -376,7 +376,7 @@ void sns_shape_spectrum_fx( L64_tmp[k] = W_mult_32_32( spectrum[k], scf_int[i] ); // Q = q_spectrum + q_scf_int + 1 move64(); shift = W_norm( L64_tmp[k] ); - IF( LT_16( shift, min_shift ) ) + if ( LT_16( shift, min_shift ) ) { min_shift = shift; move16(); @@ -398,9 +398,9 @@ void sns_shape_spectrum_fx( } FOR( k = 0; k < tmp_k; k++ ) { - L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); + L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); // Q = q_tmp+1 move64(); - spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp + spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp+1 move64(); } *q_spectrum = q_tmp; @@ -418,7 +418,8 @@ void sns_shape_spectrum_fx( L64_tmp[k] = W_mult_32_32( spectrum[k], scf_int[i] ); // Q = q_spectrum + q_scf_int + 1 move64(); shift = W_norm( L64_tmp[k] ); - IF( LT_16( shift, min_shift ) && NE_64( L64_tmp[k], 0 ) ) + test(); + if ( LT_16( shift, min_shift ) && NE_64( L64_tmp[k], 0 ) ) { min_shift = shift; move16(); @@ -440,9 +441,9 @@ void sns_shape_spectrum_fx( } FOR( k = 0; k < tmp_k; k++ ) { - L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); + L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); // q_tmp+1 move64(); - spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp + spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp+1 move64(); } *q_spectrum = q_tmp; diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index f70a74d6e..74d3c01d3 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -64,18 +64,18 @@ #define IVAS_REMIX_MULT_FAC ( 0.5f ) #define IVAS_ACTIVEW_DM_F ( 1.0f ) -#define IVAS_ACTIVEW_DM_F_Q30 ( ONE_IN_Q30 ) +#define IVAS_ACTIVEW_DM_F_Q30 ( ONE_IN_Q30 ) /*1 Q30*/ #define IVAS_ACTIVEW_DM_F_DTX ( 0.25f ) -#define IVAS_ACTIVEW_DM_F_DTX_Q30 ( 268435456 ) +#define IVAS_ACTIVEW_DM_F_DTX_Q30 ( 268435456 ) /*0.25 Q30*/ #define IVAS_ACTIVEW_DM_F_VLBR ( 0.25f ) -#define IVAS_ACTIVEW_DM_F_VLBR_Q30 ( 268435456 ) +#define IVAS_ACTIVEW_DM_F_VLBR_Q30 ( 268435456 ) /*0.25 Q30*/ #define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH ( 3.0f ) -#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) +#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) /*3 Q29*/ #define IVAS_P_NORM_SCALING ( 1.0f ) -#define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // Q31 +#define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // 1 Q31 #define IVAS_P_NORM_SCALING_DTX ( 0.75f ) -#define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // Q31 +#define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // 0.75 Q31 #define IVAS_MAT_DIM_3 ( 3 ) #define IVAS_MAT_DIM_2 ( 2 ) @@ -88,11 +88,11 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_get_pred_coeffs_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ Word16 *q_pred_coeffs, - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, @@ -105,11 +105,11 @@ static void ivas_get_pred_coeffs_enc_fx( const Word16 res_ind ); static void ivas_get_Wscaling_factor_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -119,24 +119,24 @@ static void ivas_get_Wscaling_factor_enc_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ); static void ivas_calc_post_pred_per_band_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ); static void ivas_get_pred_coeffs_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q30*/ + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -148,11 +148,11 @@ static void ivas_get_pred_coeffs_fx( const Word16 res_ind, Word16 *q_pred_coeffs, Word16 *q_dm_fv_re ); -static void ivas_reorder_array_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat, const Word16 start_band, const Word16 end_band ); -static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], Word16 q_pred_coeffs_re, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, const Word16 num_ch, const Word16 *pNum_dmx, const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, Word32 *pWscale, Word16 *q_pWscale, const Word16 dyn_active_w_flag ); -static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_postpred_cov_re ); -static Word16 ivas_is_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim ); -static void ivas_calc_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 *q_out_re ); +static void ivas_reorder_array_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /*qx*/, const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat /*qx*/, const Word16 start_band, const Word16 end_band ); +static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] /*q_cov_real*/, Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS] /*q_pred_coeffs_re*/, Word16 q_pred_coeffs_re, Word32 ***mixer_mat /*q_mixer_mat*/, Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, const Word16 num_ch, const Word16 *pNum_dmx, const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, Word32 *pWscale /*q_pWscale*/, Word16 *q_pWscale, const Word16 dyn_active_w_flag ); +static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] /*q_cov_real*/, Word16 q_cov_real, Word32 ***mixer_mat /*q_mixer_mat*/, Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] /*q_postpred_cov_re*/, Word16 *q_postpred_cov_re ); +static Word16 ivas_is_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_in_re*/, Word16 q_in_re, const Word16 dim ); +static void ivas_calc_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_in_re*/, Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_out_re*/, Word16 *q_out_re ); #endif /*-----------------------------------------------------------------------------------------* @@ -323,13 +323,13 @@ void ivas_spar_config_fx( move16(); } - *nSCE = max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); + *nSCE = s_max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); move16(); IF( EQ_16( *nchan_transport, 1 ) ) { /* map SPAR SID bitrate to SPAR active bitrate */ - IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + if ( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { ivas_total_brate = IVAS_32k; move32(); @@ -439,7 +439,7 @@ Word16 ivas_get_spar_table_idx_fx( ( EQ_16( ivas_spar_br_table_consts[i].sba_order, sba_order ) ) ) { ind1[j] = i; - j = add( j, 1 ); + j++; move16(); } } @@ -459,7 +459,7 @@ Word16 ivas_get_spar_table_idx_fx( table_idx = ind1[ind2]; move16(); - IF( ind != NULL ) + if ( ind != NULL ) { *ind = ind2; move16(); @@ -525,11 +525,11 @@ Word16 ivas_get_sba_num_TCs_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_get_pred_coeffs_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ Word16 *q_pred_coeffs, - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, @@ -573,7 +573,7 @@ static void ivas_get_pred_coeffs_enc_fx( set16_fx( q_pPred_temp, 31, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( 1, cov_real[0][0][k] ), &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 in q31*/, L_max( 1, cov_real[0][0][k] ), &s_div ); /*Q=15-(s_div-(31-q_cov_real))*/ move16(); div_factor_e[k] = sub( add( s_div, q_cov_real[0][0][k] ), 31 ); @@ -584,7 +584,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); /*q_cov_real+15-div_factor_e[k]+1*/ tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { @@ -607,11 +607,11 @@ static void ivas_get_pred_coeffs_enc_fx( IF( GE_16( q_tmp, q_pPred_temp[k] ) ) { - abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); + abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); // q_tmp -> q_pPred_temp[k] } ELSE { - pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); + pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); // q_pPred_temp[k]->q_tmp move64(); q_pPred_temp[k] = q_tmp; move16(); @@ -626,13 +626,13 @@ static void ivas_get_pred_coeffs_enc_fx( { tmp_shift = W_norm( pPred_temp[k] ); e_tmp = sub( 31, sub( add( q_pPred_temp[k], tmp_shift ), 32 ) ); - L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); + L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp - one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); + one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); // 1 in Q(31-e_tmp) IF( LT_32( one_in_q, L_tmp ) ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); // Q=15-s_div move16(); div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 move16(); @@ -641,7 +641,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - div_factor[k] = ONE_IN_Q15 - 1; + div_factor[k] = ONE_IN_Q15 - 1; /*1 in Q15*/ move16(); div_factor_e[k] = 0; move16(); @@ -654,7 +654,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 ) ) + IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 /*1 in Q15*/ ) ) { ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] move32(); @@ -672,7 +672,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); + ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); // Q=tmp_shift move32(); } } @@ -702,12 +702,12 @@ static void ivas_get_pred_coeffs_enc_fx( IF( EQ_16( dyn_active_w_flag, 1 ) ) { - activew_quad_thresh = ONE_IN_Q29; + activew_quad_thresh = ONE_IN_Q29; /*1 in Q29*/ move32(); } ELSE { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; /*3.0f Q29*/ move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -734,7 +734,7 @@ static void ivas_get_pred_coeffs_enc_fx( } IF( LT_16( q_tmp, dm_alpha64_q[k] ) ) { - dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); + dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); // Q=q_tmp move64(); dm_alpha64_q[k] = q_tmp; move16(); @@ -744,7 +744,7 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_alpha64_q[k] ); IF( LT_16( tmp_shift, 63 ) ) { - dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); + dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); // Q=dm_alpha64_q[k] move64(); } } @@ -763,12 +763,12 @@ static void ivas_get_pred_coeffs_enc_fx( e_tmp = 0; move16(); } - dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); + dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp move32(); dm_alpha64_q[k] = sub( 31, e_tmp ); move16(); - div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( dm_alpha[k], 1 ), &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 Q31*/, L_max( dm_alpha[k], 1 ), &s_div ); // Q=15-(dm_alpha64_q[k]+ s_div-31) move16(); div_factor_e[k] = sub( add( dm_alpha64_q[k], s_div ), 31 ); @@ -779,7 +779,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); // Q=(15-div_factor_e[k]+q_cov_real[i+1][0][k])+1 tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { @@ -800,19 +800,19 @@ static void ivas_get_pred_coeffs_enc_fx( IF( dtx_vad == 0 ) { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; // q30 move32(); } ELSE { IF( active_w_vlbr ) { - dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; // q30 move32(); } ELSE { - dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; // q30 move32(); } } @@ -827,7 +827,7 @@ static void ivas_get_pred_coeffs_enc_fx( FOR( k = 1; k < in_chans; k++ ) { // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); + re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); // Q=q_cov_real[j+1][k][b]+dm_v_re_q[k-1][b] tmp_shift = W_norm( re ); IF( re != 0 ) { @@ -841,7 +841,7 @@ static void ivas_get_pred_coeffs_enc_fx( IF( LT_16( q_tmp, real64_q[j] ) ) { - real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); // Q=q_tmp move64(); real64_q[j] = q_tmp; move16(); @@ -851,7 +851,7 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), real64_q[j] ); IF( LT_16( tmp_shift, 63 ) ) { - real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); + real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); // Q=real64_q[j] move64(); } } @@ -866,7 +866,7 @@ static void ivas_get_pred_coeffs_enc_fx( { // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); tmp_shift = W_norm( real64[k] ); - re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); + re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); // Q=(real64[k]+tmp_shift-32)+dm_v_re_q q_tmp = sub( add( add( real64_q[k], dm_v_re_q[k][b] ), tmp_shift ), 32 ); tmp_shift = W_norm( re ); IF( re != 0 ) @@ -881,7 +881,7 @@ static void ivas_get_pred_coeffs_enc_fx( IF( LT_16( q_tmp, dm_beta_re_q ) ) { - tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); // Q=q_tmp dm_beta_re_q = q_tmp; move16(); } @@ -890,12 +890,12 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_beta_re_q ); IF( LT_16( tmp_shift, 63 ) ) { - tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); + tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); // Q=dm_beta_re_q } } } tmp_shift = W_norm( tmp64 ); - dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); + dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); // Q=dm_beta_re_q+tmp_shift-32 IF( tmp64 != 0 ) { dm_beta_re_q = sub( add( dm_beta_re_q, tmp_shift ), 32 ); @@ -908,7 +908,7 @@ static void ivas_get_pred_coeffs_enc_fx( dm_w = cov_real[0][0][b]; // q_cov_real[0][0][b] move32(); - den_f = L_max( dm_w, 1 ); + den_f = L_max( dm_w, 1 ); // q_cov_real[0][0][b] passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha64_q[b] - q_cov_real[0][0][b] + 15 - s_div div_shift = sub( Q29, add( sub( dm_alpha64_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); @@ -929,16 +929,16 @@ static void ivas_get_pred_coeffs_enc_fx( dm_v_re_q[i][b] = 31; move16(); } - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; /*1 Q31*/ move32(); dm_v_re_q[i][b] = 31; move16(); - passive_g = activew_quad_thresh; + passive_g = activew_quad_thresh; // q29 move32(); } - IF( LT_32( passive_g, activew_quad_thresh ) ) + IF( LT_32( passive_g, activew_quad_thresh ) ) // q29 { /*linear activeW*/ dm_y = 0; @@ -950,30 +950,30 @@ static void ivas_get_pred_coeffs_enc_fx( { IF( GT_16( q_tmp, q_cov_real[k][k][b] ) ) { - dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); + dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); // q_cov_real[k][k][b] q_tmp = q_cov_real[k][k][b]; move16(); } ELSE { - dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); + dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); // q_tmp } } - tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); + tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); // Q=q_tmp IF( LT_16( q_tmp, q_cov_real[0][0][b] ) ) { - tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); + tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); // Q=q_tmp } ELSE { q_tmp = q_cov_real[0][0][b]; move16(); - dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); + dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); // Q=q_cov_real[0][0][b] } if ( GT_64( tmp64, dm_y ) ) { - dm_y = tmp64; + dm_y = tmp64; // Q=q_tmp move16(); } @@ -989,7 +989,7 @@ static void ivas_get_pred_coeffs_enc_fx( den_f = W_extract_h( W_shl( dm_y, tmp_shift ) ); // q_tmp + tmp_shift - 32 } - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // q_tmp + tmp_shift - 32 DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha64_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div move32(); @@ -997,15 +997,15 @@ static void ivas_get_pred_coeffs_enc_fx( DM_F_q[b] = add( sub( sub( dm_alpha64_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); move16(); - IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) + IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) // q30 { - DM_F[b] = ONE_IN_Q31; + DM_F[b] = ONE_IN_Q31; /*1 Q31*/ move32(); DM_F_q[b] = Q31; move16(); } - tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); + tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); /*Q=(2*DM_F_q[b])*/ tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1014,7 +1014,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); /*Q=(2*DM_F_q[b]+tmp_shift)*/ } tmp64 = W_mult0_32_32( W_extract_h( tmp64 ), dm_beta_re ); // 2 * DM_F_q[b] + tmp_shift - 32 + dm_beta_re_q q_tmp = sub( add( add( shl( DM_F_q[b], 1 ), tmp_shift ), dm_beta_re_q ), 32 ); @@ -1026,12 +1026,12 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=q_tmp+tmp_shift } - L_tmp2 = W_extract_h( tmp64 ); + L_tmp2 = W_extract_h( tmp64 ); // Q=q_tmp+tmp_shift-32 L_tmp2_q = sub( add( q_tmp, tmp_shift ), 32 ); - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); // Q=dm_alpha64_q[b]+DM_F_q[b] tmp_shift = sub( W_norm( tmp64 ), 2 ); IF( tmp64 == 0 ) { @@ -1040,40 +1040,40 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q[b]+DM_F_q[b]+tmp_shift } L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); IF( LT_16( L_tmp2_q, L_tmp1_q ) ) { - L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q L_tmp1_q = L_tmp2_q; move16(); } ELSE { - L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp1_q } tmp_shift = sub( norm_l( dm_w ), 1 ); - L_tmp2 = L_shl( dm_w, tmp_shift ); + L_tmp2 = L_shl( dm_w, tmp_shift ); // Q=q_cov_real[0][0][b]+ tmp_shift L_tmp2_q = add( q_cov_real[0][0][b], tmp_shift ); IF( LT_16( L_tmp2_q, L_tmp1_q ) ) { - den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q den_f_e = sub( 31, L_tmp2_q ); } ELSE { - den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp2_q den_f_e = sub( 31, L_tmp1_q ); } - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q=31-den_f_e - tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); + tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); // Q= DM_F_q[b]+dm_beta_re_q tmp_shift = sub( W_norm( tmp64 ), 1 ); IF( tmp64 == 0 ) { @@ -1082,23 +1082,23 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q= DM_F_q[b]+dm_beta_re_q+tmp_shift } L_tmp2_q = sub( add( add( DM_F_q[b], dm_beta_re_q ), tmp_shift ), 32 ); - L_tmp2 = W_extract_h( tmp64 ); + L_tmp2 = W_extract_h( tmp64 ); // Q= DM_F_q[b]+dm_beta_re_q+tmp_shift-32 tmp_shift = sub( norm_l( dm_alpha[b] ), 1 ); IF( LT_16( L_tmp2_q, add( dm_alpha64_q[b], tmp_shift ) ) ) { - L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); + L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q L_tmp1_q = L_tmp2_q; move16(); } ELSE { L_tmp1_q = add( dm_alpha64_q[b], tmp_shift ); - L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp1_q } dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // L_tmp1_q - (31 - den_f_e) + (15 - s_div) @@ -1113,7 +1113,7 @@ static void ivas_get_pred_coeffs_enc_fx( Word16 num_f_e; /* quadratic activeW */ - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); // Q=dm_alpha64_q[b]+29 tmp_shift = sub( W_norm( tmp64 ), 1 ); IF( tmp64 == 0 ) { @@ -1122,31 +1122,31 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q+29+tmp_shift } - L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); // Q=dm_alpha64_q+29+1+tmp_shift-32 - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); // Q=31-num_f_e - sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 move16(); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ), &val_e ); // reducing the Q by 2 instead of multiplication by 4 + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); // q=31-val_e + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ) /* reducing the Q by 2 instead of multiplication by 4*/, &val_e ); // q=31-val_e // val_e = norm_l( sqrt_val ); - sqrt_val = Sqrt32( sqrt_val, &val_e ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); // q=31-val_e - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); // q=31-num_f_e - den_f = Mpy_32_32( dm_beta_re, g_th_sq ); + den_f = Mpy_32_32( dm_beta_re, g_th_sq ); // Q=dm_beta_re_q+27-31-1 den_f_e = add( add( sub( 31, dm_beta_re_q ), 4 ), 1 ); // adding the exp with 1 instead of multiplication by 2 - den_f = L_max( den_f, 1 ); - dm_g[b] = activew_quad_thresh; // Q29 + den_f = L_max( den_f, 1 ); // q=31-den_f_e + dm_g[b] = activew_quad_thresh; // Q29 move32(); dm_g_q[b] = Q29; move16(); - DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); // Q=(31-(s_dm_f+2+num_f_e-den_f_e)) move32(); DM_F_q[b] = sub( 31, add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ) ); move16(); @@ -1162,7 +1162,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); + tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); // dm_v_re_q[i][b]+dm_g_q[b] tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1171,14 +1171,14 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // dm_v_re_q[i][b]+dm_g_q[b]+tmp_shift } ppPred_coeffs_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + dm_g_q[b] + tmp_shift - 32 move32(); q_ppPred_coeffs_re[i][b] = sub( add( add( dm_v_re_q[i][b], dm_g_q[b] ), tmp_shift ), 32 ); move16(); - tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); + tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); // Q = dm_v_re_q[i][b] + DM_F_q[b] tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1187,7 +1187,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift } ppDM_Fv_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift - 32 move32(); @@ -1204,9 +1204,9 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( b = start_band; b < end_band; b++ ) { - ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); + ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); // Q=*q_pred_coeffs move32(); - ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); + ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); // Q=*q_dm_fv_re move32(); } } @@ -1216,9 +1216,9 @@ static void ivas_get_pred_coeffs_enc_fx( } static void ivas_get_pred_coeffs_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q30*/ + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -1241,12 +1241,12 @@ static void ivas_get_pred_coeffs_fx( IF( EQ_16( from_dirac, 1 ) ) { - w_norm_fac = ONE_IN_Q29; + w_norm_fac = ONE_IN_Q29; /*1 q29*/ move32(); } ELSE { - w_norm_fac = 3 * ONE_IN_Q29; + w_norm_fac = 3 * ONE_IN_Q29; /* 3 q29*/ move32(); } tmp_shift = Q30; @@ -1261,13 +1261,13 @@ static void ivas_get_pred_coeffs_fx( set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_max( 1, cov_real[0][0][k] ); + div_factor[k] = L_max( 1, cov_real[0][0][k] ); // q30 move32(); tmp_shift = Q30; move16(); - IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) // q30 { - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 q31*/, div_factor[k], &s_div ) ); // Q=15-(s_div-(31-30)) move32(); IF( s_div < 0 ) { @@ -1288,7 +1288,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1296,7 +1296,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1324,7 +1324,7 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); - pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); + pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); // q=31-q_pred_temp move32(); IF( LT_16( q_pred_temp, 1 ) ) @@ -1342,14 +1342,14 @@ static void ivas_get_pred_coeffs_fx( move16(); } - one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); + one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); /*Q=q_pred_temp*/ IF( LT_32( one_in_q, pPred_temp[k] ) ) { - div_factor[k] = pPred_temp[k]; + div_factor[k] = pPred_temp[k]; /*Q=q_pred_temp*/ move32(); - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); // q=15-s_div move32(); IF( s_div < 0 ) { @@ -1368,7 +1368,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE { - div_factor[k] = one_in_q; + div_factor[k] = one_in_q; // q=31-q_pred_temp move32(); tmp_shift = sub( 31, q_pred_temp ); } @@ -1377,7 +1377,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // q=tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1385,7 +1385,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // q=prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1427,12 +1427,12 @@ static void ivas_get_pred_coeffs_fx( IF( EQ_16( dyn_active_w_flag, 1 ) ) { - activew_quad_thresh = ONE_IN_Q29; + activew_quad_thresh = ONE_IN_Q29; // 1 q29 move32(); } ELSE { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; // 3 q29 move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -1453,13 +1453,13 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { dm_alpha_e = 31 - Q29; - dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); + dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); // q=31-dm_alpha_e move32(); - div_factor[k] = L_max( dm_alpha[k], 1 ); + div_factor[k] = L_max( dm_alpha[k], 1 ); // q=31-dm_alpha_e move32(); - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); // q=15-(s_div+(0-dm_alpha_e)) move32(); IF( s_div < 0 ) { @@ -1480,7 +1480,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // q=tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1488,7 +1488,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // q=prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1506,19 +1506,19 @@ static void ivas_get_pred_coeffs_fx( IF( dtx_vad == 0 ) { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; // q30 move32(); } ELSE { IF( active_w_vlbr ) { - dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; // q30 move32(); } ELSE { - dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; // q30 move32(); } } @@ -1552,8 +1552,8 @@ static void ivas_get_pred_coeffs_fx( dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); dm_w = cov_real[0][0][b]; // Q30 move32(); - den_f = L_max( dm_w, 1 ); - passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + den_f = L_max( dm_w, 1 ); // Q30 + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // Q=15-(s_div+dm_alpha_e-1) div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); passive_g = L_shl( passive_g, div_shift ); // Q = 29 @@ -1571,15 +1571,15 @@ static void ivas_get_pred_coeffs_fx( } IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) { - dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); // Q=tmp_shift-1 move32(); } ELSE { - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; // Q=tmp_shift-1 move32(); } - passive_g = activew_quad_thresh; + passive_g = activew_quad_thresh; // q29 move32(); } @@ -1604,24 +1604,24 @@ static void ivas_get_pred_coeffs_fx( DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 move32(); - DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); // q30 move32(); L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ - L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); - L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 - L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); + L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); // Q=(Q29-dm_beta_re_e) + L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 + L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); // Q29 den_f = L_add( L_tmp1, L_tmp2 ); // Q29 - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q29 den_f_e = 31 - 29; move16(); - L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); + L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); // Q=30-dm_beta_re_e L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); - L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); - L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); - L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); // Q=29 + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); // Q=29 + L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div move32(); @@ -1637,34 +1637,34 @@ static void ivas_get_pred_coeffs_fx( /* quadratic activeW */ - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); // Q=31-num_f_e sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ val_e = 4; move16(); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); // Q=31-val_e + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); // Q=31-val_e // val_e = norm_l( sqrt_val ); - sqrt_val = Sqrt32( sqrt_val, &val_e ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); // Q=31-val_e IF( val_e < 0 ) { - sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); + sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); // Q31 } ELSE IF( val_e > 0 ) { - sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); + sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); // Q31 val_e = 0; move16(); } - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); // Q=31-num_f_e - den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); + den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); // Q=31-dm_beta_re_e+27-31=>-dm_beta_re_e+27 den_f_e = add( dm_beta_re_e, 4 ); - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q=31-den_f_e dm_g[b] = activew_quad_thresh; // Q29 move32(); - DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); // s_dm_f+2+num_f_e-den_f_e move32(); s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ div_shift = sub( s_dm_f, 1 ); @@ -1679,7 +1679,7 @@ static void ivas_get_pred_coeffs_fx( { ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 move32(); - ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); // Q = tmp_shift - 1 + 30 -31 move32(); } } @@ -1703,11 +1703,11 @@ static void ivas_get_pred_coeffs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_Wscaling_factor_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -1717,7 +1717,7 @@ static void ivas_get_Wscaling_factor_enc_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ) { @@ -1770,41 +1770,41 @@ static void ivas_get_Wscaling_factor_enc_fx( ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } - Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); // 15-(tmp_exp-(q_cov_real[0][0][b]- q_postpred_cov_re)) q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real[0][0][b], q_postpred_cov_re ) ); guard_bits = find_guarded_bits_fx( num_ch ); FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) { - abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); - g_sq = L_add( g_sq, abs_val ); + abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); // q=2*q_pred_coeffs_re-guard_bits-31 + g_sq = L_add( g_sq, abs_val ); // q=2*q_pred_coeffs_re-guard_bits-31 } q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); - tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); // q_g_sq+28-31 q_tmp = sub( q_g_sq, 3 ); q_min = s_min( q_Gw_sq, q_tmp ); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // Q=q_min + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); // Q=q_min tmp_exp = sub( 31, q_min ); - tmp = Sqrt32( tmp, &tmp_exp ); + tmp = Sqrt32( tmp, &tmp_exp ); // q=31-tmp_exp q_tmp = sub( 31, tmp_exp ); tmp_exp = sub( 31, q_Gw_sq ); - Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); // q=31-tmp_exp q_Gw_sq = sub( 31, tmp_exp ); q_min = s_min( q_Gw_sq, q_tmp ); - Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); // q=q_min q_Gw_sq = q_min; move16(); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min - pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); + pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); // q=q_Gw_sq move32(); q_pWscale[b] = q_Gw_sq; move16(); @@ -1815,11 +1815,11 @@ static void ivas_get_Wscaling_factor_enc_fx( } static void ivas_get_Wscaling_factor_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -1829,7 +1829,7 @@ static void ivas_get_Wscaling_factor_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ) { @@ -1882,41 +1882,41 @@ static void ivas_get_Wscaling_factor_fx( ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } - Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); /*15-(tmp_exp-(q_cov_real-q_postpred_cov_re))*/ q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real, q_postpred_cov_re ) ); guard_bits = find_guarded_bits_fx( num_ch ); FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) { - abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); - g_sq = L_add( g_sq, abs_val ); + abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); /*q=2*q_pred_coeffs_re-guard_bits-31*/ + g_sq = L_add( g_sq, abs_val ); /*q=2*q_pred_coeffs_re-guard_bits-31*/ } q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); - tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); /*q=q_g_sq-3*/ q_tmp = sub( q_g_sq, 3 ); q_min = s_min( q_Gw_sq, q_tmp ); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); // q=q_min tmp_exp = sub( 31, q_min ); - tmp = Sqrt32( tmp, &tmp_exp ); + tmp = Sqrt32( tmp, &tmp_exp ); // q=31-tmp_exp q_tmp = sub( 31, tmp_exp ); tmp_exp = sub( 31, q_Gw_sq ); - Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); // q=31-tmp_exp q_Gw_sq = sub( 31, tmp_exp ); q_min = s_min( q_Gw_sq, q_tmp ); - Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); // q=q_min q_Gw_sq = q_min; move16(); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min - pWscale[b] = L_add( L_shr( Gw_sq, 1 /* Gw_sq * 0.5 */ ), L_shr( tmp, 1 /* tmp * 0.5 */ ) ); + pWscale[b] = L_add( L_shr( Gw_sq, 1 /* Gw_sq * 0.5 */ ), L_shr( tmp, 1 /* tmp * 0.5 */ ) ); // q=q_Gw_sq move32(); q_pWscale[b] = q_Gw_sq; move16(); @@ -1938,11 +1938,11 @@ static void ivas_get_Wscaling_factor_fx( #ifdef IVAS_FLOAT_FIXED void ivas_create_fullr_dmx_mat_fx( - Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 q_dm_fv_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 in_chans, const Word16 start_band, @@ -1983,9 +1983,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); + tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); // q=q_pred_coeffs_re } } @@ -1993,9 +1993,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[j - 1][b] ); + tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[j - 1][b] ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); // q=q_pred_coeffs_re } } @@ -2011,9 +2011,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); + tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); + max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); // q=q_dm_fv_re } } @@ -2021,9 +2021,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; + tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); + max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); // q=q_dm_fv_re } } @@ -2038,8 +2038,8 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_re = L_shr( Mpy_32_32( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b] ), guard_bits ); - down_mix_mat1_re[i][j][b] = L_add( down_mix_mat1_re[i][j][b], tmp_re ); + tmp_re = L_shr( Mpy_32_32( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b] ), guard_bits ); // q= q_dm_fv_re+ q_pred_coeffs_re-31-guard_bits + down_mix_mat1_re[i][j][b] = L_add( down_mix_mat1_re[i][j][b], tmp_re ); // q= q_dm_fv_re+ q_pred_coeffs_re-31-guard_bits move32(); } } @@ -2056,7 +2056,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; + down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; // q=q_pred_coeffs_re move32(); } } @@ -2084,10 +2084,10 @@ void ivas_create_fullr_dmx_mat_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_reorder_array_fx( - Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], /*qx*/ const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*qx*/ const Word16 start_band, const Word16 end_band ) { @@ -2102,7 +2102,7 @@ static void ivas_reorder_array_fx( { FOR( b = start_band; b < end_band; b++ ) { - mixer_mat[i][j][b] = in_re[idx][j][b]; + mixer_mat[i][j][b] = in_re[idx][j][b]; /*qx*/ move32(); } } @@ -2121,13 +2121,13 @@ static void ivas_reorder_array_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_post_pred_per_band_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ) { Word16 i, j, k, guard_bits, tmp, q_temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], q_tmp_re, q_W_tmp; @@ -2141,7 +2141,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( { FOR( j = 0; j < num_ch; j++ ) { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; /*q_mixer_mat*/ move32(); } } @@ -2165,16 +2165,16 @@ static void ivas_calc_post_pred_per_band_enc_fx( move16(); FOR( k = 0; k < num_ch; k++ ) { - W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); + W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); /*q_cov_real[i][k][band_idx]*/ IF( LT_16( q_cov_real[i][k][band_idx], q_tmp_re ) ) { - tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); /*q_cov_real[i][k][band_idx]*/ q_tmp_re = q_cov_real[i][k][band_idx]; move16(); } ELSE { - tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); /*q_tmp_re*/ } } IF( tmp_re == 0 ) @@ -2189,7 +2189,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_temp_mat[i][j] = q_tmp_re; move16(); q_tmp_re = W_norm( tmp_re ); - temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /*q_temp_mat[i][j]+ q_tmp_re -32*/ move32(); q_temp_mat[i][j] = sub( add( q_temp_mat[i][j], q_tmp_re ), 32 ); move16(); @@ -2224,17 +2224,17 @@ static void ivas_calc_post_pred_per_band_enc_fx( move16(); FOR( k = 0; k < num_ch; k++ ) { - W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); + W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); // q_temp_mat[k][j]+ q_mixer_mat-guard_bits q_W_tmp = sub( add( q_temp_mat[k][j], q_mixer_mat ), guard_bits ); IF( LT_16( q_W_tmp, q_tmp_re ) ) { - tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); // q_W_tmp q_tmp_re = q_W_tmp; move16(); } ELSE { - tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); // q_tmp_re } } @@ -2247,7 +2247,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_postpred_cov_re_per_value[i][j] = q_tmp_re; move16(); q_tmp_re = W_norm( tmp_re ); - postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /* q_tmp_re+ q_postpred_cov_re_per_value[i][j] -32*/ move32(); q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); move16(); @@ -2262,12 +2262,12 @@ static void ivas_calc_post_pred_per_band_enc_fx( { IF( postpred_cov_re[i][j] >= 0 ) { - postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); + postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); //*q_postpred_cov_re move32(); } ELSE { - postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); + postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); //*q_postpred_cov_re move32(); } } @@ -2277,7 +2277,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( { FOR( j = 0; j < i; j++ ) { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; + postpred_cov_re[i][j] = postpred_cov_re[j][i]; //*q_postpred_cov_re move32(); } } @@ -2286,13 +2286,13 @@ static void ivas_calc_post_pred_per_band_enc_fx( } static void ivas_calc_post_pred_per_band_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ) { Word16 i, j, k, guard_bits, tmp, q_temp_mat; @@ -2305,7 +2305,7 @@ static void ivas_calc_post_pred_per_band_fx( { FOR( j = 0; j < num_ch; j++ ) { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; /*q_mixer_mat*/ move32(); } } @@ -2329,7 +2329,7 @@ static void ivas_calc_post_pred_per_band_fx( move64(); FOR( k = 0; k < num_ch; k++ ) { - tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), guard_bits ) ); + tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), guard_bits ) ); /*q_cov_real+q_mixer_mat-guard_bits*/ } if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { @@ -2338,7 +2338,7 @@ static void ivas_calc_post_pred_per_band_fx( } temp_mat[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); // Q = (q_cov_real - guard_bits) move32(); - max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); + max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); // Q = (q_cov_real - guard_bits) } } q_temp_mat = sub( q_cov_real, guard_bits ); @@ -2365,7 +2365,7 @@ static void ivas_calc_post_pred_per_band_fx( move64(); FOR( k = 0; k < num_ch; k++ ) { - tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ) ); + tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ) ); /*q_mixer_mat+q_temp_mat-guard_bits*/ } if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) @@ -2374,7 +2374,7 @@ static void ivas_calc_post_pred_per_band_fx( move64(); } - postpred_cov_re[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); + postpred_cov_re[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); /*q_temp_mat-guard_bits*/ move32(); } } @@ -2386,7 +2386,7 @@ static void ivas_calc_post_pred_per_band_fx( { FOR( j = 0; j < i; j++ ) { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; + postpred_cov_re[i][j] = postpred_cov_re[j][i]; /* *q_postpred_cov_re */ move32(); } } @@ -2407,7 +2407,7 @@ static void ivas_calc_post_pred_per_band_fx( static void ivas_calc_p_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 q_postpred_cov_re, const Word16 num_ch, const Word16 dtx_vad, @@ -2445,7 +2445,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; // q_postpred_cov_re move32(); } } @@ -2458,7 +2458,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_postpred_cov_re move32(); } } @@ -2472,18 +2472,18 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { Word32 re1, re2; - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); /*q_cov_dd_re+ pSparMd->band_coeffs[b_ts_idx].q_C_re_fx*/ q_tmp1 = W_norm( W_tmp ); - re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); /*q_cov_dd_re+ q_C_re+q_tmp1-32*/ q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { q_tmp1 = 31; move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); /*q_cov_dd_re+ q_C_re*/ q_tmp = W_norm( W_tmp ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); /*q_cov_dd_re+ q_C_re+q_tmp-32*/ q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2491,10 +2491,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); // q_tmp1+q_C_re q_recon_uu_re[0][0] = W_norm( W_tmp ); move16(); - recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); + recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); // q_tmp1+q_C_re+q_recon_uu_re[0][0]-32 move32(); q_recon_uu_re[0][0] = sub( add( add( q_C_re, q_recon_uu_re[0][0] ), q_tmp1 ), 32 ); move16(); @@ -2504,10 +2504,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); // q_C_re+q_tmp1 q_recon_uu_re[0][1] = W_norm( W_tmp ); move16(); - recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); + recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); // q_C_re+q_tmp1+q_recon_uu_re[0][1]-32 move32(); q_recon_uu_re[0][1] = sub( add( add( q_C_re, q_recon_uu_re[0][1] ), q_tmp1 ), 32 ); move16(); @@ -2517,10 +2517,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); // q_C_re+q_tmp q_recon_uu_re[1][0] = W_norm( W_tmp ); move16(); - recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); + recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); // q_C_re+q_tmp+q_recon_uu_re[1][0]-32 move32(); q_recon_uu_re[1][0] = sub( add( add( q_C_re, q_recon_uu_re[1][0] ), q_tmp ), 32 ); move16(); @@ -2530,12 +2530,12 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); // q_C_re+q_tmp q_recon_uu_re[1][1] = W_norm( W_tmp ); move16(); - recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); + recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); // q_C_re+q_tmp+q_recon_uu_re[1][1]-32 move32(); - q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp1 ), 32 ); + q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp ), 32 ); move16(); if ( W_tmp == 0 ) { @@ -2558,7 +2558,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); // q_tmp move32(); } } @@ -2577,9 +2577,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( k = 0; k < 2; k++ ) { Word32 re; - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); // q_C_re+q_cov_dd_re q_tmp = sub( W_norm( W_tmp ), 1 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_cov_dd_re+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2589,35 +2589,35 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_re1[j] ) ) { - re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); + re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); // q_tmp move32(); q_re1[j] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_re1[j] ) ); + re = L_shr( re, sub( q_tmp, q_re1[j] ) ); // q_re1[j] } - re1[j] = L_add( re1[j], re ); + re1[j] = L_add( re1[j], re ); // q_re1[j] move32(); } } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); // q_C_re+q_re1[0] q_tmp = sub( W_norm( W_tmp ), 1 ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_re1[0]+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[0] ), 32 ); if ( W_tmp == 0 ) { q_tmp = 31; move16(); } - recon_uu_re[0][0] = re2; + recon_uu_re[0][0] = re2; // q_C_re+q_re1[0]+q_tmp-32 move32(); - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); // q_C_re+q_re1[1] q_tmp1 = sub( W_norm( W_tmp ), 1 ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); // q_C_re+q_re1[1]+q_tmp1-32 q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_re1[1] ), 32 ); if ( W_tmp == 0 ) { @@ -2627,22 +2627,22 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_tmp1 ) ) { - re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); + re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); // q_tmp } ELSE { - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); // q_tmp1 move32(); q_tmp = q_tmp1; move16(); } - recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); // q_tmp move32(); IF( LT_16( q_cov_uu_re, q_tmp ) ) { - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); // q_cov_uu_re move32(); } ELSE @@ -2651,7 +2651,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); // q_tmp move32(); } } @@ -2668,17 +2668,17 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); // q_cov_uu_re-1 move32(); } } q_cov_uu_re = sub( q_cov_uu_re, 1 ); - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); // q_cov_uu_re move32(); } } - cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); // q_cov_uu_re move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) @@ -2696,9 +2696,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( k = 0; k < num_dmx - 1; k++ ) { - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); // q_C_re+q_cov_dd_re q_tmp = sub( W_norm( W_tmp ), 2 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_cov_dd_re+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2708,29 +2708,29 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_re1[m] ) ) { - re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); + re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); // q_tmp move32(); q_re1[m] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_re1[m] ) ); + re = L_shr( re, sub( q_tmp, q_re1[m] ) ); // q_re1[m] } IF( re != 0 ) { test(); IF( W_norm( re ) == 0 || W_norm( re1[m] ) == 0 ) { - re1[m] = L_shr( re1[m], 1 ); + re1[m] = L_shr( re1[m], 1 ); // q_re1[m]-1 move32(); q_re1[m] = sub( q_re1[m], 1 ); move16(); - re = L_shr( re, 1 ); + re = L_shr( re, 1 ); // q_re1[m] } } - re1[m] = L_add( re1[m], re ); + re1[m] = L_add( re1[m], re ); // q_re1[m] move32(); } } @@ -2738,9 +2738,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( m = 0; m < num_dmx - 1; m++ ) { - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); // q_C_re+q_re1[m] q_tmp = sub( W_norm( W_tmp ), 2 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_re1[m]+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[m] ), 32 ); if ( W_tmp == 0 ) { @@ -2750,28 +2750,28 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_recon_uu_re[i][j] ) ) { - recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); + recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); // q_tmp move32(); q_recon_uu_re[i][j] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); + re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); // q_recon_uu_re[i][j] } IF( re != 0 ) { test(); IF( W_norm( re ) == 0 || W_norm( recon_uu_re[i][j] ) == 0 ) { - re1[m] = L_shr( re1[m], 1 ); + re1[m] = L_shr( re1[m], 1 ); // q_recon_uu_re[i][j]-1 move32(); q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); move16(); - re = L_shr( re, 1 ); + re = L_shr( re, 1 ); // q_recon_uu_re[i][j] } } - recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); // q_recon_uu_re[i][j] move32(); } } @@ -2793,7 +2793,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); // q_tmp move32(); } } @@ -2802,13 +2802,13 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( } } - p_norm_scaling = IVAS_P_NORM_SCALING_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; // q31 move32(); test(); if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; // q31 move32(); } @@ -2817,33 +2817,33 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); // q_cov_uu_re } - factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); // q_postpred_cov_re q_factor = q_postpred_cov_re; move16(); IF( trace != 0 ) { q_factor = W_norm( trace ); - tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); - q_factor = sub( add( q_postpred_cov_re, q_factor ), 32 ); + tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); // q_cov_uu_re+q_factor-32 + q_factor = sub( add( q_cov_uu_re, q_factor ), 32 ); IF( GT_16( q_factor, q_postpred_cov_re ) ) { - tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); + tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); // q_postpred_cov_re q_factor = q_postpred_cov_re; move16(); } ELSE { - factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); + factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); // q_factor } - factor = L_max( factor, tmp ); + factor = L_max( factor, tmp ); // q_factor } Word16 factor_exp = 0; move16(); - factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); + factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); // q=15-(factor_exp+31-(31-q_factor)) factor_exp = add( factor_exp, q_factor ); /* normalise Hermitian (except for rounding) cov_uu */ @@ -2854,14 +2854,14 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); + W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); /*q_cov_uu_re+15-factor_exp*/ q_tmp = 32; move16(); if ( W_tmp != 0 ) { q_tmp = W_norm( W_tmp ); } - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); /*q_cov_uu_re+15-factor_exp+q_tmp-32*/ move32(); q_cov_uu_re_per_value[i - num_dmx][j - num_dmx] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); move16(); @@ -2884,7 +2884,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] ); - cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); + cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); // q=31-cov_uu_re_exp move32(); q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] = sub( 31, cov_uu_re_exp ); move16(); @@ -2898,7 +2898,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); // Q28 move32(); } } @@ -2913,7 +2913,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( static void ivas_calc_p_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // q_postpred_cov_re Word16 q_postpred_cov_re, const Word16 num_ch, const Word16 dtx_vad, @@ -2948,7 +2948,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; // q=q_postpred_cov_re move32(); } } @@ -2961,7 +2961,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q=q_postpred_cov_re move32(); } } @@ -2973,13 +2973,13 @@ static void ivas_calc_p_coeffs_per_band_fx( { Word32 re1, re2; - re1 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ), q_C_re ) ); - re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ), q_C_re ) ); + re1 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ), q_C_re ) ); // q_cov_uu_re + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ), q_C_re ) ); // q_cov_uu_re - recon_uu_re[0][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ), q_C_re ) ); - recon_uu_re[0][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ), q_C_re ) ); - recon_uu_re[1][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ), q_C_re ) ); - recon_uu_re[1][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ), q_C_re ) ); + recon_uu_re[0][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[0][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[1][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[1][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ), q_C_re ) ); // q_cov_uu_re move32(); move32(); move32(); @@ -2989,7 +2989,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); + cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); // q_cov_uu_re move32(); } } @@ -3004,20 +3004,20 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( k = 0; k < 2; k++ ) { Word32 re; - re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ), q_C_re ) ); - re1[j] = L_add( re1[j], re ); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ), q_C_re ) ); // q_cov_uu_re + re1[j] = L_add( re1[j], re ); // q_cov_uu_re move32(); } } - re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ), q_C_re ) ); - recon_uu_re[0][0] = re2; + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[0][0] = re2; // q_cov_uu_re move32(); - re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ), q_C_re ) ); - recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); // q_cov_uu_re move32(); - cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); // q_cov_uu_re move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) @@ -3032,8 +3032,8 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( k = 0; k < num_dmx - 1; k++ ) { - re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ), q_C_re ) ); - re1[m] = L_add( re1[m], re ); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ), q_C_re ) ); // q_cov_uu_re + re1[m] = L_add( re1[m], re ); // q_cov_uu_re move32(); } } @@ -3041,8 +3041,8 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( m = 0; m < num_dmx - 1; m++ ) { - re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ), q_C_re ) ); - recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + re = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); // q_cov_uu_re move32(); } } @@ -3053,20 +3053,20 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); + cov_uu_re[i][j] = L_sub( cov_uu_re[i][j], recon_uu_re[i][j] ); // q_cov_uu_re move32(); } } } } - p_norm_scaling = IVAS_P_NORM_SCALING_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; /*q31*/ move32(); test(); if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; /*q31*/ move32(); } @@ -3075,15 +3075,15 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); + trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); // q_cov_uu_re } - factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); - factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); // q=q_postpred_cov_re + factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); // q=q_postpred_cov_re Word16 factor_exp = 0; move16(); - factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); + factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); // q=15-factor_exp tmp = sub( 15, factor_exp ); /* normalise Hermitian (except for rounding) cov_uu */ @@ -3094,7 +3094,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), tmp ) ); // q_cov_uu_re move32(); } ELSE @@ -3111,8 +3111,8 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re ); - cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); - cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); + cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); // q=31-cov_uu_re_exp + cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); // q_cov_uu_re move32(); move32(); } @@ -3124,7 +3124,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; // q_cov_uu_re move32(); } } @@ -3149,7 +3149,7 @@ static void ivas_calc_p_coeffs_per_band_fx( static void ivas_calc_c_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // q_post_pred_cov_re Word16 q_post_pred_cov_re, const Word16 num_ch, const Word16 num_dmx, @@ -3182,7 +3182,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3196,9 +3196,9 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - max_val = L_max( max_val, postpred_cov_re[i][j] ); + max_val = L_max( max_val, postpred_cov_re[i][j] ); // q_post_pred_cov_re } - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3208,10 +3208,10 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); + trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); // q_post_pred_cov_re } - abs_trace = L_abs( trace_cov_dd_re ); + abs_trace = L_abs( trace_cov_dd_re ); // q_post_pred_cov_re IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { @@ -3224,12 +3224,12 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { q_tmp = 1; move16(); - IF( norm_l( max_val ) > 0 ) + if ( norm_l( max_val ) > 0 ) { q_tmp = 0; move16(); } - trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); + trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); // q_post_pred_cov_re - q_tmp FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) @@ -3241,7 +3241,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re - q_tmp move32(); } test(); @@ -3268,12 +3268,12 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( move64(); FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) { - C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); + C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); // q_post_pred_cov_re+q_cov_dd_re_inv move64(); } - IF( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) + if ( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) { - W_max_val = W_abs( C_re_fx[i][j] ); + W_max_val = W_abs( C_re_fx[i][j] ); // q_post_pred_cov_re+q_cov_dd_re_inv } } } @@ -3284,7 +3284,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); // q_post_pred_cov_re+q_cov_dd_re_inv-tmp move32(); } } @@ -3299,7 +3299,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( static void ivas_calc_c_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_post_pred_cov_re*/ Word16 q_post_pred_cov_re, const Word16 num_ch, const Word16 num_dmx, @@ -3331,7 +3331,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3340,7 +3340,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3350,11 +3350,11 @@ static void ivas_calc_c_coeffs_per_band_fx( FOR( i = 0; i < num_dmx - 1; i++ ) { - trace_cov_dd_re = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + trace_cov_dd_re = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re } - trace_cov_dd_re = Mpy_32_32( trace_cov_dd_re, 10737418 /* 0.005f in Q31*/ ); + trace_cov_dd_re = Mpy_32_32( trace_cov_dd_re, 10737418 /* 0.005f in Q31*/ ); // q_post_pred_cov_re - abs_trace = L_abs( trace_cov_dd_re ); + abs_trace = L_abs( trace_cov_dd_re ); // q_post_pred_cov_re IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { @@ -3367,7 +3367,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re move32(); } test(); @@ -3394,12 +3394,12 @@ static void ivas_calc_c_coeffs_per_band_fx( move64(); FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) { - C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); + C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); // q_post_pred_cov_re+q_cov_dd_re_inv move64(); } - IF( LT_64( max_val, W_abs( C_re_fx[i][j] ) ) ) + if ( LT_64( max_val, W_abs( C_re_fx[i][j] ) ) ) { - max_val = W_abs( C_re_fx[i][j] ); + max_val = W_abs( C_re_fx[i][j] ); // q_post_pred_cov_re+q_cov_dd_re_inv } } } @@ -3410,7 +3410,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); // q_post_pred_cov_re+q_cov_dd_re_inv-tmp move32(); } } @@ -3435,10 +3435,10 @@ static void ivas_calc_c_coeffs_per_band_fx( void ivas_calc_c_p_coeffs_enc_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -3448,8 +3448,12 @@ void ivas_calc_c_p_coeffs_enc_fx( const Word16 dyn_active_w_flag ) { Word16 i, j, q_postpred_cov_re; - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] = { 0 }; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + { + set_zero_fx( postpred_cov_re[i], IVAS_SPAR_MAX_CH ); + } IF( NE_16( num_dmx, num_ch ) ) { ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); @@ -3494,10 +3498,10 @@ void ivas_calc_c_p_coeffs_enc_fx( void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -3556,40 +3560,40 @@ void ivas_calc_c_p_coeffs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_det_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim, - Word64 *det_re, + Word64 *det_re, /*q_det_re*/ Word16 *q_det_re ) { IF( EQ_16( dim, IVAS_MAT_DIM_3 ) ) { Word64 re1, re2, re; - re1 = W_mult0_32_32( in_re[1][1], in_re[2][2] ); - re2 = W_mult0_32_32( in_re[1][2], in_re[2][1] ); - re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[1][1], in_re[2][2] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][2], in_re[2][1] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - re1 = W_mult0_32_32( in_re[0][0], W_extract_h( re ) ); + re1 = W_mult0_32_32( in_re[0][0], W_extract_h( re ) ); /* 3*q_in_re - 32 */ - *det_re = re1; + *det_re = re1; /* 3*q_in_re - 32 */ move64(); - re1 = W_mult0_32_32( in_re[1][0], in_re[2][2] ); - re2 = W_mult0_32_32( in_re[1][2], in_re[2][0] ); - re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[1][0], in_re[2][2] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][2], in_re[2][0] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - re1 = W_mult0_32_32( in_re[0][1], W_extract_h( re ) ); + re1 = W_mult0_32_32( in_re[0][1], W_extract_h( re ) ); /* 3*q_in_re - 32 */ - *det_re = W_sub_nosat( *det_re, re1 ); + *det_re = W_sub_nosat( *det_re, re1 ); /* 3*q_in_re - 32 */ move64(); - re1 = W_mult0_32_32( in_re[1][0], in_re[2][1] ); - re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); - re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[1][0], in_re[2][1] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - re1 = W_mult0_32_32( in_re[0][2], W_extract_h( re ) ); + re1 = W_mult0_32_32( in_re[0][2], W_extract_h( re ) ); /* 3*q_in_re - 32 */ - *det_re = W_add_nosat( *det_re, re1 ); + *det_re = W_add_nosat( *det_re, re1 ); /* 3*q_in_re - 32 */ move64(); *q_det_re = add( q_in_re, sub( add( q_in_re, q_in_re ), 32 ) ); @@ -3598,16 +3602,16 @@ static void ivas_calc_mat_det_fx( ELSE IF( EQ_16( dim, IVAS_MAT_DIM_2 ) ) { Word64 re1, re2; - re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); - re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); - *det_re = W_sub_nosat( re1, re2 ); + re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); /* 2*q_in_re */ + *det_re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ move64(); *q_det_re = add( q_in_re, q_in_re ); move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { - *det_re = in_re[0][0]; + *det_re = in_re[0][0]; /*q_in_re*/ move32(); *q_det_re = q_in_re; move16(); @@ -3632,8 +3636,8 @@ static void ivas_calc_mat_det_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_mat_cofactor_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], - Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*qx*/ + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], /*qx*/ const Word16 row, const Word16 col ) { @@ -3649,7 +3653,7 @@ static void ivas_get_mat_cofactor_fx( test(); IF( NE_16( i, row ) && NE_16( j, col ) ) { - out_re[r][c] = in_re[i][j]; + out_re[r][c] = in_re[i][j]; /*qx*/ move64(); c = add( c, 1 ); } @@ -3677,10 +3681,10 @@ static void ivas_get_mat_cofactor_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim, - Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_out_re*/ Word16 *q_out_re ) { Word64 det; @@ -3689,7 +3693,7 @@ static void ivas_calc_mat_inv_fx( IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { - det = W_mult0_32_32( in_re[0][0], in_re[0][0] ); + det = W_mult0_32_32( in_re[0][0], in_re[0][0] ); /* 2*q_in_re */ /* assert to catch cases when input is singular matrix*/ assert( det > 0 ); @@ -3698,10 +3702,10 @@ static void ivas_calc_mat_inv_fx( // dbl_out_re[0][0] = dbl_in_re[0][0] * det = dbl_in_re[0][0] * (1 / (dbl_in_re[0][0] * dbl_in_re[0][0])); // dbl_out_re[0][0] = 1 / dbl_in_re[0][0]; - one_by_det = BASOP_Util_Divide3232_Scale( 1, in_re[0][0], &q_tmp ); + one_by_det = BASOP_Util_Divide3232_Scale( 1, in_re[0][0], &q_tmp ); /*q=15-(q_tmp-(0-q_in_re))*/ q_one_by_det = sub( 15, add( q_tmp, q_in_re ) ); - out_re[0][0] = one_by_det; + out_re[0][0] = one_by_det; /*q=q_one_by_det*/ move32(); *q_out_re = q_one_by_det; move16(); @@ -3715,22 +3719,22 @@ static void ivas_calc_mat_inv_fx( q_tmp = W_norm( det_re ); q_tmp = s_max( sub( 32, q_tmp ), 0 ); - det_re = W_shr( det_re, q_tmp ); + det_re = W_shr( det_re, q_tmp ); /*q_det_re-q_tmp*/ q_det_re = sub( q_det_re, q_tmp ); - det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); + det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); /* 2*q_det_re */ /* assert to catch cases when input is singular matrix*/ assert( det > 0 ); one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); // Q = (15 - (q_tmp + q_det_re)) - out_re[0][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); + out_re[0][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); /*q_in_re+(15 - (q_tmp + q_det_re)) -15=>q_in_re-(q_tmp + q_det_re)*/ - out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); + out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); /*q_in_re-(q_tmp + q_det_re)*/ - out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); + out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); /*q_in_re-(q_tmp + q_det_re)*/ - out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); + out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); /*q_in_re-(q_tmp + q_det_re)*/ move32(); move32(); move32(); @@ -3752,7 +3756,7 @@ static void ivas_calc_mat_inv_fx( q_tmp = W_norm( det_re ); q_tmp = s_max( sub( 32, q_tmp ), 0 ); - det_re = W_shr( det_re, q_tmp ); + det_re = W_shr( det_re, q_tmp ); /*q_det_re-q_tmp*/ q_det_re = sub( q_det_re, q_tmp ); if ( det_re == 0 ) @@ -3761,7 +3765,7 @@ static void ivas_calc_mat_inv_fx( move64(); } - one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); + one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); /*15-(q_tmp-(0-q_det_re))*/ q_one_by_det = sub( 15, add( q_tmp, q_det_re ) ); FOR( i = 0; i < dim; i++ ) @@ -3771,9 +3775,9 @@ static void ivas_calc_mat_inv_fx( ivas_get_mat_cofactor_fx( in_re, fac_re, i, j ); ivas_calc_mat_det_fx( fac_re, q_in_re, IVAS_MAT_DIM_2, &W_tmp, &q_W_tmp ); - out_re[j][i] = Mpy_32_16_1( W_extract_h( W_tmp ), one_by_det ); + out_re[j][i] = Mpy_32_16_1( W_extract_h( W_tmp ), one_by_det ); /*q_W_tmp-32+q_one_by_det-15*/ move32(); - out_re[j][i] = W_extract_l( W_mult0_32_32( out_re[j][i], sign ) ); + out_re[j][i] = W_extract_l( W_mult0_32_32( out_re[j][i], sign ) ); /*q_W_tmp-32+q_one_by_det-15*/ move32(); IF( s_and( add( i, j ), 1 ) == 0 ) @@ -3811,7 +3815,7 @@ static void ivas_calc_mat_inv_fx( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_is_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim ) { @@ -3825,10 +3829,10 @@ static Word16 ivas_is_mat_inv_fx( tmp = W_norm( det_re ); tmp = s_max( sub( 32, tmp ), 0 ); - det_re = W_shr( det_re, tmp ); + det_re = W_shr( det_re, tmp ); /*q_det_re-tmp*/ q_det_re = sub( q_det_re, tmp ); - det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); + det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); /*2*q_det_re*/ if ( LE_64( det, IVAS_FIX_EPS ) ) { @@ -3850,12 +3854,12 @@ static Word16 ivas_is_mat_inv_fx( #ifdef IVAS_FLOAT_FIXED void ivas_compute_spar_params_enc_fx( - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -3866,7 +3870,7 @@ void ivas_compute_spar_params_enc_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale, + Word32 *pWscale, /*q_Wscale*/ Word16 *q_Wscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ) @@ -3892,22 +3896,22 @@ void ivas_compute_spar_params_enc_fx( move16(); } - Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); /*q=15-(tmp_exp+(15-(15-q_Wscale)))=>15-(tmp_exp+q_Wscale)*/ q_tmp = sub( sub( 15, tmp_exp ), q_Wscale[b] ); tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); // Q28 move32(); } // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); - hSparMd->band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q28; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_pred_re_fx = Q28; move16(); FOR( i = 0; i < num_ch; i++ ) { - mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); /*q_mixer_mat*/ move32(); } } @@ -3928,12 +3932,12 @@ void ivas_compute_spar_params_enc_fx( void ivas_compute_spar_params_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -3944,7 +3948,7 @@ void ivas_compute_spar_params_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale_fx, + Word32 *pWscale_fx, /*q_pWscale*/ Word16 *q_pWscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ) @@ -3963,23 +3967,23 @@ void ivas_compute_spar_params_fx( FOR( b = start_band; b < end_band; b++ ) { Word16 tmp_exp, q_tmp, tmp; - Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale_fx[b], &tmp_exp ); + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale_fx[b], &tmp_exp ); /*15-(tmp_exp+q_pWscale[b])*/ q_tmp = sub( sub( 15, tmp_exp ), q_pWscale[b] ); tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); // q=tmp move32(); IF( tmp < 0 ) { tmp = negate( tmp ); - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], add( tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], add( tmp, 22 ) ); // q22 move32(); } ELSE { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], sub( tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i], sub( tmp, 22 ) ); // q22 move32(); } } @@ -3989,7 +3993,7 @@ void ivas_compute_spar_params_fx( FOR( i = 0; i < num_ch; i++ ) { - mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale_fx[b] ), q_pWscale[b] ) ); + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale_fx[b] ), q_pWscale[b] ) ); /*q_mixer_mat*/ move32(); } } @@ -4007,11 +4011,11 @@ void ivas_compute_spar_params_fx( IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX - FOR( i = 0; i < sub( num_ch, ndm ); i++ ) + FOR( i = 0; i < ( num_ch - ndm ); i++ ) { FOR( Word16 j = 0; j < sub( ndm, 1 ); j++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].C_re_fx[i][j], sub( q_tmp, 22 ) ); // q22 move32(); } } @@ -4033,10 +4037,10 @@ void ivas_compute_spar_params_fx( FOR( Word16 j = 0; j < sub( IVAS_SPAR_MAX_CH, 1 ); j++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[j], sub( q_tmp, 22 ) ); // q22 move32(); } - hSparMd->band_coeffs[b + imult1616( i_ts, IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; move16(); } } @@ -4052,9 +4056,9 @@ void ivas_compute_spar_params_fx( * *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -Word32 diff_norm_order1_table[4] = { 0, 805306368, 402653184, 268435456 }; -Word32 diff_norm_order2_table[6] = { 0, 1342177280, 671088640, 447392416, 335544320, 268435456 }; -Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762048, 375809632, 313174688, 268435456 }; +Word32 diff_norm_order1_table[4] = { 0, 805306368, 402653184, 268435456 }; // q28 +Word32 diff_norm_order2_table[6] = { 0, 1342177280, 671088640, 447392416, 335544320, 268435456 }; // q28 +Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762048, 375809632, 313174688, 268435456 }; // q28 #define EPSILON_FX_THR 70 #define ONE_BY_THREE_Q31 715827882 #define ONE_BY_FIVE_Q31 429496729 @@ -4064,7 +4068,7 @@ void ivas_get_spar_md_from_dirac_fx( Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 const Word16 n_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ Word16 *q_mixer_mat_fx, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, @@ -4147,36 +4151,36 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 move32(); } - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // q25 move32(); P_norm_fx[1] = 0; move32(); - FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { - P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 move32(); } - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ) )] ); + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // q25 move32(); P_norm_fx[2] = 0; move32(); - FOR( ; i < sub( num_ch, ndm ); i++ ) + FOR( ; i < ( num_ch - ndm ); i++ ) { - P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 move32(); } - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, sub( num_ch, ndm ) ) )] ); + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // q25 move32(); - FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) + FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -4185,16 +4189,16 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[0], IVAS_FIX_EPS ) ); + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[0], IVAS_FIX_EPS ) ); // q15 move32(); - P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 move32(); } } - FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -4202,16 +4206,16 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[1], IVAS_FIX_EPS ) ); + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[1], IVAS_FIX_EPS ) ); // q15 move32(); - P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 move32(); } } - FOR( ; i < sub( num_ch, ndm ); i++ ) + FOR( ; i < ( num_ch - ndm ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -4220,9 +4224,9 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[2], IVAS_FIX_EPS ) ); + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[2], IVAS_FIX_EPS ) ); // q15 move32(); - P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 move32(); } } @@ -4242,19 +4246,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][i_ts] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); // q0 } IF( azi_dirac_fx[band][i_ts] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); } @@ -4262,19 +4266,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][0] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); // q0 } IF( azi_dirac_fx[band][0] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); } @@ -4284,19 +4288,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][block] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); // q0 } IF( azi_dirac_fx[band][block] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, &( response_fx[block][0] ), order, Q30 ); } @@ -4316,9 +4320,9 @@ void ivas_get_spar_md_from_dirac_fx( move64(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); + temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); // q30 } - response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); + response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); // q30 move32(); } @@ -4329,13 +4333,13 @@ void ivas_get_spar_md_from_dirac_fx( move16(); FOR( ch = 1; ch < foa_ch; ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 30, 30 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4344,33 +4348,33 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q <= 0 ) { - norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); + norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); // q=31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = 1; ch < foa_ch; ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { IF( response_avg_fx[ch] != 0 ) { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 move32(); } - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 move32(); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } } @@ -4380,12 +4384,12 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4394,45 +4398,46 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, negate( norm_q ) ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - response_avg_fx[ch] = response_avg_fx[ch]; - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); } } /*normalize 3rd order*/ + norm_fx = 0; FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4441,32 +4446,32 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, negate( norm_q ) ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - response_avg_fx[ch] = response_avg_fx[ch]; - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 move32(); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } } @@ -4475,13 +4480,13 @@ void ivas_get_spar_md_from_dirac_fx( FOR( i = add( FOA_CHANNELS, 1 ); i < num_ch; i++ ) { - response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; + response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; // q30 move32(); } - en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30 - en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); + en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30=>q31 + en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); // q31 FOR( i = 0; i < num_ch; i++ ) { @@ -4491,48 +4496,48 @@ void ivas_get_spar_md_from_dirac_fx( { IF( i == 0 ) { - cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; + cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { Word32 en_ratio_fac_sq = 0; move32(); - cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); + cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); // q30 move32(); IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) { - cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); + cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); // q30 move32(); test(); IF( ( GE_16( i, ndm ) ) && ( EQ_16( dtx_vad, 1 ) ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); // q30 move32(); } ELSE { IF( LT_16( i, foa_ch ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31 /*1 q31*/, en_ratio_fac_sq ), ONE_BY_THREE_Q31 /*1/3 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } ELSE IF( LT_16( i, hoa2_ch ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } ELSE { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } } @@ -4541,17 +4546,17 @@ void ivas_get_spar_md_from_dirac_fx( { IF( LT_16( i, foa_ch ) ) { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 /*1/3 q31*/ ), 1 ) ); // q30 move32(); } ELSE IF( LT_16( i, hoa2_ch ) ) { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ), 1 ) ); // q30 move32(); } ELSE { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ), 1 ) ); // q30 move32(); } } @@ -4559,7 +4564,7 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); + cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); // q30 move32(); } } @@ -4570,7 +4575,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; + pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; // q30 move32(); } } @@ -4595,7 +4600,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); // q_mixer_mat_fx move32(); } } @@ -4614,7 +4619,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); + mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); // q_mixer_mat_fx move32(); } } @@ -4750,7 +4755,7 @@ void ivas_dirac_dec_get_response( * Input azimuth and elevation are expected in Q0 *------------------------------------------------------------------------*/ -Word32 local_result_table[91][9] = { +Word32 local_result_table[91][9] /*q30*/ = { { -1518500224, 0, @@ -5754,7 +5759,7 @@ Word32 local_result_table[91][9] = { } }; -Word32 local_result_table_2[91][9] = { +Word32 local_result_table_2[91][9] /*q30*/ = { { -1073741824, 0, @@ -6760,7 +6765,7 @@ Word32 local_result_table_2[91][9] = { void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, - Word32 *response_fx, + Word32 *response_fx, /*Q_out*/ const Word16 ambisonics_order, Word16 Q_out ) { @@ -6819,31 +6824,31 @@ void ivas_dirac_dec_get_response_fx( f_fx = 1; move16(); } - cos_1_fx = dirac_gains_trg_term_fx[az][0]; + cos_1_fx = dirac_gains_trg_term_fx[az][0]; // q31 move32(); - cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); - sin_1_fx = dirac_gains_trg_term_fx[az][1]; + cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); // q31 + sin_1_fx = dirac_gains_trg_term_fx[az][1]; // q31 move32(); if ( EQ_32( f_fx, -1 ) ) { - sin_1_fx = L_negate( sin_1_fx ); + sin_1_fx = L_negate( sin_1_fx ); // q31 move32(); } - cos_az_fx[0] = cos_1_fx; + cos_az_fx[0] = cos_1_fx; // q31 move32(); - cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 ), 1 ); + cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 /*0.5 q31*/ ), 1 ); /*q31*/ move32(); - cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) ), 1 ); + cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) /* cos_az_fx[0]/2 q31*/ ), 1 ); /*q31*/ move32(); - sin_az_fx[0] = sin_1_fx; + sin_az_fx[0] = sin_1_fx; /*q31*/ move32(); - sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); + sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); /*q31*/ move32(); - sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 ) ), 2 ); + sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 /*1/4 q31*/ ) ), 2 ); /*q31*/ move32(); - response_fx[0] = L_shl_sat( 1, Q_out ); + response_fx[0] = L_shl_sat( 1, Q_out ); // Q_out move32(); FOR( l = 1; l <= ambisonics_order; l++ ) @@ -6855,7 +6860,7 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, m ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table[el][a]; + c_fx_better = local_result_table[el][a]; // q30 move32(); response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); @@ -6870,11 +6875,11 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, m ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table[el][a]; + c_fx_better = local_result_table[el][a]; // q30 move32(); if ( EQ_16( e, -1 ) ) { - c_fx_better = L_negate( c_fx_better ); + c_fx_better = L_negate( c_fx_better ); // q30 } response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); @@ -6886,13 +6891,13 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, l ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table_2[el][a]; + c_fx_better = local_result_table_2[el][a]; // q30 move32(); IF( EQ_16( ( l % 2 ), 1 ) ) { if ( EQ_16( e, -1 ) ) { - c_fx_better = L_negate( c_fx_better ); + c_fx_better = L_negate( c_fx_better ); // q30 move32(); } } @@ -7043,7 +7048,11 @@ void ivas_spar_set_bitrate_config( num_PR_bits_dirac_bands = max( 0, num_PR_bits_dirac_bands ); num_PR_bits_dirac_bands *= DIRAC_TO_SPAR_HBR_PRED_CHS; +#ifdef IVAS_FLOAT_FIXED + n_input = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); +#else n_input = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); +#endif n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; n_dec = n_input - n_dmx; bits_PR = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx].q_lvls[quant_strat][0] ) ); @@ -7162,7 +7171,7 @@ void ivas_spar_set_bitrate_config_fx( } /* (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) */ - div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 /*1/FRAMES_PER_SEC Q31*/ ) ); /*31-31=>0*/ pSpar_md_cfg->tgt_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), total_bits ) ); pSpar_md_cfg->max_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); move16(); @@ -7186,8 +7195,8 @@ void ivas_spar_set_bitrate_config_fx( move16(); } - pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); - pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); + pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); /*Q0*/ + pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); /*Q0*/ pSpar_md_cfg->tgt_bits_per_blk = add( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); pSpar_md_cfg->max_bits_per_blk = add( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); @@ -7220,8 +7229,8 @@ void ivas_spar_set_bitrate_config_fx( num_PR_bits_dirac_bands = 0; move16(); } - div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); - num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); + div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); /*15-temp*/ + num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); /*q0*/ num_PR_bits_dirac_bands = s_max( 0, num_PR_bits_dirac_bands ); num_PR_bits_dirac_bands = i_mult( num_PR_bits_dirac_bands, DIRAC_TO_SPAR_HBR_PRED_CHS ); @@ -7238,12 +7247,12 @@ void ivas_spar_set_bitrate_config_fx( wc_coarse_strat = add( add( bits_PR, bits_C ), bits_P ); wc_coarse_strat = i_mult( wc_coarse_strat, num_bands ); - div1 = BASOP_Util_Divide3232_Scale( wc_coarse_strat, bands_bw, &temp ); - wc_coarse_strat = shr( div1, sub( 15, temp ) ); + div1 = BASOP_Util_Divide3232_Scale( wc_coarse_strat, bands_bw, &temp ); // q=15-temp + wc_coarse_strat = shr( div1, sub( 15, temp ) ); // q0 wc_coarse_strat = sub( wc_coarse_strat, num_PR_bits_dirac_bands ); wc_coarse_strat = add( wc_coarse_strat, md_coding_bits_header ); - IF( LT_16( pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat ) ) + if ( LT_16( pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat ) ) { assert( 0 ); } @@ -7402,7 +7411,7 @@ void ivas_spar_bitrate_dist_fx( move16(); FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 ) ); + core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); sum_core_act_bits = add( sum_core_act_bits, core_bits_act[i] ); @@ -7415,13 +7424,13 @@ void ivas_spar_bitrate_dist_fx( { FOR( i = 0; i < nchan_transport; i++ ) { - core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 ) ); + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); - core_bits_act[i] = add( core_bits_act[i], min( residual_bits, core_range_bits[i] ) ); + core_bits_act[i] = add( core_bits_act[i], s_min( residual_bits, core_range_bits[i] ) ); move16(); residual_bits = sub( residual_bits, core_range_bits[i] ); - IF( residual_bits <= 0 ) + if ( residual_bits <= 0 ) { BREAK; } @@ -7431,7 +7440,7 @@ void ivas_spar_bitrate_dist_fx( { FOR( i = 0; i < nchan_transport; i++ ) { - core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 ) ); + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); } @@ -7439,11 +7448,11 @@ void ivas_spar_bitrate_dist_fx( FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); + core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], s_min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); move16(); overflow_bits = sub( overflow_bits, core_range_bits[nchan_transport - 1 - i] ); - IF( overflow_bits <= 0 ) + if ( overflow_bits <= 0 ) { BREAK; } @@ -7461,7 +7470,7 @@ void ivas_spar_bitrate_dist_fx( overflow_bits = sub( overflow_bits, overflow_bits_ch ); } - core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], max( 0, overflow_bits ) ); + core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], s_max( 0, overflow_bits ) ); move16(); } } diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 0207e3e19..8b0bf766f 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -162,12 +162,12 @@ void ivas_quantise_real_values_enc_fx_varq( #ifdef IVAS_FLOAT_FIXED void ivas_quantise_real_values_fx( - const Word32 *values_fx, + const Word32 *values_fx, /*q28*/ const Word16 q_levels, - const Word32 min_value_fx, - const Word32 max_value_fx, + const Word32 min_value_fx, /*q28*/ + const Word32 max_value_fx, /*q28*/ Word16 *index, - Word32 *quant_fx, + Word32 *quant_fx, /*q28*/ const Word16 dim ) { Word16 i; @@ -186,18 +186,18 @@ void ivas_quantise_real_values_fx( ELSE IF( q_levels && NE_32( max_value_fx, min_value_fx ) ) { Word16 nor_q_level = norm_l( sub( q_levels, 1 ) ); - Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); - one_by_q_levels = L_shl( one_by_q_levels, 16 ); - q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); - Word16 one_by_max_min = divide3232( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ) ); - one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); + Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); // q15 + one_by_q_levels = L_shl( one_by_q_levels, 16 ); // q31 + q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); // q28 + Word16 one_by_max_min = divide3232( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ) ); // q15 + one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); // q15 Word32 val_fx; FOR( i = 0; i < dim; i++ ) { - val_fx = L_max( min_value_fx, L_min( values_fx[i], max_value_fx ) ); - index[i] = extract_l( L_shr( Mpy_32_32( one_by_q_step_fx, val_fx ), 12 ) ); + val_fx = L_max( min_value_fx, L_min( values_fx[i], max_value_fx ) ); // q28 + index[i] = extract_l( L_shr( Mpy_32_32( one_by_q_step_fx, val_fx ), 12 ) ); // q15+q28-q31-q12=>q0 move16(); - quant_fx[i] = imult3216( q_step_fx, index[i] ); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // q28 move16(); } } @@ -205,7 +205,7 @@ void ivas_quantise_real_values_fx( { FOR( i = 0; i < dim; i++ ) { - quant_fx[i] = values_fx[i]; + quant_fx[i] = values_fx[i]; // q28 move32(); } } @@ -418,25 +418,25 @@ void ivas_spar_get_uniform_quant_strat_fx( move16(); pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; // 1 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; //-1 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; move16(); pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].C.max_fx = ONE_IN_Q29; // Q28 + pSpar_md_com_cfg->quant_strat[i].C.max_fx = ONE_IN_Q29; // 2 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -ONE_IN_Q29; // Q28 + pSpar_md_com_cfg->quant_strat[i].C.min_fx = -ONE_IN_Q29; //-2 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; move16(); pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; // 1 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; // Q28 move32(); @@ -445,9 +445,9 @@ void ivas_spar_get_uniform_quant_strat_fx( move16(); pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; // 0.5 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27; //-0.5 Q28 move32(); } } @@ -475,33 +475,33 @@ void ivas_map_prior_coeffs_quant( { ivas_quant_strat_t qs = pSpar_md_cfg->quant_strat[qsi]; ivas_quant_strat_t prev_qs = pSpar_md_cfg->quant_strat[pSpar_md_cfg->prev_quant_idx]; - Word32 one_by_q_lvl_PR_fx = one_by_q_level[s_max( sub( prev_qs.PR.q_levels[0], 1 ), 1 )]; + Word32 one_by_q_lvl_PR_fx = one_by_q_level[max( ( prev_qs.PR.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_C_fx = one_by_q_level[s_max( sub( prev_qs.C.q_levels[0], 1 ), 1 )]; + Word32 one_by_q_lvl_C_fx = one_by_q_level[max( ( prev_qs.C.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_P_r_fx = one_by_q_level[s_max( sub( prev_qs.P_r.q_levels[0], 1 ), 1 )]; + Word32 one_by_q_lvl_P_r_fx = one_by_q_level[max( ( prev_qs.P_r.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); FOR( i = 0; i < nB; i++ ) { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - Word32 trial1 = L_mult0( sub( qs.PR.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] ); - trial1 = L_shl( trial1, 16 ); - trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_PR_fx ) ); - pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = extract_l( trial1 ); + Word32 trial1 = L_mult0( sub( qs.PR.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] ); /*q0*/ + trial1 = L_shl( trial1, 16 ); /*q16*/ + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_PR_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = extract_l( trial1 ); /*q0*/ move16(); - Word32 trial2 = L_mult0( sub( qs.P_r.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] ); - trial2 = L_shl( trial2, 16 ); - trial2 = round_fx( Mpy_32_32( trial2, one_by_q_lvl_P_r_fx ) ); - pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = extract_l( trial2 ); + Word32 trial2 = L_mult0( sub( qs.P_r.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] ); /*q0*/ + trial2 = L_shl( trial2, 16 ); /*q16*/ + trial2 = round_fx( Mpy_32_32( trial2, one_by_q_lvl_P_r_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = extract_l( trial2 ); /*q0*/ move16(); } FOR( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ ) { - Word32 trial1 = L_mult0( sub( qs.C.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] ); - trial1 = L_shl( trial1, 16 ); - trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_C_fx ) ); - pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = extract_l( trial1 ); + Word32 trial1 = L_mult0( sub( qs.C.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] ); /*q0*/ + trial1 = L_shl( trial1, 16 ); /*q16*/ + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_C_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = extract_l( trial1 ); /*q0*/ move16(); } } @@ -593,11 +593,11 @@ void ivas_spar_quant_dtx_init( void ivas_spar_quant_dtx_init_fx( ivas_spar_md_t *spar_md, - Word32 *min_max ) + Word32 *min_max /*q28*/ ) { - spar_md->min_max_fx[0] = min_max[0]; + spar_md->min_max_fx[0] = min_max[0]; // q28 move32(); - spar_md->min_max_fx[1] = min_max[1]; + spar_md->min_max_fx[1] = min_max[1]; // q28 move32(); return; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index bfe312557..fc0f2159d 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -216,7 +216,7 @@ typedef struct ivas_spar_md_t ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS]; int16_t num_bands; float min_max[2]; - Word32 min_max_fx[2]; + Word32 min_max_fx[2]; /*q28*/ int16_t dtx_vad; float en_ratio_slow[IVAS_MAX_NUM_BANDS]; Word32 en_ratio_slow_fx[IVAS_MAX_NUM_BANDS]; diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c index b315083d8..34a4573c9 100644 --- a/lib_com/ivas_stereo_dft_com.c +++ b/lib_com/ivas_stereo_dft_com.c @@ -43,7 +43,6 @@ #include "ivas_prot_fx.h" #endif -#define INV_FPS 655 // Q15 /*------------------------------------------------------------------------- * stereo_dft_config() * @@ -331,23 +330,23 @@ Word16 stereo_dft_band_config_fx( move16(); nbands = 0; move16(); - WHILE( LT_16( band_limits[nbands], shr( NFFT, 1 ) ) ) + WHILE( LT_16( band_limits[nbands], NFFT / 2 ) ) { - nbands = add( nbands, 1 ); + nbands++; IF( band_res == 0 ) { assert( 0 && "stereo DFT: band config failed!\n" ); } ELSE IF( EQ_16( band_res, 1 ) ) { - IF( enc_dec == ENC ) + IF( enc_dec == ENC /*0*/ ) { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0 move16(); } ELSE { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0 move16(); } @@ -357,12 +356,12 @@ Word16 stereo_dft_band_config_fx( { IF( enc_dec == ENC ) { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0 move16(); } ELSE { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0 move16(); } @@ -370,7 +369,7 @@ Word16 stereo_dft_band_config_fx( } } - band_limits[nbands] = shr( NFFT, 1 ); /*Nyquist Freq*/ + band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/ move16(); return ( nbands ); diff --git a/lib_com/ivas_stereo_eclvq_com_fx.c b/lib_com/ivas_stereo_eclvq_com_fx.c index deebbe7b8..aebde1530 100644 --- a/lib_com/ivas_stereo_eclvq_com_fx.c +++ b/lib_com/ivas_stereo_eclvq_com_fx.c @@ -81,12 +81,12 @@ Word32 ECSQ_dequantize_gain_fx( /* pow(10.0, index * ECLVQ_INV_GLOBAL_GAIN_FACTOR) = pow(2.0,(index * ECLVQ_INV_GLOBAL_GAIN_FACTOR)*3.321928 */ L_prod = Mpy_32_16_1( ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24, shl( index, 8 ) ); /* Q17 */ - L_tmp = Mpy_32_16_1( L_prod, 27213 ); /* Q17 + Q13 >> 15 => Q15 */ + L_tmp = Mpy_32_16_1( L_prod, 27213 /*3.321928 q13*/ ); /* Q17 + Q13 >> 15 => Q15 */ - global_gain = BASOP_util_Pow2( L_tmp, tmp_e, &gg_e ); + global_gain = BASOP_util_Pow2( L_tmp, tmp_e, &gg_e ); // 31-gg_e gg_e = sub( 16, gg_e ); - global_gain = L_shr( global_gain, gg_e ); + global_gain = L_shr( global_gain, gg_e ); // q15 return global_gain; } @@ -98,16 +98,17 @@ Word32 ECSQ_dequantize_gain_fx( * ---------------------------------------------------------------*/ void ECSQ_dequantize_vector_fx( - const Word16 *input, - const Word32 global_gain, + const Word16 *input, /*qx*/ + const Word32 global_gain, /*q15*/ const Word16 N, - Word32 *output ) + Word32 *output /*qx*/ +) { Word16 i; FOR( i = 0; i < N; ++i ) { - output[i] = Mpy_32_16_1( global_gain, input[i] ); + output[i] = Mpy_32_16_1( global_gain, input[i] ); /*qx+q15-15->qx*/ move32(); } diff --git a/lib_com/log2.c b/lib_com/log2.c index 9e1cb14ae..1fef489e9 100644 --- a/lib_com/log2.c +++ b/lib_com/log2.c @@ -51,8 +51,8 @@ * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 * *************************************************************************/ -Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ +Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15*/ + Word32 L_x /* (i) : input value (normalized) Qx*/ ) { Word16 i, a; @@ -72,7 +72,7 @@ Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val return y; } -Word32 log10_fx( Word32 Linput ) +Word32 log10_fx( Word32 Linput ) /*o : Q23, i: 2Q13*/ { Word16 n1, frac, p1, p2, q1; Word32 Ltemp1, Ltemp2; @@ -119,7 +119,7 @@ Word32 log10_fx( Word32 Linput ) return ( L_shr( Ltemp1, 1 ) ); } -Word32 pow_10( Word32 x, Word16 *Q ) +Word32 pow_10( Word32 x, Word16 *Q ) /*o : Q15, i: Q26*/ { Word16 xl, xh, t1, t2, n; Word32 Ltemp1; @@ -209,7 +209,7 @@ Word32 pow_10( Word32 x, Word16 *Q ) return ( L_shl( Lacc, sub( n, count ) ) ); } -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 - exponent*/ Word32 L_x, /* (i) : input value */ Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ ) diff --git a/lib_com/log2.h b/lib_com/log2.h index 9dc2b01ab..d87f677b5 100644 --- a/lib_com/log2.h +++ b/lib_com/log2.h @@ -26,14 +26,14 @@ * DECLARATION OF PROTOTYPES ******************************************************************************** */ -Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ +Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 */ + Word32 L_x /* (i) : input value (normalized) Qx */ ); -Word32 log10_fx( Word32 Linput ); -Word32 pow_10( Word32 x, Word16 *Q ); -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x, /* (i) : input value */ - Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ +Word32 log10_fx( Word32 Linput ); /*o : Q23, i: 2Q13*/ +Word32 pow_10( Word32 x, Word16 *Q ); /*o : Q15, i: Q26*/ +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 - exponent */ + Word32 L_x, /* (i) : input value */ + Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ ); #endif diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 4505c749d..cef2a6fa3 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -49,12 +49,12 @@ *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void logqnorm_ivas_fx( - const Word32 *x_fx, /* i : coefficient vector */ + const Word32 *x_fx, /* i : coefficient vector Qq*/ const Word16 q, /* i : q of coefficient vector */ Word16 *k_fx, /* o : index (Q0)*/ const Word16 L, /* i : codebook length */ const Word16 N, /* i : sub-vector size */ - const Word32 *thre_fxn /* i : quantization thresholds */ + const Word32 *thre_fxn /* i : quantization thresholds Q14*/ ) { Word16 i, j, j1, j2; @@ -82,10 +82,10 @@ void logqnorm_ivas_fx( thren0_sqr = W_mult0_32_32( thre_fxn[0], thre_fxn[0] ); // Q28 threnL2_sqr = W_mult0_32_32( thre_fxn[L - 2], thre_fxn[L - 2] ); // Q28 l_shift = W_norm( thren0_sqr ); - thren0_sqr32 = W_extract_h( W_shl( thren0_sqr, l_shift ) ); + thren0_sqr32 = W_extract_h( W_shl( thren0_sqr, l_shift ) ); // Q28 + l_shift - 32 thren0_sqr32_e = sub( 31, sub( add( Q28, l_shift ), 32 ) ); l_shift = W_norm( threnL2_sqr ); - threnL2_sqr32 = W_extract_h( W_shl( threnL2_sqr, l_shift ) ); + threnL2_sqr32 = W_extract_h( W_shl( threnL2_sqr, l_shift ) ); // Q28 + l_shift - 32 threnL2_sqr32_e = sub( 31, sub( add( Q28, l_shift ), 32 ) ); result1 = BASOP_Util_Add_Mant32Exp( thren0_sqr32, thren0_sqr32_e, L_negate( temp32_fx ), temp_e, &result1_e ); result2 = BASOP_Util_Add_Mant32Exp( threnL2_sqr32, threnL2_sqr32_e, L_negate( temp32_fx ), temp_e, &result2_e ); @@ -97,7 +97,7 @@ void logqnorm_ivas_fx( } ELSE IF( result2 > 0 ) { - *k_fx = L - 1; + *k_fx = sub( L, 1 ); move16(); } ELSE @@ -105,11 +105,11 @@ void logqnorm_ivas_fx( Word16 e = 0; move16(); power_fx = Sqrt32( ONE_IN_Q31, &e ); - power_fx = Sqrt32( temp32_fx, &temp_e ); + power_fx = Sqrt32( temp32_fx, &temp_e ); // Q31-temp_e // power_fx = L_shr( power_fx , Q14-(31-temp_e)); j1 = 0; move16(); - j2 = L - 1; + j2 = sub( L, 1 ); move16(); WHILE( GT_16( sub( j2, j1 ), 1 ) ) { @@ -164,21 +164,21 @@ void logqnorm_fx( FOR( i = 0; i < N; i++ ) { - coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); + coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); // Qx + coefs_shift - 16 move16(); - L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); + L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); // 2*(Qx + coefs_shift - 16) } - if ( GT_16( N, 1 ) ) + IF( GT_16( N, 1 ) ) { - Mpy_32_16_ss( L_temp, inv_tbl_fx[N], &L_temp, &lsb ); + Mpy_32_16_ss( L_temp, inv_tbl_fx[N], &L_temp, &lsb ); // 2*(Qx + coefs_shift - 16) } power_shift = shl( sub( coefs_shift, 16 ), 1 ); temp_shift = norm_l( L_temp ); m = add( temp_shift, power_shift ); - L_temp1 = L_add( L_shl( L_temp, temp_shift ), L_shr( lsb, sub( 16, temp_shift ) ) ); + L_temp1 = L_add( L_shl( L_temp, temp_shift ), L_shr( lsb, sub( 16, temp_shift ) ) ); // 2*(Qx + coefs_shift - 16)+ temp_shift m = add( offset, m ); test(); @@ -219,8 +219,8 @@ void logqnorm_2_fx( const Word16 L, /* i : codebook length */ const Word16 n_env_band, /* i : sub-vector size */ const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, /* o : norm indices */ - Word16 *normqlg2, /* o : quantized norm values */ + Word16 *ynrm, /* o : norm indices Q0*/ + Word16 *normqlg2, /* o : quantized norm values Q0*/ const Word32 *thren /* i, Q10 : quantization thresholds */ ) { @@ -306,7 +306,7 @@ void calc_norm_ivas_fx( logqnorm_ivas_fx( &x_fx[band_start[band]], 12, &nrm, 40, band_len[band], thren_HQ_fx ); norm[band] = nrm; move16(); - normlg[band] = dicnlg2[nrm]; + normlg[band] = dicnlg2[nrm]; // Q0 move16(); } diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 5efed0d03..ef47fa18d 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -27,7 +27,7 @@ void ivas_fine_gain_pred_fx( const Word16 *R, /* i : Bits per sub band Q3 */ const Word16 num_sfm, /* i : Number of sub bands */ Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *y, /* i/o: Quantized vector (int) Q0*/ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 core /* i : Core */ ) @@ -263,8 +263,8 @@ void get_max_pulses_fx( const Word16 *k_sort, /* i : Indices for sorting by energy */ const Word16 *npulses, /* i : Pulses per sub band */ const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ + Word16 *inp_vector, /* i/o: Encoded shape vectors (int)Q0*/ + Word16 *maxpulse /* o : Maximum pulse height per band Q0*/ ) { Word16 i, k; @@ -309,7 +309,7 @@ void fine_gain_dec_fx( const Word16 *ord, /* i : Indices for energy order */ const Word16 num_sfm, /* i : Number of bands */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains Q12*/ ) { Word16 band; diff --git a/lib_com/lpc_tools.c b/lib_com/lpc_tools.c index d3635d286..0c13ef7b1 100644 --- a/lib_com/lpc_tools.c +++ b/lib_com/lpc_tools.c @@ -195,10 +195,10 @@ int16_t lev_dur( } #ifdef IVAS_FLOAT_FIXED Word16 lev_dur_fx( - Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ - const Word32 *r_fx, /* i : vector of autocorrelations */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) Q(q_a)*/ + const Word32 *r_fx, /* i : vector of autocorrelations Q(q_r)*/ const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 epsP[], /* o : prediction error energy Q(q_r)*/ Word16 q_a, Word16 q_r ) { @@ -232,10 +232,10 @@ Word16 lev_dur_fx( move32(); FOR( j = 0; j < i; j++ ) { - s = L_add( s, Mpy_32_32( r_fx[i - j], a_fx[j] ) ); + s = L_add( s, Mpy_32_32( r_fx[i - j], a_fx[j] ) ); // Q(q_a + q_r - 31) } - rc_fx[i - 1] = divide3232( L_negate( s ), L_shr( err, sub( 31, q_a ) ) ); + rc_fx[i - 1] = divide3232( L_negate( s ), L_shr( err, sub( 31, q_a ) ) ); // Q15 move16(); if ( GT_16( abs_s( rc_fx[i - 1] ), 32749 ) ) // 32749 = 0.99945 in Q15 @@ -248,14 +248,14 @@ Word16 lev_dur_fx( FOR( j = 1; j <= tmp16; j++ ) { l = sub( i, j ); - at = L_add( a_fx[j], Mpy_32_16_1( a_fx[l], rc_fx[i - 1] ) ); // Q(q_a) - a_fx[l] = L_add( a_fx[l], Mpy_32_16_1( a_fx[j], rc_fx[i - 1] ) ); + at = L_add( a_fx[j], Mpy_32_16_1( a_fx[l], rc_fx[i - 1] ) ); // Q(q_a) + a_fx[l] = L_add( a_fx[l], Mpy_32_16_1( a_fx[j], rc_fx[i - 1] ) ); // Q(q_a) move32(); a_fx[j] = at; move32(); } - a_fx[i] = L_shl( rc_fx[i - 1], sub( q_a, 15 ) ); + a_fx[i] = L_shl( rc_fx[i - 1], sub( q_a, 15 ) ); // Q(q_a) move32(); err = L_add( err, L_shl( Mpy_32_16_1( s, rc_fx[i - 1] ), sub( 31, q_a ) ) ); // q_err - q_s diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index bfb5d8ed1..bec794e31 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -61,8 +61,8 @@ void autocorr_fx( const Word16 x[], /* i : Input signal */ const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16 *wind, /* i : Window used */ @@ -165,12 +165,12 @@ void autocorr_fx( } #ifdef IVAS_FLOAT_FIXED void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ + const Word16 x[], /* i : Input signal Q(q_x) */ const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations */ + Word32 r[], /* o : Autocorrelations Q_r */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ - const Word16 *wind, /* i : Window used */ + const Word16 *wind, /* i : Window used Q15 */ Word16 rev_flag, const Word16 sym_flag /* i : symmetric window flag */ ) @@ -185,7 +185,7 @@ void autocorr_fx_32( /* Windowing of signal */ FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); + y[i] = mult_r( x[i], wind[len - i - 1] ); // Q(x) move16(); } } @@ -195,12 +195,12 @@ void autocorr_fx_32( tmp16 = shr( len, 1 ); FOR( i = 0; i < tmp16; i++ ) { - y[i] = mult_r( x[i], wind[i] ); + y[i] = mult_r( x[i], wind[i] ); // Q(x) move16(); } FOR( ; i < len; i++ ) { - y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); + y[i] = mult_r( x[i], wind[len - i - 1] ); // Q(x) move16(); } } @@ -208,7 +208,7 @@ void autocorr_fx_32( { FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( x[i], wind[i] ); + y[i] = mult_r( x[i], wind[i] ); // Q(x) move16(); } } @@ -218,9 +218,9 @@ void autocorr_fx_32( L_sum = L_deposit_h( 16 ); /* sqrt(256), avoid overflow after rounding */ FOR( i = 0; i < len; i += 2 ) { - L_tmp = L_mult0( y[i], y[i] ); + L_tmp = L_mult0( y[i], y[i] ); // 2*Q(x) L_tmp = L_and( L_tmp, ~( 128 - 1 ) ); - L_tmp = L_mac0( L_tmp, y[i + 1], y[i + 1] ); + L_tmp = L_mac0( L_tmp, y[i + 1], y[i + 1] ); // 2*Q(x) L_tmp = L_shr( L_tmp, 7 ); L_sum = L_add( L_sum, L_tmp ); } @@ -234,7 +234,7 @@ void autocorr_fx_32( fact = lshr( -32768, shift ); FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( y[i], fact ); + y[i] = mult_r( y[i], fact ); // Q(x) move16(); } } @@ -245,10 +245,10 @@ void autocorr_fx_32( } /* Compute and normalize r[0] */ - L_sum = L_mac( 1, y[0], y[0] ); + L_sum = L_mac( 1, y[0], y[0] ); // 2*Q(x) FOR( i = 1; i < len; i++ ) { - L_sum = L_mac( L_sum, y[i], y[i] ); + L_sum = L_mac( L_sum, y[i], y[i] ); // 2*Q(x) } norm = norm_l( L_sum ); L_sum = L_shl( L_sum, norm ); @@ -258,14 +258,14 @@ void autocorr_fx_32( /* Compute r[1] to r[m] */ FOR( i = 1; i <= m; i++ ) { - L_sum = L_mult( y[0], y[i] ); + L_sum = L_mult( y[0], y[i] ); // 2*Q(x)+1 tmp16 = sub( len, i ); FOR( j = 1; j < tmp16; j++ ) { - L_sum = L_mac( L_sum, y[j], y[j + i] ); + L_sum = L_mac( L_sum, y[j], y[j + i] ); // 2*Q(x)+1 } - L_sum = L_shl( L_sum, norm ); + L_sum = L_shl( L_sum, norm ); // 2*Q(x)+1+norm r[i] = L_sum; move32(); } @@ -316,7 +316,7 @@ void autocorr_fx_32( * - result = L_num * (1/L_denom) * ***************************************************************************** */ -static Word32 Div_32_opt( Word32 L_num, Word16 denom_hi, Word16 denom_lo ) +static Word32 Div_32_opt( Word32 L_num /*Q31*/, Word16 denom_hi /*Qx -16*/, Word16 denom_lo /*Qx -1*/ ) { Word16 approx /*, hi, lo, n_hi , n_lo*/; Word32 L_32; @@ -364,12 +364,12 @@ static Word32 Div_32_opt( Word32 L_num, Word16 denom_hi, Word16 denom_lo ) * Returns: * void */ -Word16 E_LPC_lev_dur( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem ) +Word16 E_LPC_lev_dur( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/ ) { return ( E_LPC_lev_dur_stab( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ } -Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem, Word16 k_max ) +Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/, Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -794,12 +794,12 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 return ( flag ); } -Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem ) +Word16 E_LPC_lev_dur_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/ ) { return ( E_LPC_lev_dur_stab_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ } -Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem, Word16 k_max ) +Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/, Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -1026,7 +1026,7 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], * Returns: * void */ -void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ) +void E_LPC_a_add_tilt( const Word16 *a /*Qa*/, Word16 *ap /*Qa*/, Word16 gamma /*Q15*/, Word16 m ) { Word16 i; Word32 Amax, Atmp[M + 2]; @@ -1204,7 +1204,7 @@ Word16 E_LPC_lsp_unweight( * Returns: * void */ -Word32 E_LPC_schur( Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m ) +Word32 E_LPC_schur( Word32 r[] /*Qr*/, Word16 reflCoeff[] /*Q15*/, Word32 epsP[] /*Qr*/, const Word16 m ) { Word16 i, j, temp16, mM1, mMi, s; Word32 g0[M], *g1, tmp32; @@ -1286,8 +1286,8 @@ extern const PWord16 w19N[127]; extern const PWord16 w18N[127]; extern void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length ); static void spec2isf( - Word16 /*double*/ spec_r[], /* input spectrum real part (only left half + one zero)*/ - Word16 /*double*/ spec_i[], /* input spectrum imag part (only left half+right halt with zeros)*/ + Word16 /*double*/ spec_r[], /* input spectrum real part (only left half + one zero)Q_spec*/ + Word16 /*double*/ spec_i[], /* input spectrum imag part (only left half+right halt with zeros)Q_spec*/ Word16 /*short*/ speclen, /* length of spectrum (only left half)*/ Word16 /*double*/ lsf[], /* locations of LSFs (buffer must be sufficiently long) */ /*15Q16*/ @@ -1354,7 +1354,7 @@ static void spec2isf( return; } -void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep ) +void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/, const Word16 *old_lsf /*15Q16*/, Word16 lpcOrder, Word8 lpcRep /*Q0*/ ) { Word32 RealFFT[128]; Word32 ImagFFT[128]; diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index b41fa9de9..6292630af 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -24,15 +24,15 @@ void lsf_dec_bfi( const Word16 lsfBase[], /* i : base for differential lsf coding */ Word16 *mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ Word16 *mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) Q15*/ const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ Word16 L_frame, const Word16 last_good, /*!< i : last good received frame */ const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + Word16 *lsf_cng, /* Q2.56 */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise Q2.56*/ const Word16 Last_GSC_pit_band_idx, const Word16 Opt_AMR_WB, /* i : IO flag */ const Word8 tcxonly, @@ -140,11 +140,13 @@ void lsf_dec_bfi( ELSE { alpha = _ALPHA_VT_FX; /* rapid convergence to the CNG spectrum (long erasure, ONSETS) */ + move16(); } } ELSE { Word16 exp = 15; + move16(); alpha = Inv16( nbLostCmpt, &exp ); /*1.f/bfi_cnt;*/ alpha = shl( alpha, exp ); } @@ -254,7 +256,7 @@ return; } Word16 const *PlcGetLsfBase( - Word16 const lpcQuantization, + Word16 const lpcQuantization /*Q0*/, Word16 const narrowBand, Word32 const sr_core ) { diff --git a/lib_com/lsf_msvq_ma_fx.c b/lib_com/lsf_msvq_ma_fx.c index 409566ddc..6f8ea44c2 100644 --- a/lib_com/lsf_msvq_ma_fx.c +++ b/lib_com/lsf_msvq_ma_fx.c @@ -29,7 +29,7 @@ void midlsf_dec( const Word16 idx, /* i: codebook index */ Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ const Word16 coder_type, - Word16 *mid_lsf_int, + Word16 *mid_lsf_int, /*Q0*/ const Word16 prev_bfi, const Word16 safety_net ) { @@ -138,8 +138,8 @@ void midlsf_dec( return; } Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], + const Word16 lsf_q_ind[], /*(14Q1*1.28)*/ + const Word16 means[], /*(14Q1*1.28)*/ const Word16 narrowband, const Word16 cdk ) { diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index 4d063b5b0..d051a54c7 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -2088,12 +2088,12 @@ void dec_FDCNG_MSVQ_stage1( #ifdef IVAS_FLOAT_FIXED void dec_FDCNG_MSVQ_stage1_fx( - Word16 j_full, /* i : index full range */ - Word16 n, /* i : dimension to generate */ - const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - Word32 *uq, /* o : synthesized stage1 vector */ - Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ + Word16 j_full, /* i : index full range */ + Word16 n, /* i : dimension to generate */ + const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis Q31 */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + Word32 *uq, /* o : synthesized stage1 vector Q20 */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ) { Word16 col, segm_ind, j, i; @@ -2120,12 +2120,12 @@ void dec_FDCNG_MSVQ_stage1_fx( /* Word8 column variable Qx storage*/ cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ - cbpW8 += j * cdk1_ivas_cols_per_segment[segm_ind]; /* adaptive ptr init */ + cbpW8 += imult1616( j, cdk1_ivas_cols_per_segment[segm_ind] ); /* adaptive ptr init */ dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; FOR( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ ) { - dct_vec[col] = shl( cbpW8[col], dct_col_shift_tab[col] ); + dct_vec[col] = shl( cbpW8[col], dct_col_shift_tab[col] ); // Q0 move32(); /* LOGIC( 1 ) , SHIFT( 1 ); in BASOP: s_and(for W8->W16), shl() @@ -2138,7 +2138,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < cdk1_ivas_cols_per_segment[segm_ind]; i++ ) { - dct_vec_fx[i] = L_shl( dct_vec[i], norm ); + dct_vec_fx[i] = L_shl( dct_vec[i], norm ); // Q20 move32(); } @@ -2151,6 +2151,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < n; i++ ) { idct_vec_fx[i] = Mpy_32_32( idct_vec_fx[i], 56410112 ); /* norm + 31 - 31 = norm*/ + // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 move32(); } /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , @@ -2251,18 +2252,18 @@ void msvq_dec_float( #ifdef IVAS_FLOAT_FIXED void msvq_dec_fx( - const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ - const Word16 applyIDCT_flag, /* i : applyIDCT flag */ - const Word32 *invTrfMatrix, /* i : matrix for IDCT synthesis */ - Word32 *uq, /* o : quantized vector */ - Word16 *uq_ind, /* o : quantized vector (fixed point) */ - Word16 exp ) + const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) Q: (Q_cb) */ + const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook dimension */ + const Word16 Idx[], /* i : Indices */ + const Word16 applyIDCT_flag, /* i : applyIDCT flag */ + const Word32 *invTrfMatrix, /* i : matrix for IDCT synthesis Q31 */ + Word32 *uq, /* o : quantized vector */ + Word16 *uq_ind, /* o : quantized vector (fixed point) Q0 */ + Word16 Q_cb ) { Word16 i, n, maxn, start, k; Word16 j, max_size = 0; @@ -2327,7 +2328,7 @@ void msvq_dec_fx( { FOR( k = 0; k < N; k++ ) { - uq[k] = L_shr( uq[k], guard_bits ); + uq[k] = L_shr( uq[k], guard_bits ); // 20 - guard_bits move32(); } } @@ -2339,7 +2340,7 @@ void msvq_dec_fx( dec_FDCNG_MSVQ_stage1_fx( Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind ); /* IDCT_T2 N=24 used for all synthesis */ FOR( k = 0; k < N; k++ ) { - uq[k] = L_shr( uq[k], guard_bits ); + uq[k] = L_shr( uq[k], guard_bits ); // 20 - guard_bits move32(); } } @@ -2349,7 +2350,7 @@ void msvq_dec_fx( FOR( k = 0; k < n; k++ ) { - uq[add( start, k )] = L_add( uq[add( start, k )], L_lshl( cb[i][add( imult1616( Idx[i], maxn ), k )], sub( sub( 20, exp ), guard_bits ) ) ); + uq[start + k] = L_add( uq[start + k], L_lshl( cb[i][Idx[i] * maxn + k], sub( sub( 20, Q_cb ), guard_bits ) ) ); // 20 - guard_bits move32(); } } @@ -2359,7 +2360,8 @@ void msvq_dec_fx( { FOR( j = 0; j < n; ++j ) { - uq_ind[add( start, j )] = add( uq_ind[add( start, j )], (Word16) ( mult( cb[i][add( imult1616( Idx[i], maxn ), j )], 20971 ), sub( add( 13, exp ), 15 ) ) ); + uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 + // 2 * 1.28 in Q13 -> 20971 move16(); } } @@ -2711,11 +2713,11 @@ void dctT2_N_apply_matrix( #ifdef IVAS_FLOAT_FIXED void dctT2_N_apply_matrix_fx( - const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain */ - Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain */ + const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain Q20 */ + Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain Q20 */ const Word16 dct_dim, /* i : dct processing dim possibly truncated */ const Word16 fdcngvq_dim, /* i : fdcng domain length */ - const Word32 *matrix, /* i : IDCT matrix */ + const Word32 *matrix, /* i : IDCT matrix Q31 */ const Word16 matrix_row_dim, /* i : */ const DCTTYPE dcttype /* i : matrix operation type */ ) @@ -2773,7 +2775,7 @@ void dctT2_N_apply_matrix_fx( /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &( matrix[imult1616( i, add( mat_step_row, mat_step_col_flag ) )] ); /* ptr indexing */ + pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag ) ] ); /* ptr indexing */ PTR_INIT( 1 ); #undef WMC_TOOL_SKIP FOR( j = 0; j < dim_in; j++ ) @@ -2848,14 +2850,14 @@ void extend_dctN_input( #ifdef IVAS_FLOAT_FIXED void extend_dctN_input_fx( - const Word32 *input, /* i : input in fdcng domain Q */ - const Word32 *dct_input, /* i : input in dctN(fdcng) domain Q */ - const Word16 in_dim, /* i : in_dim == N */ - Word32 *ext_sig, /* o : extended output in fdcng domain Q */ - const Word16 out_dim, /* i : output total dim */ - Word32 *matrix, /* i : idct synthesis matrix N rows, n_cols columns 31 */ - const Word16 n_cols, /* i : number of columns == DCT truncation length */ - const DCTTYPE dcttype /* i : matrix operation type */ + const Word32 *input, /* i : input in fdcng domain Q */ + const Word32 *dct_input, /* i : input in dctN(fdcng) domain Q */ + const Word16 in_dim, /* i : in_dim == N */ + Word32 *ext_sig, /* o : extended output in fdcng domain Q */ + const Word16 out_dim, /* i : output total dim */ + Word32 *matrix, /* i : idct synthesis matrix N rows, n_cols columns 31 */ + const Word16 n_cols, /* i : number of columns == DCT truncation length */ + const DCTTYPE dcttype /* i : matrix operation type */ ) { Word16 i, j, i_rev; @@ -2868,7 +2870,7 @@ void extend_dctN_input_fx( assert( n_cols == FDCNG_VQ_DCT_MAXTRUNC ); /* for *ptr[MAX_TRUNC] adressing*/ assert( ( dcttype & 1 ) != 0 ); /* idct tables always in use for this basis vector extension */ - Copy32( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended */ + Copy32( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended q: Q */ set32_fx( &( ext_sig[in_dim] ), 0, sub( out_dim, in_dim ) ); i_rev = in_dim; /*ptr init*/ @@ -2980,10 +2982,10 @@ void create_IDCT_N_Matrix( #ifdef IVAS_FLOAT_FIXED void create_IDCT_N_Matrix_fx( - Word32 *inv_matrixFloatQ, /* i/o: RAM buffer */ - const Word16 N, /* i : DCT length, number of time samples */ - const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ - const Word16 alloc_size /* i : RAM buffer size in elements */ + Word32 *inv_matrixFloatQ, /* i/o: RAM buffer Q31 */ + const Word16 N, /* i : DCT length, number of time samples */ + const Word16 n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ + const Word16 alloc_size /* i : RAM buffer size in elements */ ) { Word16 c, c1, r, r_flip, W16_val, tmp16; @@ -2994,14 +2996,14 @@ void create_IDCT_N_Matrix_fx( Word16 idx; Word32( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) inv_matrixFloatQ; /* fixed number of columns pointers, to simplifies adressing in ANSIC */ - absval_ptr = unique_idctT2_24coeffsQ16; + absval_ptr = unique_idctT2_24coeffsQ16; // Q16 idx_ptr = idctT2_24_compressed_idx; len = FDCNG_VQ_MAX_LEN; move16(); IF( EQ_16( N, FDCNG_VQ_MAX_LEN_WB ) ) { - absval_ptr = unique_idctT2_21coeffsQ16; + absval_ptr = unique_idctT2_21coeffsQ16; // Q16 idx_ptr = idctT2_21_compressed_idx; len = N; move16(); @@ -3021,7 +3023,7 @@ void create_IDCT_N_Matrix_fx( FOR( c = 0; c < mat_cpy_size; c++ ) { idx = (Word16) ( idx_ptr[c] ); - W16_val = absval_ptr[abs( idx )]; + W16_val = absval_ptr[abs( idx )]; // Q16 move16(); IF( idx < 0 ) @@ -3048,8 +3050,8 @@ void create_IDCT_N_Matrix_fx( FOR( r = 0; r < tmp16; r_flip-- ) { #define WMC_TOOL_SKIP - ptr[r_flip][c] = ptr[r][c]; /* flipped */ - ptr[r_flip][c1] = L_negate( ptr[r][c1] ); /* flipped and sign swapped */ + ptr[r_flip][c] = ptr[r][c]; /* flipped: Q31*/ + ptr[r_flip][c1] = L_negate( ptr[r][c1] ); /* flipped and sign swapped: Q31 */ MOVE( 2 ); MULT( 1 ); /* for negate */ #undef WMC_TOOL_SKIP diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index a28f58851..d0dcc289e 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -1964,6 +1964,7 @@ ivas_error lsf_allocate_fx( bits1[n_stages] = bits_lvq; move16(); *stages1 = add( n_stages, 1 ); + move16(); } } ELSE @@ -2195,7 +2196,7 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, e ); /*Q(1+e)*/ - IF( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ L_tmp = Mpy_32_16_1( L_tmp, 16777 ); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ @@ -2296,7 +2297,7 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, e ); /*Q(0+e)*/ - IF( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ L_tmp = Mpy_32_16_1( L_tmp, 16777 ); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */ @@ -2815,28 +2816,29 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( /*=======================================================================*/ void lsf_syn_mem_backup_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsf_new, /* i: quantized LSF vector */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, - Word16 *pstreaklen ) + Encoder_State *st_fx, /* o: state structure */ + Word16 *btilt_code_fx, /* i: Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx,/* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ +) { Word16 i; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -2902,24 +2904,24 @@ void lsf_syn_mem_backup_fx( #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, + Encoder_State *st_fx, /* i: state structure */ + Word16 *btilt_code_fx, /* i: tilt code Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* o: */ + + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ) { Word16 i; @@ -2930,47 +2932,47 @@ void lsf_syn_mem_backup_ivas_fx( FOR( i = 0; i < M; i++ ) { - mem_AR[i] = st_fx->mem_AR_fx[i]; + mem_AR[i] = st_fx->mem_AR_fx[i]; // Q2.56 move16(); - mem_MA[i] = st_fx->mem_MA_fx[i]; + mem_MA[i] = st_fx->mem_MA_fx[i]; // Q2.56 move16(); - lsp_new_bck[i] = lsp_new[i]; + lsp_new_bck[i] = lsp_new[i]; // Q15 move16(); - lsp_mid_bck[i] = lsp_mid[i]; + lsp_mid_bck[i] = lsp_mid[i]; // Q15 move16(); } - *streaklimit = st_fx->streaklimit_fx; + *streaklimit = st_fx->streaklimit_fx; // Q15 move16(); *pstreaklen = st_fx->pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - Bin_E[i] = st_fx->Bin_E_fx[i]; + Bin_E[i] = st_fx->Bin_E_fx[i]; // Q_new + Q_SCALE - 2 move32(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; + Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; // Q_new + Q_SCALE - 2 move32(); } /* back-up memories */ FOR( i = 0; i < M; i++ ) { - mem_syn_bck[i] = hLPDmem->mem_syn[i]; + mem_syn_bck[i] = hLPDmem->mem_syn[i]; // Q: ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); } - *mem_w0_bck = hLPDmem->mem_w0; + *mem_w0_bck = hLPDmem->mem_w0; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); - *btilt_code_fx = hLPDmem->tilt_code; + *btilt_code_fx = hLPDmem->tilt_code; // Q15 move16(); - *gc_threshold_fx = hLPDmem->gc_threshold; + *gc_threshold_fx = hLPDmem->gc_threshold; // Q16 move16(); Copy( st_fx->clip_var_fx, clip_var_bck_fx, 6 ); *next_force_sf_bck_fx = st_fx->next_force_safety_net; @@ -3034,28 +3036,28 @@ void lsf_update_memory( /* _ None */ /*=======================================================================*/ void lsf_syn_mem_restore_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsf_new, /* o: quantized LSF vector */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3067,78 +3069,81 @@ void lsf_syn_mem_restore_fx( FOR( i = 0; i < M; i++ ) { - st_fx->mem_AR_fx[i] = mem_AR[i]; + st_fx->mem_AR_fx[i] = mem_AR[i]; // 2.56 move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; + st_fx->mem_MA_fx[i] = mem_MA[i]; // 2.56 move16(); - lsp_new[i] = lsp_new_bck[i]; + lsp_new[i] = lsp_new_bck[i]; // Q15 move16(); - lsf_new[i] = lsf_new_bck[i]; + lsf_new[i] = lsf_new_bck[i]; // Q15 move16(); - lsp_mid[i] = lsp_mid_bck[i]; + lsp_mid[i] = lsp_mid_bck[i]; // Q15 move16(); } st_fx->mCb1_fx = mCb1; move16(); - st_fx->streaklimit_fx = streaklimit; + st_fx->streaklimit_fx = streaklimit; // Q15 move16(); st_fx->pstreaklen = pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - st_fx->Bin_E_fx[i] = Bin_E[i]; + st_fx->Bin_E_fx[i] = Bin_E[i]; // Q_new + Q_SCALE - 2 move16(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; + st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; // Q_new + Q_SCALE - 2 move32(); } /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; + hLPDmem->mem_w0 = mem_w0_bck; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); FOR( i = 0; i < M; i++ ) { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; + hLPDmem->mem_syn[i] = mem_syn_bck[i]; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); } move16(); move32(); move16(); - hLPDmem->tilt_code = btilt_code_fx; - hLPDmem->gc_threshold = gc_threshold_fx; + hLPDmem->tilt_code = btilt_code_fx; // Q15 + hLPDmem->gc_threshold = gc_threshold_fx; // Q16 + move16(); + move32(); Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); st_fx->next_force_safety_net = next_force_sf_bck_fx; + move16(); return; } #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_restore_ivas_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3150,47 +3155,47 @@ void lsf_syn_mem_restore_ivas_fx( FOR( i = 0; i < M; i++ ) { - st_fx->mem_AR_fx[i] = mem_AR[i]; + st_fx->mem_AR_fx[i] = mem_AR[i]; // 2.56 move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; + st_fx->mem_MA_fx[i] = mem_MA[i]; // 2.56 move16(); - lsp_new[i] = lsp_new_bck[i]; + lsp_new[i] = lsp_new_bck[i]; // Q15 move16(); - lsp_mid[i] = lsp_mid_bck[i]; + lsp_mid[i] = lsp_mid_bck[i]; // Q15 move16(); } - st_fx->streaklimit_fx = streaklimit; + st_fx->streaklimit_fx = streaklimit; // Q15 move16(); st_fx->pstreaklen = pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - st_fx->Bin_E_fx[i] = Bin_E[i]; + st_fx->Bin_E_fx[i] = Bin_E[i]; // Q_new + Q_SCALE - 2 move16(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; + st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; // Q_new + Q_SCALE - 2 move32(); } /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; + hLPDmem->mem_w0 = mem_w0_bck; // Q(15 - st_fx->hLPDmem->e_mem_syn ) move16(); FOR( i = 0; i < M; i++ ) { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; + hLPDmem->mem_syn[i] = mem_syn_bck[i]; // Q(15 - st_fx->hLPDmem->e_mem_syn ) move16(); } move16(); - hLPDmem->tilt_code = btilt_code_fx; + hLPDmem->tilt_code = btilt_code_fx; // Q15 move32(); - hLPDmem->gc_threshold = gc_threshold_fx; + hLPDmem->gc_threshold = gc_threshold_fx; // Q16 Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); st_fx->next_force_safety_net = next_force_sf_bck_fx; move16(); diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index 70b919002..762dea2bd 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -535,7 +535,7 @@ static void spectautocorr_fx( * Here m = 51. *---------------------------------------------------------------------*/ - imid = ( N - 1 ) / 2; + imid = shr( sub( N, 1 ), 1 ); move16(); /*---------------------------------------------------------------------* @@ -569,7 +569,7 @@ static void spectautocorr_fx( FOR( i = 3; i < M; i += 2 ) { r[i] = L_deposit_l( 0 ); - r[i + 1] = -r[i - 1]; + r[i + 1] = L_negate( r[i - 1] ); move32(); move32(); } diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 4b8d785b4..42241bce1 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -534,7 +534,7 @@ void Interpolate_allpass_steep( void Interpolate_allpass_steep_32( const Word32 *in_fx, /* i : input array of size N Qx */ Word32 *mem_fx, /* i/o: memory Qx */ - const int16_t N, /* i : number of input samples */ + const int16_t N, /* i : number of input samples */ Word32 *out_fx /* o : output array of size 2*N Qx */ ) { @@ -545,46 +545,46 @@ void Interpolate_allpass_steep_32( /* upper allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = Madd_32_16( mem_fx[0], in_fx[k], AP2_STEEP_FX[0] ); + temp_fx[0] = Madd_32_16( mem_fx[0], in_fx[k], AP2_STEEP_FX[0] ); // Qx move32(); - mem_fx[0] = Msub_32_16( in_fx[k], temp_fx[0], AP2_STEEP_FX[0] ); + mem_fx[0] = Msub_32_16( in_fx[k], temp_fx[0], AP2_STEEP_FX[0] ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = Madd_32_16( mem_fx[n], temp_fx[n - 1], AP2_STEEP_FX[n] ); + temp_fx[n] = Madd_32_16( mem_fx[n], temp_fx[n - 1], AP2_STEEP_FX[n] ); // Qx move32(); - mem_fx[n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP2_STEEP_FX[n] ); + mem_fx[n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP2_STEEP_FX[n] ); // Qx move32(); } - out_fx[2 * k + 1] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + out_fx[2 * k + 1] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + mem_fx[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); } /* lower allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP], in_fx[k], AP1_STEEP_FX[0] ); + temp_fx[0] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP], in_fx[k], AP1_STEEP_FX[0] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP] = Msub_32_16( in_fx[k], temp_fx[0], AP1_STEEP_FX[0] ); + mem_fx[ALLPASSSECTIONS_STEEP] = Msub_32_16( in_fx[k], temp_fx[0], AP1_STEEP_FX[0] ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP + n], temp_fx[n - 1], AP1_STEEP_FX[n] ); + temp_fx[n] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP + n], temp_fx[n - 1], AP1_STEEP_FX[n] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP1_STEEP_FX[n] ); + mem_fx[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP1_STEEP_FX[n] ); // Qx move32(); } - out_fx[2 * k] = Madd_32_16( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + out_fx[2 * k] = Madd_32_16( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); - mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); } #else @@ -728,9 +728,9 @@ void Decimate_allpass_steep( #ifdef IVAS_FLOAT_FIXED void Decimate_allpass_steep_fx32( const Word32 *in, /* i : input array of size N Qx */ - Word32 *mem, /* i/o: memory Qx*/ - const Word16 N, /* i : number of input samples */ - Word32 *out /* o : output array of size N/2 Qx*/ + Word32 *mem, /* i/o: memory Qx */ + const Word16 N, /* i : number of input samples */ + Word32 *out /* o : output array of size N/2 Qx */ ) { Word16 n, k; @@ -739,74 +739,74 @@ void Decimate_allpass_steep_fx32( /* upper allpass filter chain */ FOR( k = 0; k < N / 2; k++ ) { - temp[0] = L_add( mem[0], Mpy_32_16_1( in[2 * k], AP1_STEEP_FX[0] ) ); + temp[0] = L_add( mem[0], Mpy_32_16_1( in[2 * k], AP1_STEEP_FX[0] ) ); // Qx move32(); - mem[0] = L_sub( in[2 * k], Mpy_32_16_1( temp[0], AP1_STEEP_FX[0] ) ); + mem[0] = L_sub( in[2 * k], Mpy_32_16_1( temp[0], AP1_STEEP_FX[0] ) ); // Qx move32(); - temp[1] = L_add( mem[1], Mpy_32_16_1( temp[0], AP1_STEEP_FX[1] ) ); + temp[1] = L_add( mem[1], Mpy_32_16_1( temp[0], AP1_STEEP_FX[1] ) ); // Qx move32(); - mem[1] = L_sub( temp[0], Mpy_32_16_1( temp[1], AP1_STEEP_FX[1] ) ); + mem[1] = L_sub( temp[0], Mpy_32_16_1( temp[1], AP1_STEEP_FX[1] ) ); // Qx move32(); - out[k] = L_add( mem[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + out[k] = L_add( mem[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); } /* lower allpass filter chain */ - temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ) ); + temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP] = L_sub( mem[2 * ALLPASSSECTIONS_STEEP], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); + mem[ALLPASSSECTIONS_STEEP] = L_sub( mem[2 * ALLPASSSECTIONS_STEEP], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); + temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx move32(); /*if ( fabs( temp[n] ) < 1e-12 ) { temp[n] = sign( temp[n] ) * 1e-12f; }*/ - mem[ALLPASSSECTIONS_STEEP + 1] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); + mem[ALLPASSSECTIONS_STEEP + 1] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); //Qx move32(); - mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - out[0] = W_round48_L( W_mac_32_16( W_mult_32_16( out[0], 16384 ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); + out[0] = W_round48_L( W_mac_32_16( W_mult_32_16( out[0], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx move32(); FOR( k = 1; k < N / 2; k++ ) { - temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); + temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); + mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); + temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx move32(); /*if ( fabs( temp[n] ) < 1e-12 ) { temp[n] = sign( temp[n] ) * 1e-12f; }*/ - mem[ALLPASSSECTIONS_STEEP + n] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); + mem[ALLPASSSECTIONS_STEEP + n] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - out[k] = W_round48_L( W_mac_32_16( W_mult_32_16( out[k], 16384 ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); + out[k] = W_round48_L( W_mac_32_16( W_mult_32_16( out[k], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx move32(); } @@ -900,57 +900,57 @@ void interpolate_3_over_2_allpass_32( Word32 out1_buff[L_FRAME32k * 3]; Word32 *out1; Word32 mem_temp; - const Word16 *filt_coeff = allpass_poles_3_ov_2; + const Word16 *filt_coeff = allpass_poles_3_ov_2; // Q15 out1 = out1_buff; FOR( i = 0; i < len; i++ ) { /* Upper branch */ - Vu[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[1] ), filt_coeff[0] ) ); + Vu[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vu[1] = L_add( mem[1], Mpy_32_16_1( ( Vu[0] - mem[2] ), filt_coeff[1] ) ); + Vu[1] = L_add( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[3] = L_add( mem[2], Mpy_32_16_1( ( Vu[1] - mem[3] ), filt_coeff[2] ) ); + mem[3] = L_add( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[1] = Vu[0]; + mem[1] = Vu[0]; // Qx move32(); - mem[2] = Vu[1]; + mem[2] = Vu[1]; // Qx move32(); - *out1++ = mem[3]; + *out1++ = mem[3]; // Qx move32(); /* Middle branch */ - Vm[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[4] ), filt_coeff[3] ) ); + Vm[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vm[1] = L_add( mem[4], Mpy_32_16_1( ( Vm[0] - mem[5] ), filt_coeff[4] ) ); + Vm[1] = L_add( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[6] = L_add( mem[5], Mpy_32_16_1( ( Vm[1] - mem[6] ), filt_coeff[5] ) ); + mem[6] = L_add( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[4] = Vm[0]; + mem[4] = Vm[0]; // Qx move32(); - mem[5] = Vm[1]; + mem[5] = Vm[1]; // Qx move32(); - *out1++ = mem[6]; + *out1++ = mem[6]; // Qx move32(); /* Lower branch */ - Vl[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[7] ), filt_coeff[6] ) ); + Vl[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vl[1] = L_add( mem[7], Mpy_32_16_1( ( Vl[0] - mem[8] ), filt_coeff[7] ) ); + Vl[1] = L_add( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[9] = L_add( mem[8], Mpy_32_16_1( ( Vl[1] - mem[9] ), filt_coeff[8] ) ); + mem[9] = L_add( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[0] = input[i]; + mem[0] = input[i]; // Qx move32(); - mem[7] = Vl[0]; + mem[7] = Vl[0]; // Qx move32(); - mem[8] = Vl[1]; + mem[8] = Vl[1]; // Qx move32(); - *out1++ = mem[9]; + *out1++ = mem[9]; // Qx move32(); } @@ -961,17 +961,19 @@ void interpolate_3_over_2_allpass_32( { mem_temp = out1_buff[2 * i]; move32(); - out[i] = L_add( Mpy_32_16_1( ( mem_temp + mem[10] ), 1550 ), Mpy_32_16_1( ( mem[11] + mem[14] ), -4965 ) ); - out[i] = L_add( out[i], Mpy_32_16_1( ( mem[12] + mem[13] ), 20125 ) ); - mem[10] = mem[11]; + out[i] = L_add( Mpy_32_16_1( L_add( mem_temp, mem[10] ), 1550 ), Mpy_32_16_1( L_add( mem[11], mem[14] ), -4965 ) ); // Qx + Q15 - Q15 -> Qx + // 0.0473147f in Q15 -> 1550, -0.151521f in Q15 -> -4965 + out[i] = L_add( out[i], Mpy_32_16_1( L_add( mem[12], mem[13] ), 20125 ) ); + // 0.614152f in Q15 -> 20125 + mem[10] = mem[11]; // Qx move32(); - mem[11] = mem[12]; + mem[11] = mem[12]; // Qx move32(); - mem[12] = mem[13]; + mem[12] = mem[13]; // Qx move32(); - mem[13] = mem[14]; + mem[13] = mem[14]; // Qx move32(); - mem[14] = mem_temp; + mem[14] = mem_temp; // Qx move32(); } @@ -1127,67 +1129,67 @@ void interpolate_3_over_1_allpass( #ifdef IVAS_FLOAT_FIXED void interpolate_3_over_1_allpass_32( - const Word32 *input, /* i : input signal */ - const Word16 len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ + const Word32 *input, /* i : input signal Qx */ + const Word16 len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ) { Word16 i, tmp16; Word32 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word32 *out1; Word32 mem_temp; - const Word16 *filt_coeff = allpass_poles_3_ov_2; + const Word16 *filt_coeff = allpass_poles_3_ov_2; // Qx out1 = &out[0]; FOR( i = 0; i < len; i++ ) { /* Upper branch */ - Vu[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); + Vu[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); // Qx move32(); - Vu[1] = L_add_sat( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); + Vu[1] = L_add_sat( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); // Qx move32(); - mem[3] = L_add_sat( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); + mem[3] = L_add_sat( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); // Qx move32(); - mem[1] = Vu[0]; + mem[1] = Vu[0]; // Qx move32(); - mem[2] = Vu[1]; + mem[2] = Vu[1]; // Qx move32(); - *out1++ = mem[3]; + *out1++ = mem[3]; // Qx move32(); /* Middle branch */ - Vm[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); + Vm[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); // Qx move32(); - Vm[1] = L_add_sat( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); + Vm[1] = L_add_sat( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); // Qx move32(); - mem[6] = L_add_sat( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); + mem[6] = L_add_sat( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); // Qx move32(); - mem[4] = Vm[0]; + mem[4] = Vm[0]; // Qx move32(); - mem[5] = Vm[1]; + mem[5] = Vm[1]; // Qx move32(); - *out1++ = mem[6]; + *out1++ = mem[6]; // Qx move32(); /* Lower branch */ - Vl[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); + Vl[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); // Qx move32(); - Vl[1] = L_add_sat( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); + Vl[1] = L_add_sat( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); // Qx move32(); - mem[9] = L_add_sat( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); + mem[9] = L_add_sat( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); // Qx move32(); - mem[0] = input[i]; + mem[0] = input[i]; // Qx move32(); - mem[7] = Vl[0]; + mem[7] = Vl[0]; // Qx move32(); - mem[8] = Vl[1]; + mem[8] = Vl[1]; // Qx move32(); - *out1++ = mem[9]; + *out1++ = mem[9]; // Qx move32(); } @@ -1195,15 +1197,16 @@ void interpolate_3_over_1_allpass_32( tmp16 = imult1616( len, 3 ); FOR( i = 0; i < tmp16; i++ ) { - mem_temp = out[i]; + mem_temp = out[i]; // Qx move32(); - out[i] = L_sub_sat( Mpy_32_16_1( L_add_sat( mem[12], mem[11] ), 18768 ), Mpy_32_16_1( L_add_sat( mem_temp, mem[10] ), 2424 ) ); + out[i] = L_sub_sat( Mpy_32_16_1( L_add_sat( mem[12], mem[11] ), 18768 ), Mpy_32_16_1( L_add_sat( mem_temp, mem[10] ), 2424 ) ); // Qx + // 0.572769 in Q15 -> 18768, 0.074005 in Q15 -> 2424 move32(); - mem[10] = mem[11]; + mem[10] = mem[11]; // Qx move32(); - mem[11] = mem[12]; + mem[11] = mem[12]; // Qx move32(); - mem[12] = mem_temp; + mem[12] = mem_temp; // Qx move32(); } diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 3cf2b645d..320682c6b 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -280,7 +280,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q test(); test(); test(); - if ( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) + IF( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) { #ifdef BASOP_NOGLOB num_den = shl_o( num_den, 1, &Overflow ); @@ -378,6 +378,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ * Find the resampling configuration *-------------------------------------------------------------------*/ *Q_new_inp = 0; + move16(); /* check if fin and fout are the same */ IF( EQ_32( fin, fout ) ) { @@ -385,6 +386,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Copy( sigIn_fx, sigOut_fx, lg ); *mem_decim_size = 0; *Q_new_inp = 0; + move16(); + move16(); return lg; } ELSE @@ -450,6 +453,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ mem_len = shl( filt_len, 1 ); *mem_decim_size = mem_len; + move16(); signal_fx = signal_tab_fx + 2 * L_FILT_MAX + sub( L_FRAME48k, add( mem_len, lg ) ); signal_ana_fx = signal_fx; mem_len_ana = mem_len; @@ -468,7 +472,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ IF( plus_sample_in > 0 ) { - autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); + autocorr_fx( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); t1 = L_Comp( r_fx_h[1], r_fx_l[1] ); /* R[1] in Q31 */ @@ -487,11 +491,11 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ mu_preemph_fx = extract_h( t0 ); /*r_fx[1] / r_fx[0]; */ mem_preemph_fx = signal_ana_fx[mem_len_ana + lg - LEN_WIN_SSS - 1]; move16(); - PREEMPH_FX( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); + PREEMPH_FX( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); /* Autocorrelations */ - autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, M, r_fx_h, r_fx_l, &Q_r, + autocorr_fx( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), M, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); /* Lag windowing */ @@ -505,7 +509,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR( i = 0; i < plus_sample_in; i++ ) { - sigPtr = signal_fx + lg + mem_len + i; + sigPtr = signal_fx + add( add( lg, mem_len ), i ); move16(); /*+i*/ L_tmp = syn_kern_16( 0, A_fx, sigPtr ); #ifdef BASOP_NOGLOB @@ -518,7 +522,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ } mem_preemph_fx = signal_fx[mem_len + lg - LEN_WIN_SSS - 1]; move16(); - deemph_fx( signal_fx + mem_len + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS + plus_sample_in, &mem_preemph_fx ); + deemph_fx( signal_fx + sub( add( mem_len, lg ), LEN_WIN_SSS ), mu_preemph_fx, add( LEN_WIN_SSS, plus_sample_in ), &mem_preemph_fx ); } /* interpolation */ @@ -543,6 +547,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ #else sigOut_fx[i] = round_fx( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); #endif + move16(); frac = add( frac, fracstep ); j = sub( fac_num, frac ); @@ -555,7 +560,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ /* rescaling */ test(); - IF( ( GT_16( fac_num, fac_den ) ) == ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) + IF( EQ_32( ( GT_16( fac_num, fac_den ) ), ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) ) { IF( LT_16( fac_num, fac_den ) ) { @@ -568,6 +573,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = round_fx( L_shl( L_mult( sigOut_fx[i], num_den ), 1 ) ); /*Q0*/ *Q_new_inp = -1; + move16(); + move16(); } } ELSE @@ -590,6 +597,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ move16(); } *Q_new_inp = -1; + move16(); } } ELSE @@ -603,6 +611,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], num_den ); /*Q-1*/ move16(); *Q_new_inp = -2; + move16(); } } ELSE @@ -612,6 +621,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = round_fx( L_mac( L_deposit_h( sigOut_fx[i] ), sigOut_fx[i], num_den ) ); /*Q0*/ *Q_new_inp = -1; + move16(); + move16(); } } } @@ -623,6 +634,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], 16384 ); move16(); /*Q-1*/ *Q_new_inp = -2; + move16(); } } /* update the filter memory */ @@ -893,11 +905,11 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output if ( LT_16( ctptr[10], 3 ) ) { - *sigOutptr++ = sigIn[add( i, 1 )]; + *sigOutptr++ = sigIn[i + 1]; move16(); } - FOR( k1 = ctptr[add( k, 1 )]; k1 < fk1; k1 += inc ) + FOR( k1 = ctptr[k + 1]; k1 < fk1; k1 += inc ) { cptr = &( cc[kk][0] ); uptr = &( cu[k1][0] ); @@ -912,7 +924,7 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output if ( EQ_16( ctptr[10], 1 ) ) { - *sigOutptr = sigIn[add( i, 2 )]; + *sigOutptr = sigIn[i + 2]; move16(); } } @@ -1558,7 +1570,7 @@ void interpolate_3_over_1_allpass_fx( Word16 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word16 *out1; Word16 mem_temp; - const Word16 *filt_coeff_fx = allpass_poles_3_ov_2; + const Word16 *filt_coeff_fx = allpass_poles_3_ov_2; // Q15 out1 = &out_fx[0]; diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index 748f2f564..3ff688d7b 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -151,6 +151,7 @@ void init_lvq_fx( move16(); WHILE( ( LT_16( j, MAX_NO_SCALES ) ) && ( no_lead_p_fx[i][j] > 0 ) ) { + test(); j++; } no_scales_p[i][0] = j; @@ -159,6 +160,7 @@ void init_lvq_fx( move16(); WHILE( ( LT_16( j, shl( MAX_NO_SCALES, 1 ) ) ) && ( no_lead_p_fx[i][j] > 0 ) ) { + test(); j++; } no_scales_p[i][1] = sub( j, MAX_NO_SCALES ); @@ -587,6 +589,7 @@ Word16 deindex_lvq_fx( /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } IF( scales_mslvq[1] ) @@ -596,6 +599,7 @@ Word16 deindex_lvq_fx( L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } } @@ -609,6 +613,7 @@ Word16 deindex_lvq_fx( L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } IF( scales_mslvq[1] ) @@ -618,6 +623,7 @@ Word16 deindex_lvq_fx( L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ x_lvq[i] = round_fx( L_tmp ); + move16(); } } } @@ -656,6 +662,7 @@ Word16 deindex_lvq_ivas_fx( } ELSE { + test(); IF( ( LT_16( mode, 6 ) ) || ( EQ_16( mode, 12 ) ) ) /* for NB */ { mode_glb = add( offset_lvq_modes_pred[mode], offset_in_lvq_mode_pred[mode][sub( no_bits, min_lat_bits_pred[mode] )] ); @@ -1002,6 +1009,7 @@ static void decode_leaders_fx( case 4: dim_loc = add( dim_loc, no_vals_ind[idx_lead][2] ); n_crt = no_vals_ind[idx_lead][2]; + move16(); index1 = divide_16_16_fx( index, C_VQ[dim_loc][n_crt], &index ); /* index1 = index/C_VQ_fx[dim_loc][n_crt]; */ /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]) ); */ /* index-= index1*C_VQ_fx[dim_loc][n_crt]; */ move16(); idx2c_fx( dim_loc, p, n_crt, index ); diff --git a/lib_com/nelp_fx.c b/lib_com/nelp_fx.c index a357b7455..b37d57093 100644 --- a/lib_com/nelp_fx.c +++ b/lib_com/nelp_fx.c @@ -127,7 +127,7 @@ Word16 dequantize_uvg_fx( L_tmp = L_shr_r( L_tmp, 11 ); /* Q16 */ frac = L_Extract_lc( L_tmp, &exp ); frac = extract_l( Pow2( 14, frac ) ); - G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB1[iG2[i]][k] ), exp - sc ) ); /* Q0 */ + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB1[iG2[i]][k] ), sub( exp, sc ) ) ); /* Q0 */ move16(); } ELSE IF( EQ_16( i, 1 ) ) @@ -136,7 +136,7 @@ Word16 dequantize_uvg_fx( L_tmp = L_shr_r( L_tmp, 11 ); /* Q16 */ frac = L_Extract_lc( L_tmp, &exp ); frac = extract_l( Pow2( 14, frac ) ); - G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB2[iG2[i]][k] ), exp - sc ) ); /* Q0 */ + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB2[iG2[i]][k] ), sub( exp, sc ) ) ); /* Q0 */ move16(); } } diff --git a/lib_com/parameter_bitmaping.c b/lib_com/parameter_bitmaping.c index ff7a9c5bd..50cf4886f 100644 --- a/lib_com/parameter_bitmaping.c +++ b/lib_com/parameter_bitmaping.c @@ -214,6 +214,7 @@ void GetParameters_fx( pSubStruct = param->GetParamValue( pParameter, index, &value ); #undef WMC_TOOL_SKIP /* If a function for encoding/decoding value is defined than it should take care of 0 */ + test(); IF( param->fZeroAllowed || ( param->EncodeValue != NULL ) ) { *( *pStream )++ = value; @@ -236,6 +237,8 @@ void GetParameters_fx( } move16(); #undef WMC_TOOL_SKIP + + test(); IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) ) { GetParameters_fx( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits ); diff --git a/lib_com/prot.h b/lib_com/prot.h index f895ef5f2..1f54c2b1b 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7818,13 +7818,13 @@ void tcx_arith_scale_envelope_ivas( ); void tcx_arith_render_envelope_ivas( - const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ - const Word16 L_frame, /* i : number of spectral lines */ - const Word16 L_spec, /* i : length of the coded spectrum */ - const Word16 preemph_fac, /* i : pre-emphasis factor */ - const Word16 gamma_w, /* i : A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor */ - Word32 env[] /* o : shaped signal envelope */ + const Word16 A_ind[], /* i : LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i : number of spectral lines Q0*/ + const Word16 L_spec, /* i : length of the coded spectrum Q0*/ + const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o : shaped signal envelope Q16*/ ); int16_t ari_encode_14bits_range( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d615e511b..de27c37c2 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -449,13 +449,13 @@ void logqnorm_fx( ); void logqnorm_2_fx( - const Word32 *env_fl, /* o : index */ + const Word32 *env_fl, /* o, Q10 : index */ const Word16 L, /* i : codebook length */ const Word16 n_env_band, /* i : sub-vector size */ const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, - Word16 *normqlg2, - const Word32 *thren /* i : quantization thresholds */ + Word16 *ynrm, /* o : norm indices Q0*/ + Word16 *normqlg2, /* o : quantized norm values Q0*/ + const Word32 *thren /* i, Q10 : quantization thresholds */ ); void calc_norm_fx( @@ -470,21 +470,21 @@ void calc_norm_fx( ); #ifdef IVAS_FLOAT_FIXED void calc_norm_ivas_fx( - const Word32 *x_fx, /* i : Input vector. */ - Word16 *norm, /* o : Quantization indices for norms */ - Word16 *normlg, /* o : Quantized norms in log2 */ + const Word32 *x_fx, /* i : Input vector.(Qin) */ + Word16 *norm, /* o : Quantization indices for norms Q0 */ + Word16 *normlg, /* o : Quantized norms in log2 Q0 */ const Word16 start_band, /* i : Indice of band to start coding */ const Word16 num_bands, /* i : Number of bands */ const Word16 *band_len, /* i : Length of bands */ const Word16 *band_start /* i : Start of bands */ ); void logqnorm_ivas_fx( - const Word32 *x_fx, /* i : coefficient vector */ + const Word32 *x_fx, /* i : coefficient vector Qq*/ const Word16 q, /* i : q of coefficient vector */ - Word16 *k_fx, /* o : index */ + Word16 *k_fx, /* o : index (Q0)*/ const Word16 L, /* i : codebook length */ const Word16 N, /* i : sub-vector size */ - const Word32 *thre_fxn /* i : quantization thresholds */ + const Word32 *thre_fxn /* i : quantization thresholds Q14*/ ); #endif /*========================================================================================================/ @@ -764,7 +764,8 @@ Word16 xsp_to_xsf( Word16 lsp ); Word16 xsf_to_xsp( - Word16 lsf ); + Word16 lsf /* Q2.56 */ +); void lsp_convolve_fx( Word32 x, Word32 *p1, Word32 *p2, Word16 len ); Word32 poscos_fx( Word16 w ); @@ -849,49 +850,50 @@ Word16 tcxlpc_get_cdk( ); void lsf_syn_mem_restore_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsf_new, /* o: quantized LSF vector */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ); #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_restore_ivas_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 btilt_code_fx, /* i: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ); #endif @@ -1091,9 +1093,9 @@ lpc_tools_fx.c void autocorr_fx( const Word16 x[], /* i : Input signal */ const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ - Word16 *Q_r, /* o : normailsation shift of r Q0 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16 *wind, /* i : Window used */ Word16 rev_flag, @@ -1101,12 +1103,12 @@ void autocorr_fx( ); void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ + const Word16 x[], /* i : Input signal Q(q_x) */ const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations (msb) */ + Word32 r[], /* o : Autocorrelations Q_r */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ - const Word16 *wind, /* i : Window used */ + const Word16 *wind, /* i : Window used Q15 */ Word16 rev_flag, const Word16 sym_flag /* i : symmetric window flag */ ); @@ -1121,29 +1123,29 @@ Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word3 Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem, Word16 k_max ); Word16 lev_dur_fx( - Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) */ - const Word32 *r_fx, /* i : vector of autocorrelations */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) Q(q_a)*/ + const Word32 *r_fx, /* i : vector of autocorrelations Q(q_r)*/ const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 epsP[], /* o : prediction error energy Q(q_r)*/ Word16 q_a, Word16 q_r ); -void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ); +void E_LPC_a_add_tilt( const Word16 *a /*Qa*/, Word16 *ap /*Qa*/, Word16 gamma /*Q15*/, Word16 m ); void E_LPC_int_lpc_tcx( const Word16 lsp_old[], /* i : LSPs from past frame (1Q14) */ const Word16 lsp_new[], /* i : LSPs from present frame (1Q14) */ Word16 a[] /* o : interpolated LP coefficients (4Q11) */ ); Word16 E_LPC_lsp_unweight( - /* const */ Word16 xsp_w[], /* (I): weighted xSP */ - Word16 xsp_uw[], /* (O): unweighted xSP */ - Word16 xsf_uw[], /* (O): unweighted xSF */ - Word16 inv_gamma, /* (I): inverse weighting factor */ - Word16 lpcorder /* (I): prediction order */ + /* const */ Word16 lsp_w[], /* (I): weighted xSP Q15 */ + Word16 lsp_uw[], /* (O): unweighted xSP Q15 */ + Word16 lsf_uw[], /* (O): unweighted LSF Q1*1.28 */ + Word16 inv_gamma, /* (I): inverse weighting factor Q14 */ + Word16 lpcorder /* (I): prediction order Q0 */ ); -Word32 E_LPC_schur( Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m ); -void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep ); +Word32 E_LPC_schur( Word32 r[] /*Qr*/, Word16 reflCoeff[] /*Q15*/, Word32 epsP[] /*Qr*/, const Word16 m ); +void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/, const Word16 *old_lsf /*15Q16*/, Word16 lpcOrder, Word8 lpcRep /*Q0*/ ); /*========================================================================================================/ @@ -4852,15 +4854,15 @@ void get_max_pulses_fx( const Word16 *k_sort, /* i : Indices for sorting by energy */ const Word16 *npulses, /* i : Pulses per sub band */ const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ + Word16 *inp_vector, /* i/o: Encoded shape vectors (int)Q0*/ + Word16 *maxpulse /* o : Maximum pulse height per band Q0*/ ); void fine_gain_dec_fx( Decoder_State *st, const Word16 *ord, /* i : Indices for energy order */ const Word16 num_sfm, /* i : Number of bands */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains Q12*/ ); // fine_gain_bits_fx.c @@ -4959,15 +4961,15 @@ void lsf_dec_bfi( const Word16 lsfBase[], /* i : base for differential lsf coding */ Word16 *mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ Word16 *mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) Q15*/ const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ Word16 L_frame, const Word16 last_good, /*!< i : last good received frame */ const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + Word16 *lsf_cng, /* Q2.56 */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise Q2.56*/ const Word16 Last_GSC_pit_band_idx, const Word16 Opt_AMR_WB, /* i : IO flag */ const Word8 tcxonly, @@ -5736,13 +5738,13 @@ void tcx_arith_scale_envelope( ); void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - const Word16 L_frame, /* i: number of spectral lines */ - const Word16 L_spec, - const Word16 preemph_fac, /* i: pre-emphasis factor */ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 L_spec, /* Q0 */ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ); @@ -8667,8 +8669,8 @@ void midlsf_dec( const Word16 safety_net ); Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], + const Word16 lsf_q_ind[], /*(14Q1*1.28)*/ + const Word16 means[], /*(14Q1*1.28)*/ const Word16 narrowband, const Word16 cdk ); @@ -9652,10 +9654,10 @@ void generate_masking_noise_dirac_ivas_fx( // modif_fs/c void interpolate_3_over_2_allpass_32( - const Word32 *input, /* i : input signal */ - const int16_t len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ + const Word32 *input, /* i : input signal Qx */ + const int16_t len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ); void interpolate_3_over_1_allpass_32( @@ -10431,12 +10433,12 @@ void msvq_dec_fx( Word16 exp ); void dec_FDCNG_MSVQ_stage1_fx( - Word16 j_full, /* i : index full range */ - Word16 n, /* i : dimension to generate */ - const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - Word32 *uq, /* o : synthesized stage1 vector */ - Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ + Word16 j_full, /* i : index full range */ + Word16 n, /* i : dimension to generate */ + const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis Q31 */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + Word32 *uq, /* o : synthesized stage1 vector Q20 */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ); void dctT2_N_apply_matrix_fx( @@ -10797,24 +10799,24 @@ Word16 ari_decode_14bits_sign_ivas( Tastat *s ); void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, + Encoder_State *st_fx, /* i: state structure */ + Word16 *btilt_code_fx, /* i: tilt code Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* o: */ + + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ); ivas_error config_acelp1_IVAS( diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 51c2c4643..ae5f0c2b1 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2800,7 +2800,7 @@ void perform_noise_estimation_dec_ivas_fx( } ELSE { - Word16 tmp = s_max( sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); + Word16 tmp = s_max( sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); hFdCngDec->msNoiseEst_exp = tmp; diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index de8d19e32..c31727f29 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -938,7 +938,7 @@ void ivas_hq_core_dec_fx( // fscaleFB = sr2fscale( st_fx->output_Fs ); // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; - mdctWindowLength = getMdctWindowLength( st_fx->fscale ); /* Q0 */ + mdctWindowLength = getMdctWindowLength_fx( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index fc2bef83c..633675002 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -332,7 +332,7 @@ void init_coder_ace_plus( int16_t L_subfr; /* Bitrate */ - st->tcxonly = getTcxonly_ivas( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); + st->tcxonly = getTcxonly_ivas_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); /* Core Sampling Rate */ st->sr_core = getCoreSamplerateMode2_flt( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 89ae59101..46fc42291 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -839,7 +839,7 @@ ivas_error ivas_cpe_enc( { int32_t internal_Fs; - internal_Fs = getTcxonly_ivas( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); + internal_Fs = getTcxonly_ivas_fx( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); /* iDFT at input sampling rate */ #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 454b2305f..2ad739323 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -104,7 +104,11 @@ ivas_error ivas_spar_enc_open( hSpar->spar_reconfig_flag = 0; input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#ifdef IVAS_FLOAT_FIXED + nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); +#else nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); +#endif // IVAS_FLOAT_FIXED assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -1381,7 +1385,7 @@ static ivas_error ivas_spar_enc_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 mixer_q = 31; Word16 prior_mixer_q = 31; - Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + Word32 num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 1bfa16eaf..b2413c928 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -164,7 +164,11 @@ ivas_error ivas_spar_md_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } +#ifdef IVAS_FLOAT_FIXED + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); +#else num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); +#endif // IVAS_FLOAT_FIXED if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { -- GitLab From 0370eaa3a62bf29444a14aeb896f44203cdd3157 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:42:47 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/lsf_tools.c | 10 ++++----- lib_com/lsf_tools_fx.c | 46 +++++++++++++++++++++--------------------- lib_com/modif_fs.c | 2 +- lib_com/modif_fs_fx.c | 2 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index d051a54c7..b2be1b043 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -2119,8 +2119,8 @@ void dec_FDCNG_MSVQ_stage1_fx( /* Word8 column variable Qx storage*/ - cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ - cbpW8 += imult1616( j, cdk1_ivas_cols_per_segment[segm_ind] ); /* adaptive ptr init */ + cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ + cbpW8 += imult1616( j, cdk1_ivas_cols_per_segment[segm_ind] ); /* adaptive ptr init */ dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; FOR( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ ) @@ -2151,7 +2151,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < n; i++ ) { idct_vec_fx[i] = Mpy_32_32( idct_vec_fx[i], 56410112 ); /* norm + 31 - 31 = norm*/ - // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 + // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 move32(); } /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , @@ -2360,7 +2360,7 @@ void msvq_dec_fx( { FOR( j = 0; j < n; ++j ) { - uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 + uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 // 2 * 1.28 in Q13 -> 20971 move16(); } @@ -2775,7 +2775,7 @@ void dctT2_N_apply_matrix_fx( /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag ) ] ); /* ptr indexing */ + pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag )] ); /* ptr indexing */ PTR_INIT( 1 ); #undef WMC_TOOL_SKIP FOR( j = 0; j < dim_in; j++ ) diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index d0dcc289e..d3694637e 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -2816,28 +2816,28 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( /*=======================================================================*/ void lsf_syn_mem_backup_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 *btilt_code_fx, /* i: Q15 */ - Word32 *gc_threshold_fx, /* i: Q16 */ - Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 *next_force_sf_bck_fx,/* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsf_new, /* i: quantized LSF vector Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ - Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ - Word16 *mem_syn_bck, /* i: synthesis filter memory q */ - Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ - Word16 *streaklimit, /* i:LSF quantizer Q15 */ - Word16 *pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 *btilt_code_fx, /* i: Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3113,7 +3113,7 @@ void lsf_syn_mem_restore_fx( move16(); move32(); move16(); - hLPDmem->tilt_code = btilt_code_fx; // Q15 + hLPDmem->tilt_code = btilt_code_fx; // Q15 hLPDmem->gc_threshold = gc_threshold_fx; // Q16 move16(); move32(); diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 42241bce1..5bc57cc4b 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -774,7 +774,7 @@ void Decimate_allpass_steep_fx32( move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); //Qx + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 320682c6b..b53bb9d1c 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -597,7 +597,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ move16(); } *Q_new_inp = -1; - move16(); + move16(); } } ELSE -- GitLab