From 9a457d33d794e3eea8da3f175bea67297338740e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 28 Apr 2024 10:41:32 +0530 Subject: [PATCH] Few dirac_rend functions converted to fixed point, cleanup of flt code [x] computeIntensityVector_dec, computeDirectionAngles, computeDiffuseness and rotateAziEle_DirAC integrated. [x] Few headtrack functions converted to fixed point. [x] Core coder and CPE cleanup. --- lib_com/basop32.h | 1 + lib_com/basop_util.c | 98 ++ lib_com/basop_util.h | 4 + lib_com/float_to_fix_ops.c | 6 +- lib_com/ivas_dirac_com.c | 160 ++++ lib_com/ivas_prot.h | 11 + lib_com/ivas_stereo_ica_com_fx.c | 93 +- lib_com/prot_fx2.h | 4 +- lib_dec/acelp_core_dec_ivas_fx.c | 16 +- lib_dec/fd_cng_dec.c | 46 +- lib_dec/ivas_core_dec.c | 94 +- lib_dec/ivas_cpe_dec_fx.c | 896 ++++++++----------- lib_dec/ivas_dirac_dec.c | 116 ++- lib_dec/ivas_masa_dec.c | 2 +- lib_dec/ivas_mct_dec.c | 96 -- lib_dec/ivas_stat_dec.h | 11 +- lib_dec/ivas_stereo_cng_dec.c | 30 +- lib_dec/ivas_stereo_ica_dec.c | 13 +- lib_dec/ivas_stereo_switching_dec.c | 487 ++++------ lib_dec/ivas_stereo_td_dec.c | 3 +- lib_dec/stat_dec.h | 2 +- lib_dec/tonalMDCTconcealment.c | 2 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 506 ++++++++++- lib_rend/ivas_dirac_rend.c | 170 +++- lib_rend/ivas_prot_rend.h | 25 + lib_rend/ivas_rotation.c | 11 + lib_rend/ivas_stat_rend.h | 14 +- 27 files changed, 1741 insertions(+), 1176 deletions(-) diff --git a/lib_com/basop32.h b/lib_com/basop32.h index b0ad2a428..372348816 100644 --- a/lib_com/basop32.h +++ b/lib_com/basop32.h @@ -239,6 +239,7 @@ Word32 L_abs( Word32 L_var1 ); /* Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry ); /* Long saturation, 4 */ Word16 norm_s( Word16 var1 ); /* Short norm, 1 */ Word16 div_s( Word16 var1, Word16 var2 ); /* Short division, 18 */ +Word32 div_w(Word32 L_num, Word32 L_den); Word16 norm_l( Word32 L_var1 ); /* Long norm, 1 */ #endif /* BASOP_NOGLOB */ diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 40a3c3baa..2760f4feb 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -933,6 +933,104 @@ Word16 BASOP_Util_Divide3232_uu_1616_Scale(Word32 x, Word32 y, Word16 *s) return (z); } +Word32 div_w( Word32 L_num, Word32 L_den ) +{ + Word32 L_var_out = (Word32) 0; + Word16 iteration; + + + if ( L_den == (Word32) 0 ) + { + /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */ + return ( 0 ); + } + + if ( ( L_num < (Word32) 0 ) || ( L_den < (Word32) 0 ) ) + { + /* printf("Division Error in div_l, Fatal error in "); printStack(); */ + return ( 0 ); + } + Word64 W_num, W_den; + W_num = W_deposit32_h( L_num ); + W_den = W_deposit32_h( L_den ); + + if ( W_num >= W_den ) + { + return MAX_32; + } + else + { + W_num = W_shr( W_num, (Word16) 1 ); + W_den = W_shr( W_den, (Word16) 1 ); + + for ( iteration = (Word16) 0; iteration < (Word16) 31; iteration++ ) + { + L_var_out = L_shl( L_var_out, (Word16) 1 ); + W_num = W_shl( W_num, (Word16) 1 ); + + if ( W_num >= W_den ) + { + W_num = W_sub( W_num, W_den ); + L_var_out = L_add( L_var_out, (Word32) 1 ); + } + } + + return L_var_out; + } +} + +Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s ) +{ + Word32 z; + Word16 sx; + Word16 sy; + Word32 sign; + + /* assert (x >= (Word32)0); */ + assert( y != (Word32) 0 ); + + sign = 0; + move16(); + + IF( x < 0 ) + { + x = L_negate( x ); + sign = L_xor( sign, 1 ); + } + + IF( y < 0 ) + { + y = L_negate( y ); + sign = L_xor( sign, 1 ); + } + + IF( x == (Word32) 0 ) + { + *s = 0; + return ( (Word32) 0 ); + } + + sx = norm_l( x ); + x = L_shl( x, sx ); + x = L_shr( x, 1 ); + move16(); + *s = sub( 1, sx ); + + sy = norm_l( y ); + y = L_shl( y, sy ); + move16(); + *s = add( *s, sy ); + + z = div_w( x, y ); + + if ( sign != 0 ) + { + z = L_negate( z ); + } + + return z; +} + Word16 BASOP_Util_Divide3232_Scale(Word32 x, Word32 y, Word16 *s) { Word16 z; diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index 61b170af3..988fb937c 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -325,6 +325,10 @@ Word16 BASOP_Util_Divide3232_Scale(Word32 x, /*!< i : Numerator*/ Word32 y, /*!< i : Denominator*/ Word16 *s); /*!< o : Additional scalefactor difference*/ +Word32 BASOP_Util_Divide3232_Scale_cadence(Word32 x, /*!< i : Numerator*/ + Word32 y, /*!< i : Denominator*/ + Word16 *s); /*!< o : Additional scalefactor difference*/ + /************************************************************************/ /*! diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 4dcfa932c..ebc877ac0 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -85,11 +85,11 @@ float fixedToFloat_32( Word32 number, Word16 Q ) { if ( Q > 0 ) { - val = (float) ( ( number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) ); + val = ( ( (float) number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) ); } else { - val = (float) ( number * ( 1 << ( -Q - 31 ) ) * (unsigned int)MIN_32 ); + val = ( (float) number * ( 1 << ( -Q - 31 ) ) * (unsigned int) MIN_32 ); } } else @@ -111,7 +111,7 @@ Word32 floatToFixed_32( float number, Word16 Q ) } else { - val = ( number / ( 1 << ( -Q - 31 ) ) ) / (unsigned int)MIN_32; + val = ( number / ( 1 << ( -Q - 31 ) ) ) / (unsigned int) MIN_32; } if ( val >= 0.0f ) { diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index ec8c3e400..180e27ddb 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -1122,6 +1122,166 @@ void computeDiffuseness_fx( #endif + +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * computeDiffuseness() + * + * + *------------------------------------------------------------------------*/ + +void computeDiffuseness_fixed( + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], + const Word32 *buffer_energy, + const Word16 num_freq_bands, + Word32 *diffuseness, + Word16 *q_factor_intensity, + Word16 *q_factor_energy, + Word16 *q_diffuseness /*Ouput Q*/ +) +{ + Word32 intensity_slow[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX]; + Word32 intensity_slow_abs[CLDFB_NO_CHANNELS_MAX]; + Word32 energy_slow[CLDFB_NO_CHANNELS_MAX]; + Word16 i, j, k; + Word32 tmp = 0; + Word32 *p_tmp; + const Word32 *p_tmp_c; + Word16 min_q_shift1, min_q_shift2, exp1, exp2, q_tmp; + Word16 q_ene, q_intensity, q_intensity_slow; + + /* Compute Intensity slow and energy slow buffer_intensity and buffer_energy */ + + set_zero_fx( intensity_slow, i_mult( DIRAC_NUM_DIMS, CLDFB_NO_CHANNELS_MAX ) ); + set_zero_fx( intensity_slow_abs, CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( energy_slow, CLDFB_NO_CHANNELS_MAX ); + + /* Calculate max possible shift for the buffer buffer_energy and buffer_intensity */ + min_q_shift1 = Q31; + move16(); + min_q_shift1 = s_min( min_q_shift1, getScaleFactor32( buffer_energy, i_mult( DIRAC_NO_COL_AVG_DIFF, num_freq_bands ) ) ); + min_q_shift1 = sub( min_q_shift1, find_guarded_bits_fx( DIRAC_NO_COL_AVG_DIFF ) ); + + min_q_shift2 = Q31; + move16(); + min_q_shift2 = s_min( min_q_shift2, getScaleFactor32( buffer_energy, i_mult( DIRAC_NUM_DIMS, i_mult( DIRAC_NO_COL_AVG_DIFF, num_freq_bands ) ) ) ); + min_q_shift2 = find_guarded_bits_fx( DIRAC_NO_COL_AVG_DIFF ); + + q_ene = add( q_factor_energy[0], min_q_shift1 ); + move16(); + q_intensity = sub( q_factor_intensity[0], min_q_shift2 ); + move16(); + + FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) + { + /* Energy slow */ + p_tmp_c = buffer_energy + i_mult( i, num_freq_bands ); + + q_tmp = add( q_factor_energy[i], min_q_shift1 ); + FOR( k = 0; k < num_freq_bands; k++ ) + { + tmp = L_shl( p_tmp_c[k], min_q_shift1 ); + IF( LT_16( q_tmp, q_ene ) ) + { + energy_slow[k] = L_add( L_shr( energy_slow[k], sub( q_ene, q_tmp ) ), tmp ); + move32(); + } + ELSE + { + energy_slow[k] = L_add( energy_slow[k], L_shr( tmp, sub( q_tmp, q_ene ) ) ); + move32(); + } + } + q_ene = s_min( q_ene, q_tmp ); + + /* Intensity slow */ + q_tmp = sub( q_factor_intensity[i], min_q_shift2 ); + FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) + { + p_tmp = buffer_intensity[j][i]; + FOR( k = 0; k < num_freq_bands; k++ ) + { + tmp = L_shr( p_tmp[k], min_q_shift2 ); + IF( LT_16( q_intensity, q_tmp ) ) + { + intensity_slow[add( i_mult( j, num_freq_bands ), k )] = L_add( intensity_slow[add( i_mult( j, num_freq_bands ), k )], L_shr( tmp, sub( q_tmp, q_intensity ) ) ); + move32(); + } + ELSE + { + intensity_slow[add( i_mult( j, num_freq_bands ), k )] = L_add( L_shr( intensity_slow[add( i_mult( j, num_freq_bands ), k )], sub( q_intensity, q_tmp ) ), tmp ); + move32(); + } + } + } + q_intensity = s_min( q_intensity, q_tmp ); + } + + min_q_shift1 = getScaleFactor32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ) ); + min_q_shift1 = sub( min_q_shift1, idiv1616( add( find_guarded_bits_fx( DIRAC_NUM_DIMS ), 1 ), 2 ) ); + scale_sig32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ), min_q_shift1 ); + q_intensity = add( q_intensity, min_q_shift1 ); + + /* intensity_slow.^2 + intensity_slow_abs*/ + FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) + { + p_tmp = intensity_slow + i_mult( j, num_freq_bands ); + + FOR( k = 0; k < num_freq_bands; k++ ) + { + p_tmp[k] = Mpy_32_32( p_tmp[k], p_tmp[k] ); + move32(); + intensity_slow_abs[k] = L_add( intensity_slow_abs[k], p_tmp[k] ); + move32(); + } + } + q_intensity_slow = sub( add( q_intensity, q_intensity ), 31 ); + + /* Compute Diffuseness */ + p_tmp = intensity_slow_abs; + exp2 = 0; + move16(); + FOR( i = 0; i < num_freq_bands; ++i ) + { + exp1 = sub( 31, q_intensity_slow ); + tmp = Sqrt32( p_tmp[i], &exp1 ); + + tmp = BASOP_Util_Divide3232_Scale_cadence( tmp, L_add( energy_slow[i], EPSILLON_FX ), &exp2 ); + q_tmp = sub( 31, exp2 ) + sub( sub( 31, exp1 ), q_ene ); + + IF( LT_16( q_tmp, Q30 ) ) + { + tmp = L_sub( L_shr( ONE_IN_Q30, sub( Q30, q_tmp ) ), tmp ); + } + ELSE + { + tmp = L_sub( ONE_IN_Q30, L_shr( tmp, sub( q_tmp, Q30 ) ) ); + q_tmp = Q30; + } + + IF( GE_32( tmp, L_shl( 1, q_tmp ) ) ) + { + diffuseness[i] = ONE_IN_Q30; + move32(); + } + ELSE IF( LE_32( tmp, 0 ) ) + { + diffuseness[i] = 0; + move32(); + } + ELSE + { + diffuseness[i] = L_shl( tmp, sub( Q30, q_tmp ) ); + move32(); + } + } + *q_diffuseness = Q30; + move16(); + + return; +} +#endif + /*------------------------------------------------------------------------- * computeDiffuseness() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 0f3a2a911..e185ffa7e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4443,6 +4443,17 @@ void computeDiffuseness_fx( ); #endif +#ifdef IVAS_FLOAT_FIXED +void computeDiffuseness_fixed( + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], + const Word32 *buffer_energy, + const Word16 num_freq_bands, + Word32 *diffuseness , + Word16 *q_factor_intensity, + Word16 *q_factor_energy, + Word16 *q_diffuseness +); +#endif void ivas_dirac_dec_get_response( const int16_t azimuth, const int16_t elevation, diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index e24e688a1..deee92b71 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -130,16 +130,18 @@ static void interpTargetChannel_fx( Word32 spread_factor2_fx; Word64 tempD1_fx, tempD2_fx; - d = -( currShift - prevShift ); - signShift = ( d >= 0 ) ? ( 1 ) : ( -1 ); + d = sub( prevShift, currShift ); + signShift = GE_16( d, 0 ) ? ( 1 ) : ( -1 ); + move16(); - IF( d == 0 ) + IF( EQ_16( d, 0 ) ) { /* this can happen in DFT->TD switching */ return; } N = L_shift_adapt; + move16(); Word32 *table_pointer = NULL; Word32 *inv_table_pointer = NULL; Word32 *table_D1_pointer = NULL; @@ -149,29 +151,31 @@ static void interpTargetChannel_fx( table_pointer = table_596; inv_table_pointer = inv_table_596; table_D1_pointer = tableD1_596; - break; + BREAK; case 298: table_pointer = table_298; inv_table_pointer = inv_table_298; table_D1_pointer = tableD1_298; - break; + BREAK; case 290: table_pointer = table_290; inv_table_pointer = inv_table_290; table_D1_pointer = tableD1_290; - break; + BREAK; case 145: table_pointer = table_145; inv_table_pointer = inv_table_145; table_D1_pointer = tableD1_145; - break; + BREAK; default: assert( 0 ); } factor_fx = table_pointer[L_abs( d )]; + move32(); interp_factor2_fx = L_shr( factor_fx, 1 ); spread_factor2_fx = inv_table_pointer[L_abs( d )]; + move32(); /* start from (target - N - d + 1) : (extra lag = step1) :to: (target - 1 - d) : (extra lag = d) */ /* sinc interp by a factor of 2 */ @@ -185,20 +189,23 @@ static void interpTargetChannel_fx( IF( i & 0x1 ) { ptr2_fx[i] = 0; + move32(); /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */ /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */ - lim1 = add(shr((i - SINC_ORDER1), 1), 1); + lim1 = add( shr( ( i - SINC_ORDER1 ), 1 ), 1 ); - lim2 = shr((i + SINC_ORDER1), 1); + lim2 = shr( ( i + SINC_ORDER1 ), 1 ); FOR( j = lim1; j <= lim2; j++ ) { ptr2_fx[i] = L_add( Mpy_32_32( win_fx[j * INTERP_FACTOR1 - i], ptr1_fx[j] ), ptr2_fx[i] ); + move32(); } } ELSE { ptr2_fx[i] = ptr1_fx[shr( i, 1 )]; + move32(); } } @@ -206,15 +213,16 @@ static void interpTargetChannel_fx( ptr1_fx = ptr2_fx; ptr2_fx = tempBuff2_fx; - ; tempD1_fx = table_D1_pointer[L_abs( d )]; + move64(); tempD2_fx = 3 * table_D1_pointer[L_abs( d )]; + move64(); - tempF1_fx = L_sub( d * factor_fx, ( signShift == 1 ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ); + tempF1_fx = L_sub( d * factor_fx, ( EQ_16( signShift, 1 ) ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ); FOR( k = 0; k < N - 1; k++ ) { Word32 local = ( ( (Word64) tempF1_fx * spread_factor2_fx ) >> 31 ) - ONE_IN_Q12; - Word32 sign_local = local > 0 ? 1 : -1; + Word32 sign_local = GT_32( local, 0 ) ? 1 : -1; Word32 local_int = (Word32) W_shr( W_abs( local ), 12 ); Word32 res_a1, res_a2, res_a3; Word32 res_b1, res_b2, res_b3; @@ -233,48 +241,56 @@ static void interpTargetChannel_fx( } y_fx[0] = ptr1_fx[lim1]; + move32(); y_fx[1] = ptr1_fx[lim1 + 1]; + move32(); y_fx[2] = ptr1_fx[lim1 + 2]; + move32(); y_fx[3] = ptr1_fx[lim1 + 3]; + move32(); x_fx[0] = lim1 * interp_factor2_fx; + move32(); x_fx[1] = L_add( x_fx[0], interp_factor2_fx ); + move32(); x_fx[2] = L_add( x_fx[1], interp_factor2_fx ); + move32(); x_fx[3] = L_add( x_fx[2], interp_factor2_fx ); + move32(); - res_a1 = ( tempF1_fx - x_fx[0] ); - res_a2 = ( tempF1_fx - x_fx[1] ); - res_a3 = ( tempF1_fx - x_fx[2] ); + res_a1 = L_sub( tempF1_fx, x_fx[0] ); + res_a2 = L_sub( tempF1_fx, x_fx[1] ); + res_a3 = L_sub( tempF1_fx, x_fx[2] ); res_a = ( ( (Word64) res_a1 * res_a2 ) >> 12 ) * res_a3; res_a = ( y_fx[3] * ( res_a >> 16 ) ); - res_b1 = ( tempF1_fx - x_fx[1] ); - res_b2 = ( tempF1_fx - x_fx[2] ); - res_b3 = ( tempF1_fx - x_fx[3] ); + res_b1 = L_sub( tempF1_fx, x_fx[1] ); + res_b2 = L_sub( tempF1_fx, x_fx[2] ); + res_b3 = L_sub( tempF1_fx, x_fx[3] ); res_b = ( ( (Word64) res_b1 * res_b2 ) >> 12 ) * res_b3; res_b = ( y_fx[0] * ( res_b >> 16 ) ); - res_c1 = ( tempF1_fx - x_fx[0] ); - res_c2 = ( tempF1_fx - x_fx[2] ); - res_c3 = ( tempF1_fx - x_fx[3] ); + res_c1 = L_sub( tempF1_fx, x_fx[0] ); + res_c2 = L_sub( tempF1_fx, x_fx[2] ); + res_c3 = L_sub( tempF1_fx, x_fx[3] ); res_c = ( ( (Word64) res_c1 * res_c2 ) >> 12 ) * res_c3; res_c = ( y_fx[1] * ( res_c >> 16 ) ); - res_d1 = ( tempF1_fx - x_fx[0] ); - res_d2 = ( tempF1_fx - x_fx[1] ); - res_d3 = ( tempF1_fx - x_fx[3] ); + res_d1 = L_sub( tempF1_fx, x_fx[0] ); + res_d2 = L_sub( tempF1_fx, x_fx[1] ); + res_d3 = L_sub( tempF1_fx, x_fx[3] ); res_d = ( ( (Word64) res_d1 * res_d2 ) >> 12 ) * res_d3; res_d = ( y_fx[2] * ( res_d >> 16 ) ); - tempa = res_a - res_b; - tempb = res_c - res_d; + tempa = W_sub( res_a, res_b ); + tempb = W_sub( res_c, res_d ); mult_a_D1 = ( tempD1_fx * ( tempa >> 14 ) ) >> 15; mult_b_D2 = ( tempD2_fx * ( tempb >> 14 ) ) >> 15; ptr2_fx[k] = (Word32) ( ( mult_a_D1 + mult_b_D2 ) >> 14 ); // 38-14 - tempF1_fx = (Word32) W_add( tempF1_fx, L_sub( factor_fx, ( signShift == 1 ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ) ); + tempF1_fx = (Word32) W_add( tempF1_fx, L_sub( factor_fx, ( EQ_16( signShift, 1 ) ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ) ); } ptr1_fx = target_fx; Copy32( ptr2_fx, ptr1_fx, N - 1 ); @@ -302,35 +318,42 @@ static void targetCh_AlignStereoDFT_fx( Word32 fadeOutBuff_fx[L_SHIFT_ADAPT_MAX]; Word32 fadeInBuff_fx[L_SHIFT_ADAPT_MAX]; - d = -( currShift - prevShift ); + d = sub( prevShift, currShift ); Copy32( target_fx + d, fadeOutBuff_fx, L_shift_adapt ); Copy32( target_fx, fadeInBuff_fx, L_shift_adapt ); - IF( L_shift_adapt > 0 ) + IF( GT_16( L_shift_adapt, 0 ) ) { alpha_fx = 0; + move32(); SWITCH( L_shift_adapt ) { case 596: winSlope_fx = 3603160; - break; + move32(); + BREAK; case 298: winSlope_fx = 7206320; - break; + move32(); + BREAK; case 290: winSlope_fx = 7405116; - break; + move32(); + BREAK; case 145: winSlope_fx = 14810232; - break; + move32(); + BREAK; default: winSlope_fx = ONE_IN_Q31; - break; + move32(); + BREAK; } FOR( i = 0; i < L_shift_adapt; i++ ) { target_fx[i] = L_add( Mpy_32_32( alpha_fx, fadeInBuff_fx[i] ), Mpy_32_32( L_sub( ONE_IN_Q31, alpha_fx ), fadeOutBuff_fx[i] ) ); + move32(); alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); } @@ -359,7 +382,7 @@ void adjustTargetSignal_fx( { /* inter-frame shift variation and target shifting */ - IF( method == 0 ) + IF( EQ_16( method, 0 ) ) { interpTargetChannel_fx( target_fx, prevShift, currShift, L_shift_adapt ); } diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 9e8a2ee18..2099979a9 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -9343,8 +9343,8 @@ void ivas_bw_switching_pre_proc_fx( #ifdef IVAS_FLOAT_FIXED /* float2fix and fix2float utilities (to be removed) */ -void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng); -void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng); +void acelp_decoder_state_float2fix(Decoder_State *st); +void acelp_decoder_state_fix2float(Decoder_State *st); #endif uint32_t mvl2s_r( diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 0c8238c04..1940591db 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -2603,11 +2603,11 @@ ivas_error acelp_core_dec_ivas_fx( return error; } -void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) { +void acelp_decoder_state_float2fix(Decoder_State *st/*, STEREO_CNG_DEC_HANDLE hStereoCng*/) { - if (hStereoCng) { - floatToFixed_arr(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22_fx, st->Q_syn, FFTLEN); - } + //if (hStereoCng) { + // floatToFixed_arr(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22_fx, st->Q_syn, FFTLEN); + //} /* CLDFB */ Word16 old_len_ana, old_len_bpf; @@ -2671,13 +2671,13 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte } } -void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) { +void acelp_decoder_state_fix2float(Decoder_State *st/*, STEREO_CNG_DEC_HANDLE hStereoCng*/) { st->prev_Q_syn = st->Q_syn; - if (hStereoCng) { - fixedToFloat_arr(hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22, st->Q_syn, FFTLEN); - } + //if (hStereoCng) { + // fixedToFloat_arr(hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22, st->Q_syn, FFTLEN); + //} /* CLDFB */ Word16 new_len; diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 48101b320..89f39045a 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -2124,28 +2124,12 @@ void generate_masking_noise_ivas_fx( IF( secondary ) { // SynthesisSTFT_flt(fftBuffer, maskingNoise, hStereoCng->olapBufferSynth22, hFdCngCom->olapWinSyn_flt, 0, hFdCngCom, element_mode, nchan_out); - FOR( i = 0; i < hFdCngCom->fftlen; i++ ) - { - hStereoCng->olapBufferSynth22_32fx[i] = float_to_fix( hStereoCng->olapBufferSynth22[i], *exp_out ); - } SynthesisSTFT_fx( fftBuffer_fx, *exp_out, maskingNoise_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); - FOR( i = 0; i < hFdCngCom->fftlen; i++ ) - { - hStereoCng->olapBufferSynth22[i] = fix_to_float( hStereoCng->olapBufferSynth22_32fx[i], *exp_out ); - } } ELSE { // SynthesisSTFT_flt(fftBuffer, maskingNoise, hFdCngCom->olapBufferSynth2_flt, hFdCngCom->olapWinSyn_flt, 0, hFdCngCom, element_mode, nchan_out); - //FOR( i = 0; i < hFdCngCom->fftlen; i++ ) - //{ - // hFdCngCom->olapBufferSynth2_fx[i] = float_to_fix( hFdCngCom->olapBufferSynth2_flt[i], *exp_out ); - //} SynthesisSTFT_fx( fftBuffer_fx, *exp_out, maskingNoise_fx, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); - //FOR( i = 0; i < hFdCngCom->fftlen; i++ ) - //{ - // hFdCngCom->olapBufferSynth2_flt[i] = fix_to_float( hFdCngCom->olapBufferSynth2_fx[i], *exp_out ); - //} } *exp_out = *exp_out - 9; @@ -2447,18 +2431,17 @@ void generate_stereo_masking_noise_16fx( hFdCngCom = st->hFdCngDec->hFdCngCom; // mvr2r(hStereoCng->olapBufferSynth22, Ns, hFdCngCom->frameSize / 2); // mvr2r(hFdCngCom->olapBufferSynth2_flt, Np, hFdCngCom->frameSize / 2); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, hFdCngCom->frameSize / 2, Q6 - st->Q_syn ); Copy32(hFdCngCom->olapBufferSynth2_fx, Np_fx, hFdCngCom->frameSize / 2); - for (i = 0; i < hFdCngCom->frameSize / 2; i++) - { - Ns_fx[i] = float_to_fix(hStereoCng->olapBufferSynth22[i], Q6); - //Np_fx[i] = float_to_fix(hFdCngCom->olapBufferSynth2_flt[i], Q6); - } + set_l(&Np_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2); set_l(&Ns_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2); IF(!fadeOut) { // generate_masking_noise_flt(N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, -(st->Q_syn - 15) ); + generate_masking_noise_ivas_fx(N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); // N1_fx Q6 /* Generate masking noise for secondary channel */ IF(flag_sec_CNA) @@ -2466,7 +2449,7 @@ void generate_stereo_masking_noise_16fx( // generate_masking_noise_flt(N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out); generate_masking_noise_ivas_fx(N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out); // N2_fx Q6 // gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT; - gamma_fx = float_to_fix(hStereoCng->c_PS_LT * hStereoCng->c_PS_LT, Q30); + gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); // scale = 1.0f; scale_fx = ONE_IN_Q30; // if (gamma < 0.9f) @@ -2499,7 +2482,7 @@ void generate_stereo_masking_noise_16fx( Np_fx[i] = L_add(Np_fx[i], Mpy_32_32(scale_fx, L_shl(L_add(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1))); // Q6 Word32 add2 = Mpy_32_32(scale_fx, L_shl(L_sub(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6 - if (hStereoCng->c_PS_LT < 0.0f) + if (hStereoCng->c_PS_LT_fx < 0) { add2 = L_negate(add2); } @@ -2511,7 +2494,7 @@ void generate_stereo_masking_noise_16fx( // Ns[i] = scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]); Np_fx[i] = Mpy_32_32(scale_fx, L_shl(L_add(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6 Ns_fx[i] = Mpy_32_32(scale_fx, L_shl(L_sub(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6 - IF(hStereoCng->c_PS_LT < 0.0f) + IF(hStereoCng->c_PS_LT_fx < 0) { Ns_fx[i] = L_negate(Ns_fx[i]); } @@ -2553,6 +2536,9 @@ void generate_stereo_masking_noise_16fx( hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] ), Q6 ); // Q_olap } } + + Copy_Scale_sig_32_16(hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, (st->Q_syn - 15)); + } else { @@ -2562,10 +2548,8 @@ void generate_stereo_masking_noise_16fx( if (flag_sec_CNA) { // mvr2r(Ns, hStereoCng->maskingNoiseS, hFdCngCom->frameSize); - for (i = 0; i < hFdCngCom->frameSize; i++) - { - hStereoCng->maskingNoiseS[i] = fix_to_float(Ns_fx[i], Q6); - } + //Copy(Ns_fx, hStereoCng->maskingNoiseS_fx, hFdCngCom->frameSize); // Q6 + Copy_Scale_sig_32_16(Ns_fx, hStereoCng->maskingNoiseS_fx, hFdCngCom->frameSize, 0); // Q6 hStereoCng->enableSecCNA = 1; } else @@ -2591,17 +2575,17 @@ void generate_stereo_masking_noise_16fx( //float scale = ( ( hStereoTD->prevSP_ratio * ( *hStereoCng->frameSize / 4 - (float) i ) + SP_ratio * (float) i ) / ( *hStereoCng->frameSize / 4 ) ); Word16 scale_fx_tmp = (Word16)(((Word32)prevSP_ratio_fx * (*hStereoCng->frameSize / 4 - i) + SP_ratio_fx * i) / (*hStereoCng->frameSize / 4)); //Q15 //syn[i] += scale * hStereoCng->maskingNoiseS[i]; - syn[i] = add(syn[i], mult(scale_fx_tmp, float_to_fix16(hStereoCng->maskingNoiseS[i], Q15))); + syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); } for (; i < *hStereoCng->frameSize / 2; i++) { //syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; - syn[i] = add(syn[i], mult(SP_ratio_fx, float_to_fix16(hStereoCng->maskingNoiseS[i], Q15))); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); } for (; i < *hStereoCng->frameSize; i++) { //syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; - syn[i] = add(syn[i], mult(SP_ratio_fx, float_to_fix16(hStereoCng->maskingNoiseS[i], Q15))); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); } hStereoTD->prevSP_ratio = hStereoTD->SP_ratio_LT; } diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index a14984704..b23198202 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -224,11 +224,6 @@ ivas_error ivas_core_dec( // } // } // -// if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) -// { -// floatToFixed_arrL( hCPE->input_mem_LB[0], hCPE->input_mem_LB_fx[0], 11, STEREO_DFT32MS_OVL_16k ); -// } -// // IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) // { // FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) @@ -271,11 +266,8 @@ ivas_error ivas_core_dec( last_element_mode = hCPE->last_element_mode; hStereoICBWE = hCPE->hStereoICBWE; hStereoTD = hCPE->hStereoTD; - //p_output_mem = hCPE->output_mem[1]; p_output_mem_fx = hCPE->output_mem_fx[1]; - if(hCPE->output_mem[1] != NULL)floatToFixed_arrL(hCPE->output_mem[1], hCPE->output_mem_fx[1],Q11, NS2SA_fx2(sts[0]->output_Fs, STEREO_DFT32MS_OVL_NS)); - nchan_out = hCPE->nchan_out; IF( hCPE->hStereoTD != NULL ) @@ -446,11 +438,6 @@ ivas_error ivas_core_dec( } #ifndef TO_BE_REMOVED_CONVERSION - if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) - { - fixedToFloat_arrL( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB[0], 11, STEREO_DFT32MS_OVL_16k ); - //fixedToFloat_arrL( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct, 11, STEREO_MDCT2DFT_FADE_LEN_48k ); - } // n_channels loop // sts is initialized here for (Word16 k = 0; k < n_channels; k++ ) @@ -643,7 +630,7 @@ ivas_error ivas_core_dec( //Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; /* float2fix, to be removed */ - acelp_decoder_state_float2fix(st, hCPE == NULL ? NULL : hCPE->hStereoCng); + acelp_decoder_state_float2fix(st/*, hCPE == NULL ? NULL : hCPE->hStereoCng*/); //if (hStereoTD) { // floatToFixed_arr(hStereoTD->tdm_Pri_pitch_buf, hStereoTD->tdm_Pri_pitch_buf_fx, Q6, NB_SUBFR); //} @@ -664,7 +651,7 @@ ivas_error ivas_core_dec( /* fix2float, to be removed */ Copy_Scale_sig_16_32(output_16_fx[n],output_32_fx[n],L_FRAME48k, Q11 - st->Q_syn2); Scale_sig(output_16_fx[n], L_FRAME48k, -st->Q_syn2); - acelp_decoder_state_fix2float(st, hCPE == NULL ? NULL : hCPE->hStereoCng); + acelp_decoder_state_fix2float(st/*, hCPE == NULL ? NULL : hCPE->hStereoCng*/); //fixedToFloat_arr(output_16_fx[n], output[n], 0, L_FRAME48k); fixedToFloat_arr(synth_fxl, synth[n], 0, L_FRAME48k); if ( save_hb_synth_32_fx ) @@ -1222,15 +1209,18 @@ ivas_error ivas_core_dec( // } //} - if ( (Word32) hCPE->hStereoCng->c_PS_LT != 0 ) - { - Q_c_PS_LT = norm_l( (Word32) hCPE->hStereoCng->c_PS_LT ); - } - Word32 c_PS_LT_fx = float_to_fix( hCPE->hStereoCng->c_PS_LT, Q_c_PS_LT ); + //if ( (Word32) hCPE->hStereoCng->c_PS_LT != 0 ) + //{ + // Q_c_PS_LT = norm_l( (Word32) hCPE->hStereoCng->c_PS_LT ); + //} + //Word32 c_PS_LT_fx = float_to_fix( hCPE->hStereoCng->c_PS_LT, Q_c_PS_LT ); + Word32 c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx); + Q_c_PS_LT = Q31; stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); - hCPE->hStereoCng->c_PS_LT = fix_to_float( c_PS_LT_fx, Q_c_PS_LT ); + hCPE->hStereoCng->c_PS_LT_fx = extract_h( c_PS_LT_fx ); + //hCPE->hStereoCng->c_PS_LT = fix_to_float( c_PS_LT_fx, Q_c_PS_LT ); } /*---------------------------------------------------------------------* @@ -2019,34 +2009,6 @@ ivas_error ivas_core_dec( } } } - if (hCPE->input_mem[ch_ind]) - { - FOR(int ind = 0; ind < NS2SA(output_Fs, STEREO_DFT32MS_OVL_NS); ind++) - { - hCPE->input_mem_fx[ch_ind][ind] = (Word32)(hCPE->input_mem[ch_ind][ind] * (1 << 11)); - } - } - if (hCPE->input_mem_LB[ch_ind]) - { - FOR(int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++) - { - hCPE->input_mem_LB_fx[ch_ind][ind] = (Word32)(hCPE->input_mem_LB[ch_ind][ind] * (1 << 11)); - } - } - if (hCPE->input_mem_BPF[0] != NULL) - { - FOR(int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++) - { - hCPE->input_mem_BPF_fx[0][ind] = (Word32)(hCPE->input_mem_BPF[0][ind] * (1 << 11)); - } - } - IF(hCPE->output_mem[ch_ind] != NULL) - { - FOR(Word32 kk = 0; kk < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); kk++) - { - hCPE->output_mem_fx[ch_ind][kk] = (Word32)(hCPE->output_mem[ch_ind][kk] * (1 << OUTPUT_Q)); - } - } IF(hCPE->hStereoDft != NULL) { FOR(int ind = 0; ind < NS2SA(16000, DELAY_BWE_TOTAL_NS); ind++) @@ -2054,10 +2016,6 @@ ivas_error ivas_core_dec( hCPE->hStereoDft->ap_delay_mem_fx[ind] = (Word32)(hCPE->hStereoDft->ap_delay_mem[ind] * (1 << 11)); } hCPE->hStereoDft->q_ap_delay_mem_fx = 11; - FOR(int ind = 0; ind < NS2SA(16000, STEREO_DFT32MS_OVL_NS); ind++) - { - hCPE->hStereoDft->buff_LBTCX_mem_fx[ind] = (Word32)(hCPE->hStereoDft->buff_LBTCX_mem[ind] * (1 << 11)); - } IF(hCPE->hStereoDft->hTcxLtpDec != NULL) { FOR(Word32 p = 0; p < L_FRAME48k; p++) @@ -2290,42 +2248,12 @@ ivas_error ivas_core_dec( } } } - if ( hCPE->input_mem_fx[ch_ind] ) - { - FOR( i = 0; i < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ); i++ ) - { - hCPE->input_mem[ch_ind][i] = (float) hCPE->input_mem_fx[ch_ind][i] / (float) ( 1 << 11 ); - } - } - IF(hCPE->output_mem[ch_ind] != NULL) - { - FOR(Word32 kk = 0; kk < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); kk++) - { - hCPE->output_mem[ch_ind][kk] = (float)hCPE->output_mem_fx[ch_ind][kk] / (1u << 11); - } - } - if ( hCPE->input_mem_LB[ch_ind] ) - { - FOR( i = 0; i < STEREO_DFT32MS_OVL_16k; i++ ) - { - hCPE->input_mem_LB[ch_ind][i] = (float) hCPE->input_mem_LB_fx[ch_ind][i] / (float) ( 1 << 11 ); - } - } - if ( hCPE->input_mem_BPF[0] != NULL ) - { - FOR( i = 0; i < STEREO_DFT32MS_OVL_16k; i++ ) - hCPE->input_mem_BPF[0][i] = (float) hCPE->input_mem_BPF_fx[0][i] / (float) ( 1 << 11 ); - } IF( hCPE->hStereoDft != NULL ) { FOR( int ind = 0; ind < NS2SA( 16000, DELAY_BWE_TOTAL_NS ); ind++ ) { hCPE->hStereoDft->ap_delay_mem[ind] = (float) hCPE->hStereoDft->ap_delay_mem_fx[ind] / (float) ( 1 << 11 ); } - FOR( int ind = 0; ind < NS2SA( 16000, STEREO_DFT32MS_OVL_NS ); ind++ ) - { - hCPE->hStereoDft->buff_LBTCX_mem[ind] = (float) hCPE->hStereoDft->buff_LBTCX_mem_fx[ind] / (float) ( 1 << 11 ); - } IF(hCPE->hStereoDft->hTcxLtpDec != NULL) { diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 0234e0b40..475f3f7e5 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -77,15 +77,9 @@ ivas_error ivas_cpe_dec_fx( Word16 nb_bits, last_core; Word16 last_bwidth; Word16 tdm_ratio_idx; -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - float outputHB[CPE_CHANNELS][L_FRAME48k]; /* 'float' buffer for output HB synthesis, both channels */ - float res_buf[STEREO_DFT_N_8k]; - Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ - Word32 res_buf_fx[STEREO_DFT_N_8k]; -#else - Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ - Word32 res_buf_fx[STEREO_DFT_N_8k]; -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED + Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */ + Word16 q_res_buf = Q8; + Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */ CPE_DEC_HANDLE hCPE; Decoder_State **sts; Word32 ivas_total_brate; @@ -98,18 +92,48 @@ ivas_error ivas_cpe_dec_fx( push_wmops( "ivas_cpe_dec" ); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); hCPE = st_ivas->hCPE[cpe_id]; sts = hCPE->hCoreCoder; last_core = sts[0]->last_core; + move16(); last_bwidth = sts[0]->last_bwidth; + move16(); sts[0]->BER_detect = s_or( sts[0]->BER_detect, st_ivas->BER_detect ); sts[1]->BER_detect = s_or( sts[1]->BER_detect, st_ivas->BER_detect ); element_brate_ref = hCPE->element_brate; + move32(); +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + Word16 q_common = Q11; + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + floatToFixed_arrL( hCPE->output_mem[n], hCPE->output_mem_fx[n], q_common, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ) ); + } + IF( hCPE->input_mem_LB[n] != NULL ) + { + floatToFixed_arrL( hCPE->input_mem_LB[n], hCPE->input_mem_LB_fx[n], q_common, STEREO_DFT32MS_OVL_16k ); + } + if (hCPE->input_mem[n] != NULL) + { + floatToFixed_arrL(&hCPE->input_mem[n][0], &hCPE->input_mem_fx[n][0], q_common, NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS)); + } + if (hCPE->input_mem_BPF[0] != NULL) + { + floatToFixed_arrL(hCPE->input_mem_BPF[0], hCPE->input_mem_BPF_fx[0], q_common, STEREO_DFT32MS_OVL_16k); + } + } + IF( hCPE->hStereoDft != NULL ) + { + floatToFixed_arrL( hCPE->hStereoDft->buff_LBTCX_mem, hCPE->hStereoDft->buff_LBTCX_mem_fx, q_common, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); + } +#endif /*------------------------------------------------------------------* * Read stereo technology info & audio bandwidth *-----------------------------------------------------------------*/ @@ -128,80 +152,62 @@ ivas_error ivas_cpe_dec_fx( return error; } #else -#if 1 // Float to fix conversions +#if 1 // Float to fix conversions float maxim = 0; - Word16 q_output_mem, q_buff_LBTCX_mem, q_input_mem_LB, q_old_out = 31, q_old_out_LB = 31, q_tcxltp_mem_in_float=15; + Word16 q_output_mem, q_buff_LBTCX_mem, q_input_mem_LB, q_old_out = 31, q_old_out_LB = 31, q_tcxltp_mem_in_float; q_output_mem = 11; - IF(hCPE->hStereoDft) - FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { - FOR(Word16 ind2 = 0; ind2 < s_max(hCPE->hStereoDft->dft32ms_ovl, hCPE->hStereoDft->dft32ms_ovl - NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS )); ind2++) { - hCPE->output_mem_fx[ind1][ind2] = (Word32)(hCPE->output_mem[ind1][ind2] * (1<hStereoDft) - FOR(Word16 ind1 = 0; ind1 < s_min(50, NS2SA( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )); ind1++) { - hCPE->hStereoDft->buff_LBTCX_mem_fx[ind1] = (Word32)(hCPE->hStereoDft->buff_LBTCX_mem[ind1] * (1<hStereoDft && hCPE->input_mem_LB[0] && NE_16(hCPE->hCoreCoder[0]->last_core, ACELP_CORE)) - FOR(Word16 ind1 = 0; ind1 < s_min(NS2SA( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), 50); ind1++) { - hCPE->input_mem_LB_fx[0][ind1] = (Word32)(hCPE->input_mem_LB[0][ind1] * (1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) - FOR(Word16 ind2 = 0; ind2 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind2++) { - maxim = fmaxf(fabsf(hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2]), maxim); - } - } - IF (maxim > 1.f) q_old_out = norm_l((Word32)maxim); - q_old_out -= 1; - FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { - IF(hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) - FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { - hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx[ind2] = (Word32)(hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2] * (1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) + // FOR( Word16 ind2 = 0; ind2 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind2++ ) + // { + // maxim = fmaxf( fabsf( hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2] ), maxim ); + // } + //} + //IF( maxim > 1.f ) + //q_old_out = norm_l( (Word32) maxim ); + //q_old_out -= 1; + q_old_out = Q11; + FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) + { + IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) + FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) + { + hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx[ind2] = (Word32) ( hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2] * ( 1 << q_old_out ) ); } } maxim = 0; - FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { - IF(hCPE->hCoreCoder[ind1]->hHQ_core) - FOR(Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++) { - maxim = fmaxf(fabsf(hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2]), maxim); + FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) + { + IF( hCPE->hCoreCoder[ind1]->hHQ_core ) + FOR( Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++ ) + { + maxim = fmaxf( fabsf( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2] ), maxim ); } } - IF (maxim > 1.f) q_old_out_LB = norm_l((Word32)maxim); + IF( maxim > 1.f ) + q_old_out_LB = norm_l( (Word32) maxim ); q_old_out_LB -= 1; - FOR(Word16 ind1 = 0; ind1 < 1; ind1++) { - IF(hCPE->hCoreCoder[ind1]->hHQ_core) + FOR( Word16 ind1 = 0; ind1 < 1; ind1++ ) + { + IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { - FOR(Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++) { - hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx[ind2] = (Word32)(hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2] * (1<hCoreCoder[ind1]->hHQ_core->old_outLB_fx[ind2] = (Word32) ( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2] * ( 1 << q_old_out_LB ) ); } hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = q_old_out_LB; } } q_tcxltp_mem_in_float = 11; - IF(hCPE->hStereoDft && hCPE->hStereoDft->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[ind] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[ind] * (1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1<hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)(TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { - //hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_32[ind] = (Word32)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_float[ind] * (1 << q_tcxltp_mem_in_float)); - } - IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)(L_FRAME48k * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { - //hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1 << q_tcxltp_mem_in_float)); - } - IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->cldfbSyn) - hCPE->hCoreCoder[ind2]->cldfbSyn->scale = (Word16)(hCPE->hCoreCoder[ind2]->cldfbSyn->scale_flt * (1u << norm_s((Word16)hCPE->hCoreCoder[0]->cldfbSyn->scale_flt))); + FOR( Word16 ind2 = 0; ind2 < 2; ind2++ ) + { + IF( hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->cldfbSyn ) + hCPE->hCoreCoder[ind2]->cldfbSyn->scale = (Word16) ( hCPE->hCoreCoder[ind2]->cldfbSyn->scale_flt * ( 1u << norm_s( (Word16) hCPE->hCoreCoder[0]->cldfbSyn->scale_flt ) ) ); } FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { //IF(hCPE->hCoreCoder[0] && hCPE->hCoreCoder[0]->hTcxDec) @@ -209,60 +215,27 @@ ivas_error ivas_cpe_dec_fx( //IF(hCPE->hCoreCoder[1] && hCPE->hCoreCoder[1]->hTcxDec) //hCPE->hCoreCoder[1]->hTcxDec->old_syn_Overl_32[ind] = (Word32)(hCPE->hCoreCoder[1]->hTcxDec->old_syn_Overl_float[ind] * (ONE_IN_Q11)); } - IF(hCPE->hStereoTD) - FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { - hCPE->hStereoTD->TCX_old_syn_Overl_fx[ind] = (Word32)(hCPE->hStereoTD->TCX_old_syn_Overl[ind] * (ONE_IN_Q11)); - } - #endif // Float to fix conversions IF( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } -#if 1 // Fix to float conversions - IF(hCPE->hStereoDft) - FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { - FOR(Word16 ind2 = 0; ind2 < s_max(hCPE->hStereoDft->dft32ms_ovl, hCPE->hStereoDft->dft32ms_ovl - NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS )); ind2++) { - hCPE->output_mem[ind1][ind2] = (float)hCPE->output_mem_fx[ind1][ind2] / (float)(1<input_mem_LB[0]) - FOR(Word16 ind1 = 0; ind1 < s_min(NS2SA( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), 50); ind1++) { - hCPE->input_mem_LB[0][ind1] = (float)(hCPE->input_mem_LB_fx[0][ind1]) / (float)(1<hStereoDft) - FOR(Word16 ind1 = 0; ind1 < s_min(NS2SA( s_min( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, 16000 ), STEREO_DFT32MS_OVL_NS ), 50); ind1++) { - hCPE->hStereoDft->buff_LBTCX_mem[ind1] = (float)(hCPE->hStereoDft->buff_LBTCX_mem_fx[ind1]) / (float)(1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) - FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { - hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2] = (float)(hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx[ind2]) / (1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) - FOR(Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++) { - hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2] = (float)(hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx[ind2]) / (1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) + FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) + { + hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2] = (float) ( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx[ind2] ) / ( 1 << q_old_out ); } } - IF(hCPE->hStereoDft && hCPE->hStereoDft->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[ind] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[ind] / (float)(1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { - //hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_float[ind] = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_32[ind] / (float)(1<hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) - FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { - //hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) + FOR( Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++ ) + { + hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2] = (float) ( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx[ind2] ) / ( 1 << q_old_out_LB ); } } FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { @@ -279,82 +252,47 @@ ivas_error ivas_cpe_dec_fx( *-----------------------------------------------------------------*/ n_channels = CPE_CHANNELS; + move16(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { n_channels = 1; /* in DFT stereo, only M channel is coded */ + move16(); } tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; + move16(); FOR( n = 0; n < n_channels; n++ ) { sts[n]->idchan = n; + move16(); sts[n]->element_mode = hCPE->element_mode; + move16(); IF( !st_ivas->bfi ) { sts[n]->tdm_LRTD_flag = 0; + move16(); } /* TD stereo parameters */ IF( hCPE->hStereoTD != NULL ) { hCPE->hStereoTD->tdm_lp_reuse_flag = 0; + move16(); hCPE->hStereoTD->tdm_low_rate_mode = 0; + move16(); hCPE->hStereoTD->tdm_Pitch_reuse_flag = 0; + move16(); } } /*----------------------------------------------------------------* * Resets/updates in case of stereo switching *----------------------------------------------------------------*/ - Word16 q_temp = 11;//any q works - FOR(n = 0; n < CPE_CHANNELS; n++) - { - if (hCPE->output_mem[n] != NULL) - { - floatToFixed_arrL(&hCPE->output_mem[n][0], &hCPE->output_mem_fx[n][0], q_temp, NS2SA_fx2(st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS));//any q works - } -#ifndef FIX_746 - if (hCPE->input_mem[n] != NULL) - { - floatToFixed_arrL(&hCPE->input_mem[n][0], &hCPE->input_mem_fx[n][0], q_temp, NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS)); - } -#endif - if (hCPE->input_mem_LB[n] != NULL) - { - floatToFixed_arrL(&hCPE->input_mem_LB[n][0], &hCPE->input_mem_LB_fx[n][0], q_temp, STEREO_DFT32MS_OVL_16k); - } - - //if (hCPE->hCoreCoder[n] != NULL) - //{ - // floatToFixed_arrL(&hCPE->hCoreCoder[n]->prev_synth_buffer[0], &hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[0], q_temp, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); - // floatToFixed_arr(&hCPE->hCoreCoder[n]->prev_synth_buffer[0], &hCPE->hCoreCoder[n]->prev_synth_buffer_fx[0], 0, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); - //} - } stereo_switching_dec( hCPE, ivas_total_brate ); - FOR(n = 0; n < CPE_CHANNELS; n++) - { - if (hCPE->output_mem[n] != NULL) - { - fixedToFloat_arrL(&hCPE->output_mem_fx[n][0], &hCPE->output_mem[n][0], q_temp, NS2SA_fx2(st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS));//any q works - } - if (hCPE->input_mem[n] != NULL) - { - fixedToFloat_arrL(&hCPE->input_mem_fx[n][0], &hCPE->input_mem[n][0], q_temp, NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS)); - } - if (hCPE->input_mem_LB[n] != NULL) - { - fixedToFloat_arrL(&hCPE->input_mem_LB_fx[n][0], &hCPE->input_mem_LB[n][0], q_temp, STEREO_DFT32MS_OVL_16k); - } - //if (hCPE->hCoreCoder[n] != NULL) - //{ - //fixedToFloat_arrL(&hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[0], &hCPE->hCoreCoder[n]->prev_synth_buffer[0], q_temp, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); - //fixedToFloat_arrL(&hCPE->hCoreCoder[n]->prev_synth_buffer_fx[0], &hCPE->hCoreCoder[n]->prev_synth_buffer[0], 0, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); - //} - } /*----------------------------------------------------------------* * Configuration of stereo decoder *----------------------------------------------------------------*/ @@ -363,19 +301,25 @@ ivas_error ivas_cpe_dec_fx( FOR( n = 0; n < n_channels; n++ ) { sts[n]->codec_mode = MODE1; + move16(); } + test(); + test(); + test(); + test(); IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || EQ_16( sts[0]->ini_frame, 0 ) || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) ) { + test(); IF( st_ivas->hQMetaData != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (Word32) ( st_ivas->hQMetaData->bits_frame_nominal * 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (Word32) ( st_ivas->hQMetaData->bits_frame_nominal * 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } ELSE { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } ELSE @@ -383,11 +327,11 @@ ivas_error ivas_cpe_dec_fx( /* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */ IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } ELSE { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } } @@ -396,12 +340,12 @@ ivas_error ivas_cpe_dec_fx( { IF( hCPE->hStereoTD->tdm_LRTD_flag ) { - sts[0]->bits_frame_nominal = (Word16) ( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); - sts[1]->bits_frame_nominal = (Word16) ( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); + sts[0]->bits_frame_nominal = extract_l( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); + sts[1]->bits_frame_nominal = extract_l( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); } ELSE { - stereo_dft_config( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } @@ -425,18 +369,22 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { hCPE->hCoreCoder[n]->core_brate = ivas_total_brate; + move16(); hCPE->hCoreCoder[0]->total_brate = ivas_total_brate; + move16(); } ELSE { hCPE->hCoreCoder[n]->core_brate = SID_2k40; + move16(); } } /* read DFT Stereo side info */ nb_bits = extract_l( L_sub( ( hCPE->element_brate / FRAMES_PER_SEC ), Mpy_32_16_1( 26214, sts[0]->bits_frame_nominal ) ) ); // 0.8f in q15 = 26214 cpe_brate = st_ivas->hCPE[0]->element_brate; - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + move32(); + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( (Word16) ( cpe_brate / FRAMES_PER_SEC ), 1 ), nb_bits_metadata ); sts[1]->bit_stream = sts[1]->bit_stream + (Word16) ( hCPE->brate_surplus / FRAMES_PER_SEC ); @@ -454,32 +402,35 @@ ivas_error ivas_cpe_dec_fx( sts[1]->total_brate = L_sub( IVAS_SID_5k2, SID_2k40 ); } - IF( ( ( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) || ( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) + test(); + test(); + test(); + test(); + IF( ( ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) || ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { sts[0]->total_brate = hCPE->element_brate; /* Only mono downmix was transmitted in this case */ + move32(); } ELSE { - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nb_bits = sub( nb_bits, nb_bits_metadata ); IF( LT_32( hCPE->brate_surplus, 0 ) ) { - nb_bits = add( nb_bits, (Word16) ( hCPE->brate_surplus / FRAMES_PER_SEC ) ); + nb_bits = add( nb_bits, extract_l( hCPE->brate_surplus / FRAMES_PER_SEC ) ); } } #ifdef IVAS_FLOAT_FIXED #if 1 - Word16 Q_coh = 13, Q_res_buf = 8; - // Q_res_buf = Q_factor_arrL( res_buf, STEREO_DFT_N_8k ); - floatToFixed_arr(hCPE->hStereoCng->coh, hCPE->hStereoCng->coh_fx, Q_coh, 14 ); - floatToFixed_arrL( res_buf, res_buf_fx, Q_res_buf, STEREO_DFT_N_8k ); + Word16 Q_coh = 13; + floatToFixed_arr( hCPE->hStereoCng->coh, hCPE->hStereoCng->coh_fx, Q_coh, 14 ); #endif stereo_dft_dec_read_BS_fx( ivas_total_brate, hCPE->element_brate, &sts[0]->total_brate, sts[1], hCPE->hStereoDft, sts[0]->bwidth, output_frame, res_buf_fx, &nb_bits, hCPE->hStereoCng->coh_fx, st_ivas->ivas_format ); -#if 1 /*Fixed To Float changes*/ +#if 1 /*Fixed To Float changes*/ fixedToFloat_arr( hCPE->hStereoCng->coh_fx, hCPE->hStereoCng->coh, Q_coh, 14 ); /*Q-13*/ - fixedToFloat_arrL( res_buf_fx, res_buf, Q_res_buf, STEREO_DFT_N_8k ); #endif #else stereo_dft_dec_read_BS( ivas_total_brate, hCPE->element_brate, &sts[0]->total_brate, sts[1], hCPE->hStereoDft, sts[0]->bwidth, output_frame, res_buf, &nb_bits, hCPE->hStereoCng->coh, st_ivas->ivas_format ); @@ -490,7 +441,10 @@ ivas_error ivas_cpe_dec_fx( sts[0]->total_brate = L_sub( sts[0]->total_brate, nb_bits_metadata * FRAMES_PER_SEC ); /* subtract bit-rate for combined format coding */ - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { sts[0]->total_brate = L_add( sts[0]->total_brate, hCPE->brate_surplus ); } @@ -498,14 +452,16 @@ ivas_error ivas_cpe_dec_fx( ELSE { hCPE->hStereoDft->sg_mem_corrupt = 1; + move16(); } } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { /* signal bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; - sts[1]->bits_frame_channel = (Word16) ( hCPE->element_brate / FRAMES_PER_SEC ); - sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, (Word16) ( hCPE->brate_surplus / FRAMES_PER_SEC ) ); + move16(); + sts[1]->bits_frame_channel = extract_l( hCPE->element_brate / FRAMES_PER_SEC ); + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( hCPE->brate_surplus / FRAMES_PER_SEC ) ); IF( st_ivas->hQMetaData != NULL ) { sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits ); @@ -515,12 +471,18 @@ ivas_error ivas_cpe_dec_fx( { /* compute bit-rate surplus per channel in combined format coding */ Word32 brate_surplus[CPE_CHANNELS]; - IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + test(); + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { brate_surplus[0] = L_shr( L_mult( (Word16) L_shr( ( hCPE->brate_surplus / FRAMES_PER_SEC ), 1 ), FRAMES_PER_SEC ), 1 ); + move32(); brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] ); + move32(); } + test(); + test(); IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( EQ_16( sts[0]->first_CNG, 0 ) || EQ_16( sts[1]->first_CNG, 0 ) ) ) { IF( ( error = initMdctStereoDtxData_fx( hCPE ) ) != IVAS_ERR_OK ) @@ -533,30 +495,34 @@ ivas_error ivas_cpe_dec_fx( FOR( n = 0; n < n_channels; n++ ) { IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) - { sts[n]->total_brate = SID_2k40; + move32(); sts[1]->bit_stream = sts[0]->bit_stream + SID_2k40 / FRAMES_PER_SEC; } ELSE { /*total bitrate must be set to the element bitrate to avoid false BER IF bits read are larger than half the bitrate*/ sts[n]->total_brate = hCPE->element_brate; + move32(); } - sts[n]->bits_frame_nominal = (Word16) ( sts[n]->total_brate / FRAMES_PER_SEC ); + sts[n]->bits_frame_nominal = extract_l( sts[n]->total_brate / FRAMES_PER_SEC ); sts[n]->bits_frame_channel = extract_l( L_shr( ( hCPE->element_brate / FRAMES_PER_SEC ), sub( n_channels, 1 ) ) ); /* subtract bit-rate for combined format coding */ - IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + test(); + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, (Word16) ( brate_surplus[n] / FRAMES_PER_SEC ) ); + sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( brate_surplus[n] / FRAMES_PER_SEC ) ); sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] ); } } IF( !st_ivas->hMCT ) { - IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { FOR( n = 0; n < n_channels; n++ ) { @@ -587,27 +553,35 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) ) { sts[n]->VAD = 0; + move16(); sts[n]->active_cnt = 0; + move16(); IF( sts[1] != NULL ) { sts[1]->active_cnt = 0; + move16(); } } ELSE { sts[n]->VAD = 1; + move16(); sts[n]->active_cnt++; sts[n]->active_cnt = s_min( sts[n]->active_cnt, 100 ); } /* set CNA flag */ + test(); + test(); IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && LE_32( hCPE->element_brate, CNA_MAX_BRATE_DFT_STEREO ) ) || LE_32( hCPE->element_brate, CNA_MAX_BRATE_STEREO ) ) { sts[n]->flag_cna = 1; + move16(); } ELSE { sts[n]->flag_cna = 0; + move16(); } } @@ -618,12 +592,14 @@ ivas_error ivas_cpe_dec_fx( { tdm_configure_dec( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata ); - sts[1]->bit_stream = sts[0]->bit_stream + (Word16) ( sts[0]->total_brate / FRAMES_PER_SEC ); + sts[1]->bit_stream = sts[0]->bit_stream + extract_l( sts[0]->total_brate / FRAMES_PER_SEC ); } ELSE { sts[1]->coder_type = sts[1]->last_coder_type; + move16(); tdm_ratio_idx = hCPE->hStereoTD->tdm_last_ratio_idx; + move16(); } } @@ -631,67 +607,47 @@ ivas_error ivas_cpe_dec_fx( * Core Decoder *----------------------------------------------------------------*/ + test(); + test(); IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { #ifndef TO_BE_REMOVED_CONVERSION - Word16 k; - - //{ - // sts = hCPE->hCoreCoder; - //} - - //core_coding_part will go in this loop, once the things are done - for (k = 0; k < n_channels; k++) - { - if (sts[k]->hTcxDec != NULL) + Word16 k; + for ( k = 0; k < n_channels; k++ ) { - floatToFixed_arr(sts[k]->hHQ_core->old_out, sts[k]->hHQ_core->old_out_fx, 0, L_FRAME48k); - floatToFixed_arr(sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_out_LB_fx, 0, L_FRAME32k); - floatToFixed_arrL(sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_outLB_fx, 11, L_FRAME32k); - //sts[k]->hTcxDec->conceal_eof_gain32 = floatToFixed( sts[k]->hTcxDec->conceal_eof_gain_float, 15 ); + if ( sts[k]->hTcxDec != NULL ) + { + floatToFixed_arr( sts[k]->hHQ_core->old_out, sts[k]->hHQ_core->old_out_fx, 0, L_FRAME48k ); + floatToFixed_arr( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_out_LB_fx, 0, L_FRAME32k ); + floatToFixed_arrL( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_outLB_fx, 11, L_FRAME32k ); + } } - } - - if (hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT) - { - floatToFixed_arrL(hCPE->input_mem_LB[0], hCPE->input_mem_LB_fx[0], 11, STEREO_DFT32MS_OVL_16k); - } - IF(sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40) - { - FOR(Word16 ch = 0; ch < CPE_CHANNELS; ++ch) + IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) { //f2me_buf(sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, &sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, sts[ch]->hFdCngDec->hFdCngCom->stopBand - sts[ch]->hFdCngDec->hFdCngCom->startBand); //floatToFixed_arr(sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt, sts[ch]->hFdCngDec->hFdCngCom->A_cng, Q14, M + 1); } - } - floatToFixed_arrL( outputHB[0], outputHB_fx[0], Q11, L_FRAME48k ); - floatToFixed_arrL( outputHB[1], outputHB_fx[1], Q11, L_FRAME48k ); #endif IF( ( error = ivas_core_dec( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ) != IVAS_ERR_OK ) { return error; } - fixedToFloat_arrL(outputHB_fx[0], outputHB[0], Q11, L_FRAME48k); - fixedToFloat_arrL(outputHB_fx[1], outputHB[1], Q11, L_FRAME48k); } IF( st_ivas->hMCT ) { pop_wmops(); - + return error; } /*----------------------------------------------------------------* * Stereo decoder & upmixing *----------------------------------------------------------------*/ - for (int j = 0; j < output_frame; j++) - { - outputHB_fx[0][j] = (Word32)(outputHB[0][j] * (1 << *q_output)); - outputHB_fx[1][j] = (Word32)(outputHB[1][j] * (1 << *q_output)); - } + test(); + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; @@ -701,29 +657,17 @@ ivas_error ivas_cpe_dec_fx( #ifndef TO_BE_REMOVED_CONVERSION Word16 k; - - //{ - // sts = hCPE->hCoreCoder; - //} - - //core_coding_part will go in this loop, once the things are done - for (k = 0; k < n_channels; k++) + for ( k = 0; k < n_channels; k++ ) { - if (sts[k]->hTcxDec != NULL) - { - floatToFixed_arr(sts[k]->hHQ_core->old_out, sts[k]->hHQ_core->old_out_fx, 0, L_FRAME48k); - floatToFixed_arr(sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_out_LB_fx, 0, L_FRAME32k); - floatToFixed_arrL(sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_outLB_fx, 11, L_FRAME32k); - //sts[k]->hTcxDec->conceal_eof_gain32 = floatToFixed( sts[k]->hTcxDec->conceal_eof_gain_float, 15 ); - } - } - - if (hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT) - { - floatToFixed_arrL(hCPE->input_mem_LB[0], hCPE->input_mem_LB_fx[0], 11, STEREO_DFT32MS_OVL_16k); + if ( sts[k]->hTcxDec != NULL ) + { + floatToFixed_arr( sts[k]->hHQ_core->old_out, sts[k]->hHQ_core->old_out_fx, 0, L_FRAME48k ); + floatToFixed_arr( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_out_LB_fx, 0, L_FRAME32k ); + floatToFixed_arrL( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_outLB_fx, 11, L_FRAME32k ); + } } - IF(sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40) + IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) { FOR(Word16 ch = 0; ch < CPE_CHANNELS; ++ch) { @@ -737,43 +681,41 @@ ivas_error ivas_cpe_dec_fx( set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); /* core decoder */ - floatToFixed_arrL(outputHB[0], outputHB_fx[0], Q11, L_FRAME48k); - floatToFixed_arrL(outputHB[1], outputHB_fx[1], Q11, L_FRAME48k); IF( ( error = ivas_core_dec( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ) != IVAS_ERR_OK ) { return error; } - fixedToFloat_arrL(outputHB_fx[0], outputHB[0], Q11, L_FRAME48k); - fixedToFloat_arrL(outputHB_fx[1], outputHB[1], Q11, L_FRAME48k); - fixedToFloat_arrL(DFT_fx[0], DFT[0], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX); - fixedToFloat_arrL(DFT_fx[1], DFT[1], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX); + fixedToFloat_arrL( DFT_fx[0], DFT[0], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX ); + fixedToFloat_arrL( DFT_fx[1], DFT[1], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX ); // Scaling of DFT's - //Word16 q_dft_tmp = s_min(getScaleFactor32(DFT_fx[0], STEREO_DFT_BUF_MAX), getScaleFactor32(DFT_fx[1], STEREO_DFT_BUF_MAX)); + // Word16 q_dft_tmp = s_min(getScaleFactor32(DFT_fx[0], STEREO_DFT_BUF_MAX), getScaleFactor32(DFT_fx[1], STEREO_DFT_BUF_MAX)); Word16 shift; Word32 tmp1, tmp2; - maximum_abs_32_fx(DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1); - maximum_abs_32_fx(DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2); + maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 ); + maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 ); - shift = s_min((tmp1 == 0) ? 31 : norm_l(tmp1), (tmp2 == 0) ? 31 : norm_l(tmp2)); + shift = s_min( ( tmp1 == 0 ) ? 31 : norm_l( tmp1 ), ( tmp2 == 0 ) ? 31 : norm_l( tmp2 ) ); - if (shift != 31) { + IF( shift != 31 ) + { shift = hCPE->hStereoDft->q_dft + shift - Q11; /* Q11 for guard bits */ - IF(shift > hCPE->hStereoDft->q_dft) + IF( shift > hCPE->hStereoDft->q_dft ) { - Scale_sig32(DFT_fx[0], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft); - Scale_sig32(DFT_fx[1], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft); + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft ); hCPE->hStereoDft->q_dft = shift; } } - else + ELSE { hCPE->hStereoDft->q_dft = Q8; } /* DFT Stereo residual decoding */ + test(); IF( GT_16( hCPE->hStereoDft->res_cod_band_max, 0 ) && !st_ivas->bfi ) { #ifndef IVAS_FLOAT_FIXED @@ -781,61 +723,44 @@ ivas_error ivas_cpe_dec_fx( stereo_dft_dec_analyze( hCPE, output[1], DFT, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 ); #else - //Word32 output_fix[L_FRAME8k]; + // Word32 output_fix[L_FRAME8k]; hCPE->hStereoDft->q_res_cod_mem_fx = 0; // keeping same as shift needed inside. - floatToFixed_arrL(hCPE->hStereoDft->res_cod_mem, hCPE->hStereoDft->res_cod_mem_fx, Q16, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); + floatToFixed_arrL( hCPE->hStereoDft->res_cod_mem, hCPE->hStereoDft->res_cod_mem_fx, Q16, sizeof( hCPE->hStereoDft->res_cod_mem_fx ) / sizeof( hCPE->hStereoDft->res_cod_mem_fx[0] ) ); - Copy_Scale_sig_32_16(hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10 ); - stereo_dft_dec_res_fx(hCPE, res_buf_fx, Q8, output[1]); + stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] ); - Copy_Scale_sig_16_32(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10 ); - fixedToFloat_arrL(hCPE->hStereoDft->res_cod_mem_fx, hCPE->hStereoDft->res_cod_mem, Q16, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); + fixedToFloat_arrL( hCPE->hStereoDft->res_cod_mem_fx, hCPE->hStereoDft->res_cod_mem, Q16, sizeof( hCPE->hStereoDft->res_cod_mem_fx ) / sizeof( hCPE->hStereoDft->res_cod_mem_fx[0] ) ); - Scale_sig32(output[1], L_FRAME8k, Q11 - Q15); // Q15 -> Q11 + Scale_sig32( output[1], L_FRAME8k, Q11 - Q15 ); // Q15 -> Q11 #endif - /////////////////////////////////////////////////////// Word16 q = Q11; - Word32 output_Fs = hCPE->hCoreCoder[0]->output_Fs; - floatToFixed_arrL(hCPE->input_mem_BPF[0], hCPE->input_mem_BPF_fx[0], q, STEREO_DFT32MS_OVL_16k); - FOR(int i = 0; i < CPE_CHANNELS; ++i) - { - floatToFixed_arrL(hCPE->input_mem[i], hCPE->input_mem_fx[i], q, NS2SA(output_Fs, STEREO_DFT32MS_OVL_NS)); - floatToFixed_arrL(hCPE->input_mem_LB[i], hCPE->input_mem_LB_fx[i], q, STEREO_DFT32MS_OVL_16k); - } - /////////////////////////////////////////////////////// Word16 q_out_DFT[2]; q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft; // output in Q11, q not modified // q_out_DFT only of 1 modified - stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT); // q not modified + stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT ); // q not modified - /////////////////////////////////////////////////////// - fixedToFloat_arrL(hCPE->input_mem_BPF_fx[0], hCPE->input_mem_BPF[0], q, STEREO_DFT32MS_OVL_16k); - FOR(int i = 0; i < CPE_CHANNELS; ++i) - { - fixedToFloat_arrL(hCPE->input_mem_fx[i], hCPE->input_mem[i], q, NS2SA(output_Fs, STEREO_DFT32MS_OVL_NS)); - fixedToFloat_arrL(hCPE->input_mem_LB_fx[i], hCPE->input_mem_LB[i], q, STEREO_DFT32MS_OVL_16k); - } - /////////////////////////////////////////////////////// - - Scale_sig32(DFT_fx[1], STEREO_DFT_BUF_MAX, hCPE->hStereoDft->q_dft - q_out_DFT[1]); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, hCPE->hStereoDft->q_dft - q_out_DFT[1] ); } - fixedToFloat_arrL(DFT_fx[0], DFT[0], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX); - fixedToFloat_arrL(DFT_fx[1], DFT[1], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX); + fixedToFloat_arrL( DFT_fx[0], DFT[0], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX ); + fixedToFloat_arrL( DFT_fx[1], DFT[1], hCPE->hStereoDft->q_dft, STEREO_DFT_BUF_MAX ); /* DFT stereo CNG */ #ifndef IVAS_FLOAT_FIXED stereo_dtf_cng( hCPE, ivas_total_brate, DFT, output_frame ); #else { - Word16 q_dft, q_smoothed_psd; - float max_val = 0.0; - int i_max_val =0, i_max_val_psd = 0; + Word16 q_dft; #if 0 + Word16 q_smoothed_psd; + float max_val = 0.0; + int i_max_val = 0, i_max_val_psd = 0; for (int ii = 0; ii < sizeof(DFT) / sizeof(DFT[0]); ii++) { for (int jj = 0; jj < sizeof(DFT[0]) / sizeof(DFT[0][0]); jj++) @@ -864,8 +789,8 @@ ivas_error ivas_cpe_dec_fx( #endif q_dft = hCPE->hStereoDft->q_dft; - //hCPE->hStereoDft->q_dft = norm_l(i_max_val); - //IF (hCPE->hStereoDft->q_dft > Q8) + // hCPE->hStereoDft->q_dft = norm_l(i_max_val); + // IF (hCPE->hStereoDft->q_dft > Q8) //{ // hCPE->hStereoDft->q_dft = Q8; //} @@ -885,16 +810,16 @@ ivas_error ivas_cpe_dec_fx( stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft ); - fixedToFloat_arrL(&hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[0], - &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[0], - hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel, - FFTCLDFBLEN); - //fixedToFloat_arrL(&sts[0]->hFdCngDec->smoothed_psd_fx[0], &sts[0]->hFdCngDec->smoothed_psd[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); - fixedToFloat_arr(&hCPE->hStereoCng->coh_fx[0], &hCPE->hStereoCng->coh[0], Q15, sizeof(hCPE->hStereoCng->coh_fx) / sizeof(hCPE->hStereoCng->coh_fx[0]) ); + fixedToFloat_arrL( &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[0], + &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[0], + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel, + FFTCLDFBLEN ); + // fixedToFloat_arrL(&sts[0]->hFdCngDec->smoothed_psd_fx[0], &sts[0]->hFdCngDec->smoothed_psd[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); + fixedToFloat_arr( &hCPE->hStereoCng->coh_fx[0], &hCPE->hStereoCng->coh[0], Q15, sizeof( hCPE->hStereoCng->coh_fx ) / sizeof( hCPE->hStereoCng->coh_fx[0] ) ); fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); - //fixedToFloat_arr(&hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0], &hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0], Q15, sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG) / sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0])); - //fixedToFloat_arrL(sts[0]->hFdCngDec->bandNoiseShape, sts[0]->hFdCngDec->bandNoiseShape_float, Q31 - sts[0]->hFdCngDec->bandNoiseShape_exp, FFTLEN2); - fixedToFloat_arrL(&DFT_fx[0][0], &DFT[0][0], q_dft, sizeof(DFT) / sizeof(DFT[0][0])); + // fixedToFloat_arr(&hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0], &hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0], Q15, sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG) / sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0])); + // fixedToFloat_arrL(sts[0]->hFdCngDec->bandNoiseShape, sts[0]->hFdCngDec->bandNoiseShape_float, Q31 - sts[0]->hFdCngDec->bandNoiseShape_exp, FFTLEN2); + fixedToFloat_arrL( &DFT_fx[0][0], &DFT[0][0], q_dft, sizeof( DFT ) / sizeof( DFT[0][0] ) ); } #endif @@ -902,11 +827,10 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->nchan_out, 1 ) ) { #if 1 - float l_hb_nrg = 0.0, l_hb_nrg_subr = 0.0; - float max_val = 0.0; - int i_max_val = 0, i_max_val_psd; - + float l_hb_nrg = 0.0, l_hb_nrg_subr = 0.0; #if 0 + float max_val = 0.0; + int i_max_val = 0, i_max_val_psd; //for (int ii = 0; ii < sizeof(sts[0]->hFdCngDec->smoothed_psd) / sizeof(sts[0]->hFdCngDec->smoothed_psd[0]); ii++) //{ // if (max_val < fabs(sts[0]->hFdCngDec->smoothed_psd[ii])) @@ -1023,10 +947,10 @@ ivas_error ivas_cpe_dec_fx( ELSE { float l_hb_nrg = 0.0, l_hb_nrg_subr = 0.0; - float max_val = 0.0; - int i_max_val = 0, i_max_val_psd; { #if 0 + float max_val = 0.0; + int i_max_val = 0, i_max_val_psd; //for (int ii = 0; ii < sizeof(sts[0]->hFdCngDec->smoothed_psd) / sizeof(sts[0]->hFdCngDec->smoothed_psd[0]); ii++) //{ // if (max_val < fabs(sts[0]->hFdCngDec->smoothed_psd[ii])) @@ -1063,85 +987,88 @@ ivas_error ivas_cpe_dec_fx( hCPE->hStereoDft->q_dft = 0; } #endif - IF (EQ_16(hCPE->hStereoDft->first_frame, 1)) + IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; - FOR (int ii = 0; ii < sizeof(hCPE->hStereoDft->q_DFT_past_DMX_fx) / sizeof(hCPE->hStereoDft->q_DFT_past_DMX_fx[0]); ii++) + FOR( int ii = 0; ii < sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ); ii++ ) { - hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; } hCPE->hStereoDft->first_frame = 0; } // sts[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(sts[0]->hFdCngDec->cna_rescale_fact, 15); - //floatToFixed_arrL(&sts[0]->hFdCngDec->smoothed_psd[0], &sts[0]->hFdCngDec->smoothed_psd_fx[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); - floatToFixed_arrL(&DFT[0][0], &DFT_fx[0][0], hCPE->hStereoDft->q_dft , sizeof(DFT) / sizeof(DFT[0][0])); - floatToFixed_arrL(&hCPE->hStereoDft->res_cod_mem[0], &hCPE->hStereoDft->res_cod_mem_fx[0], hCPE->hStereoDft->q_dft, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); - for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) + // floatToFixed_arrL(&sts[0]->hFdCngDec->smoothed_psd[0], &sts[0]->hFdCngDec->smoothed_psd_fx[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); + floatToFixed_arrL( &DFT[0][0], &DFT_fx[0][0], hCPE->hStereoDft->q_dft, sizeof( DFT ) / sizeof( DFT[0][0] ) ); + floatToFixed_arrL( &hCPE->hStereoDft->res_cod_mem[0], &hCPE->hStereoDft->res_cod_mem_fx[0], hCPE->hStereoDft->q_dft, sizeof( hCPE->hStereoDft->res_cod_mem_fx ) / sizeof( hCPE->hStereoDft->res_cod_mem_fx[0] ) ); + for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) { - if (l_hb_nrg_subr < hCPE->hStereoDft->hb_nrg_subr[ii]) + if ( l_hb_nrg_subr < hCPE->hStereoDft->hb_nrg_subr[ii] ) { l_hb_nrg_subr = hCPE->hStereoDft->hb_nrg_subr[ii]; } } hCPE->hStereoDft->q_hb_nrg_subr = 0; - if (l_hb_nrg_subr > (float)MAX_32) + if ( l_hb_nrg_subr > (float) MAX_32 ) { - int quotient = (int) ceil(l_hb_nrg_subr / (float)MAX_32); - hCPE->hStereoDft->q_hb_nrg_subr = Q31 - norm_l(quotient); + int quotient = (int) ceil( l_hb_nrg_subr / (float) MAX_32 ); + hCPE->hStereoDft->q_hb_nrg_subr = Q31 - norm_l( quotient ); } - for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) + for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) { - hCPE->hStereoDft->hb_nrg_subr_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg_subr[ii] / ((float)(1 << hCPE->hStereoDft->q_hb_nrg_subr))); + hCPE->hStereoDft->hb_nrg_subr_fx[ii] = (Word32) ( hCPE->hStereoDft->hb_nrg_subr[ii] / ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg_subr ) ) ); } - for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_fx) / sizeof(hCPE->hStereoDft->hb_nrg_fx[0]); ii++) + for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_fx[0] ); ii++ ) { - if (l_hb_nrg < hCPE->hStereoDft->hb_nrg[ii]) + if ( l_hb_nrg < hCPE->hStereoDft->hb_nrg[ii] ) { l_hb_nrg = hCPE->hStereoDft->hb_nrg[ii]; } } hCPE->hStereoDft->q_hb_nrg = 0; - if (l_hb_nrg > (float)MAX_32) + if ( l_hb_nrg > (float) MAX_32 ) { - int quotient = (int) ceil(l_hb_nrg / (float)MAX_32); - hCPE->hStereoDft->q_hb_nrg = Q31 - norm_l(quotient); + int quotient = (int) ceil( l_hb_nrg / (float) MAX_32 ); + hCPE->hStereoDft->q_hb_nrg = Q31 - norm_l( quotient ); } - for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_fx) / sizeof(hCPE->hStereoDft->hb_nrg_fx[0]); ii++) + for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_fx[0] ); ii++ ) { - hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg[ii] / ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); + hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32) ( hCPE->hStereoDft->hb_nrg[ii] / ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg ) ) ); } - //floatToFixed_arr(&sts[0]->hFdCngDec->cna_cm[0], &sts[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); - floatToFixed_arr(&hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof(hCPE->hStereoCng->cm_fx) / sizeof(hCPE->hStereoCng->cm_fx[0])); - //floatToFixed_arr(&sts[0]->hFdCngDec->cna_g_state[0], &sts[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); + // floatToFixed_arr(&sts[0]->hFdCngDec->cna_cm[0], &sts[0]->hFdCngDec->cna_cm_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); + floatToFixed_arr( &hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); + // floatToFixed_arr(&sts[0]->hFdCngDec->cna_g_state[0], &sts[0]->hFdCngDec->cna_g_state_fx[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); } stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); { // sts[0]->hFdCngDec->cna_rescale_fact = fixedToFloat(sts[0]->hFdCngDec->cna_rescale_fact_fx, 15); - //fixedToFloat_arrL(&sts[0]->hFdCngDec->smoothed_psd_fx[0], &sts[0]->hFdCngDec->smoothed_psd[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); - fixedToFloat_arrL(&DFT_fx[0][0], &DFT[0][0], hCPE->hStereoDft->q_dft , sizeof(DFT) / sizeof(DFT[0][0])); - for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) + // fixedToFloat_arrL(&sts[0]->hFdCngDec->smoothed_psd_fx[0], &sts[0]->hFdCngDec->smoothed_psd[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); + fixedToFloat_arrL( &DFT_fx[0][0], &DFT[0][0], hCPE->hStereoDft->q_dft, sizeof( DFT ) / sizeof( DFT[0][0] ) ); + for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) { - hCPE->hStereoDft->hb_nrg_subr[0] = ((float)hCPE->hStereoDft->hb_nrg_subr_fx[0] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg_subr))); + hCPE->hStereoDft->hb_nrg_subr[0] = ( (float) hCPE->hStereoDft->hb_nrg_subr_fx[0] * ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg_subr ) ) ); } - for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_fx) / sizeof(hCPE->hStereoDft->hb_nrg_fx[0]); ii++) + for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_fx[0] ); ii++ ) { - hCPE->hStereoDft->hb_nrg[ii] = ((float)hCPE->hStereoDft->hb_nrg_fx[ii] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); + hCPE->hStereoDft->hb_nrg[ii] = ( (float) hCPE->hStereoDft->hb_nrg_fx[ii] * ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg ) ) ); } - //fixedToFloat_arr(&sts[0]->hFdCngDec->cna_cm_fx[0], &sts[0]->hFdCngDec->cna_cm[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); - fixedToFloat_arr(&hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof(hCPE->hStereoCng->cm_fx) / sizeof(hCPE->hStereoCng->cm_fx[0])); - //fixedToFloat_arr(&sts[0]->hFdCngDec->cna_g_state_fx[0], &sts[0]->hFdCngDec->cna_g_state[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); - fixedToFloat_arrL(&hCPE->hStereoDft->td_gain_fx[0], &hCPE->hStereoDft->td_gain[0], Q15, sizeof(hCPE->hStereoDft->td_gain_fx) / sizeof(hCPE->hStereoDft->td_gain_fx[0])); - fixedToFloat_arrL(&hCPE->hStereoDft->res_cod_mem_fx[0], &hCPE->hStereoDft->res_cod_mem[0], hCPE->hStereoDft->q_dft, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); + // fixedToFloat_arr(&sts[0]->hFdCngDec->cna_cm_fx[0], &sts[0]->hFdCngDec->cna_cm[0], Q15, sizeof(sts[0]->hFdCngDec->cna_cm_fx) / sizeof(sts[0]->hFdCngDec->cna_cm_fx[0])); + fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); + // fixedToFloat_arr(&sts[0]->hFdCngDec->cna_g_state_fx[0], &sts[0]->hFdCngDec->cna_g_state[0], Q15, sizeof(sts[0]->hFdCngDec->cna_g_state_fx) / sizeof(sts[0]->hFdCngDec->cna_g_state_fx[0])); + fixedToFloat_arrL( &hCPE->hStereoDft->td_gain_fx[0], &hCPE->hStereoDft->td_gain[0], Q15, sizeof( hCPE->hStereoDft->td_gain_fx ) / sizeof( hCPE->hStereoDft->td_gain_fx[0] ) ); + fixedToFloat_arrL( &hCPE->hStereoDft->res_cod_mem_fx[0], &hCPE->hStereoDft->res_cod_mem[0], hCPE->hStereoDft->q_dft, sizeof( hCPE->hStereoDft->res_cod_mem_fx ) / sizeof( hCPE->hStereoDft->res_cod_mem_fx[0] ) ); } } FOR( n = 0; n < hCPE->nchan_out; n++ ) { - Scale_sig32( output[n], L_FRAME48k, hCPE->hStereoDft->q_dft - Q11 ); + Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[n], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; + move16(); } /* synthesis iFFT */ @@ -1150,44 +1077,43 @@ ivas_error ivas_cpe_dec_fx( #ifndef IVAS_FLOAT_FIXED stereo_dft_dec_synthesize( hCPE, DFT, n, output_flt[n], output_frame ); #else - hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; - //hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); - floatToFixed_arrL(&DFT[n][0], &DFT_fx[n][0],hCPE->hStereoDft->q_dft, sizeof(DFT[n]) / sizeof(DFT[0][0])); - floatToFixed_arrL(&hCPE->output_mem[n][0], &hCPE->output_mem_fx[n][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); + floatToFixed_arrL( &DFT[n][0], &DFT_fx[n][0], hCPE->hStereoDft->q_dft, sizeof( DFT[n] ) / sizeof( DFT[0][0] ) ); + stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame ); - fixedToFloat_arrL(&hCPE->output_mem_fx[n][0], &hCPE->output_mem[n][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); - fixedToFloat_arrL(&DFT_fx[n][0], &DFT[n][0],hCPE->hStereoDft->q_dft, sizeof(DFT_fx[n]) / sizeof(DFT_fx[0][0])); - //hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); + + fixedToFloat_arrL( &DFT_fx[n][0], &DFT[n][0], hCPE->hStereoDft->q_dft, sizeof( DFT_fx[n] ) / sizeof( DFT_fx[0][0] ) ); #endif } - //delete below + // delete below FOR( n = 0; n < hCPE->nchan_out; n++ ) { - Scale_sig32( output[n], L_FRAME48k, Q11 - hCPE->hStereoDft->q_dft); - } - for (int j = 0; j < output_frame; j++) - { - outputHB_fx[0][j] = (Word32)(outputHB[0][j] * (1 << *q_output)); - outputHB_fx[1][j] = (Word32)(outputHB[1][j] * (1 << *q_output)); + Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[n], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + hCPE->q_output_mem_fx[n] = Q11; + move16(); } } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { + test(); IF( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && sts[0]->tdm_LRTD_flag ) { hCPE->hStereoTD->tdm_last_ratio_idx = tdm_ratio_idx; + move16(); } /* TD stereo upmixing */ - stereo_tdm_combine_fx(hCPE, output[0], output[1], output_frame, 0, tdm_ratio_idx); + stereo_tdm_combine_fx( hCPE, output[0], output[1], output_frame, 0, tdm_ratio_idx ); IF( sts[0]->tdm_LRTD_flag ) { - stereo_tdm_combine_fx(hCPE, outputHB_fx[0], outputHB_fx[1], output_frame, 0, tdm_ratio_idx); + stereo_tdm_combine_fx( hCPE, outputHB_fx[0], outputHB_fx[1], output_frame, 0, tdm_ratio_idx ); } hCPE->hStereoCng->last_tdm_idx = hCPE->hStereoTD->tdm_last_ratio_idx; + move16(); hCPE->hStereoTD->tdm_last_ratio_idx = tdm_ratio_idx; + move16(); IF( EQ_16( hCPE->nchan_out, 1 ) ) { @@ -1197,6 +1123,7 @@ ivas_error ivas_cpe_dec_fx( FOR( i = 0; i < output_frame; i++ ) { output[0][i] = L_shr( L_add( output[0][i], output[1][i] ), 1 ); + move32(); } } } @@ -1204,15 +1131,15 @@ ivas_error ivas_cpe_dec_fx( /*----------------------------------------------------------------* * Update parameters for stereo CNA *----------------------------------------------------------------*/ - //Delete below - IF(hCPE->hStereoDft != NULL) + // Delete below + IF( hCPE->hStereoDft != NULL ) { - Word16 q_td_gain = Q_factor_arr(hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX); - floatToFixed_arrL(hCPE->hStereoDft->td_gain, hCPE->hStereoDft->td_gain_fx, q_td_gain, STEREO_DFT_CORE_HIST_MAX); // Checking this. + Word16 q_td_gain = Q_factor_arr( hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); + floatToFixed_arrL( hCPE->hStereoDft->td_gain, hCPE->hStereoDft->td_gain_fx, q_td_gain, STEREO_DFT_CORE_HIST_MAX ); // Checking this. } //////Till here - //stereo_cna_update_params( hCPE, output_flt, output_frame, tdm_ratio_idx ); + // stereo_cna_update_params( hCPE, output_flt, output_frame, tdm_ratio_idx ); stereo_cna_update_params_fx( hCPE, output, output_frame, tdm_ratio_idx ); /*----------------------------------------------------------------* @@ -1221,155 +1148,34 @@ ivas_error ivas_cpe_dec_fx( IF( !st_ivas->sba_dirac_stereo_flag ) { - // Delete below - Word16 output_q = OUTPUT_Q; - FOR( Word32 n = 0; n < CPE_CHANNELS; n++ ) - { - IF( hCPE->hStereoDft != NULL ) - { - IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); - } - } - } - IF( hCPE->hCoreCoder[n] != NULL ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - //hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - //hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); - } - } - - //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) - //{ - // hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->prev_synth_buffer[k] * ( 1 << output_q ) ); - //} - //FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - //{ - // hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << output_q ) ); - //} - IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - //hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1 << output_q ) ); - } - } - } - - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->output_mem_fx[n][k] = (Word32) ( hCPE->output_mem[n][k] * ( 1 << output_q ) ); - } - } - IF( hCPE->input_mem[n] != NULL ) - { - FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - { - hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << output_q ) ); - } - } - - //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - //{ - // hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << output_q ) ); - //} - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); - } - } - //till here + // Delete below + Word16 output_q = OUTPUT_Q; + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); + } + } + // till here - synchro_synthesis_fx( ivas_total_brate, hCPE, output, output_frame, 0 ); + synchro_synthesis_fx( ivas_total_brate, hCPE, output, output_frame, 0 ); - // delete the below - IF( hCPE->hStereoDft != NULL ) - { - IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); - } - } - } - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); - } - } - IF( hCPE->hCoreCoder[n] != NULL ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - //hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - //hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); - } - } - //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) - //{ - // hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); - //} - //FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - //{ - // hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); - //} - IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - //hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << output_q ); - } - } - } - IF( hCPE->input_mem[n] != NULL ) - { - FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - { - hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); - } - } - //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - //{ - // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); - //} - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); - } - } - // till here + // delete the below + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); + } + } + // till here } + test(); + test(); + test(); + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && EQ_16( is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ), 0 ) ) ) ) { applyDmxMdctStereo_fx( hCPE, output, output_frame ); @@ -1379,7 +1185,7 @@ ivas_error ivas_cpe_dec_fx( * IC-BWE: output LB and HB mix in ACELP mode *----------------------------------------------------------------*/ - stereo_icBWE_decproc_fx(hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame, *q_output); + stereo_icBWE_decproc_fx( hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame, *q_output ); smooth_dft2td_transition_fx( hCPE, output, output_frame ); @@ -1387,13 +1193,13 @@ ivas_error ivas_cpe_dec_fx( * Temporal ICA, stereo adjustment and upmix *----------------------------------------------------------------*/ - stereo_tca_dec_fx(hCPE, output, output_frame); + stereo_tca_dec_fx( hCPE, output, output_frame ); - //delete below - IF(hCPE->hStereoDft != NULL) + // delete below + IF( hCPE->hStereoDft != NULL ) { - Word16 q_td_gain = Q_factor_arr(hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX); - fixedToFloat_arrL(hCPE->hStereoDft->td_gain_fx, hCPE->hStereoDft->td_gain, q_td_gain, STEREO_DFT_CORE_HIST_MAX); // Checking this. + Word16 q_td_gain = Q_factor_arr( hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX ); + fixedToFloat_arrL( hCPE->hStereoDft->td_gain_fx, hCPE->hStereoDft->td_gain, q_td_gain, STEREO_DFT_CORE_HIST_MAX ); // Checking this. } /*----------------------------------------------------------------* @@ -1401,13 +1207,17 @@ ivas_error ivas_cpe_dec_fx( *----------------------------------------------------------------*/ hCPE->last_element_brate = hCPE->element_brate; + move32(); hCPE->last_element_mode = hCPE->element_mode; + move32(); - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { hCPE->element_brate = element_brate_ref; + move32(); } + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { stereo_cng_dec_update( hCPE, ivas_total_brate ); @@ -1416,6 +1226,32 @@ ivas_error ivas_cpe_dec_fx( st_ivas->BER_detect = s_or( st_ivas->BER_detect, sts[0]->BER_detect ); st_ivas->BER_detect = s_or( st_ivas->BER_detect, sts[1]->BER_detect ); +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + fixedToFloat_arrL( hCPE->output_mem_fx[n], hCPE->output_mem[n], q_common, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ) ); + } + IF( hCPE->input_mem_LB[n] != NULL ) + { + fixedToFloat_arrL( hCPE->input_mem_LB_fx[n], hCPE->input_mem_LB[n], q_common, STEREO_DFT32MS_OVL_16k ); + } + if (hCPE->input_mem[n] != NULL) + { + fixedToFloat_arrL(&hCPE->input_mem_fx[n][0], &hCPE->input_mem[n][0], q_common, NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS)); + } + if (hCPE->input_mem_BPF[0] != NULL) + { + fixedToFloat_arrL(hCPE->input_mem_BPF_fx[0], hCPE->input_mem_BPF[0], q_common, STEREO_DFT32MS_OVL_16k); + } + } + IF( hCPE->hStereoDft != NULL ) + { + fixedToFloat_arrL( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->hStereoDft->buff_LBTCX_mem, q_common, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); + } +#endif + pop_wmops(); return error; } @@ -1916,9 +1752,11 @@ static void read_stereo_mode_and_bwidth_fx( * BFI or NO_DATA frame: Use stereo parameters from last (active) frame *-----------------------------------------------------------------*/ + test(); IF( st_ivas->bfi || LT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { hCPE->element_mode = hCPE->last_element_mode; + move16(); } /*-----------------------------------------------------------------* @@ -1931,41 +1769,46 @@ static void read_stereo_mode_and_bwidth_fx( { case SID_DFT_STEREO: hCPE->element_mode = IVAS_CPE_DFT; + move16(); /* Read CNG type */ - hCPE->hCoreCoder[0]->cng_type = get_next_indice( hCPE->hCoreCoder[0], 1 ); + hCPE->hCoreCoder[0]->cng_type = get_next_indice_fx( hCPE->hCoreCoder[0], 1 ); /* Read BW information in SID */ - hCPE->hCoreCoder[0]->bwidth = get_next_indice( hCPE->hCoreCoder[0], 2 ); + hCPE->hCoreCoder[0]->bwidth = get_next_indice_fx( hCPE->hCoreCoder[0], 2 ); BREAK; case SID_MDCT_STEREO: /* 2TC SBA DTX also uses MDCT-Stereo DTX */ case SID_SBA_2TC: hCPE->element_mode = IVAS_CPE_MDCT; + move16(); BREAK; case SID_SBA_1TC: assert( !"Forbidden value for SID format in CPE (SBA 1TC), should have already been adressed earlier" ); BREAK; case SID_MASA_1TC: hCPE->element_mode = IVAS_SCE; + move16(); BREAK; case SID_MASA_2TC: /* 2TC MASA DTX uses MDCT or DFT based core */ IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { hCPE->element_mode = IVAS_CPE_DFT; + move16(); } IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /* Read CNG type */ - hCPE->hCoreCoder[0]->cng_type = get_next_indice( hCPE->hCoreCoder[0], 1 ); + hCPE->hCoreCoder[0]->cng_type = get_next_indice_fx( hCPE->hCoreCoder[0], 1 ); /* Read BW information in SID */ - hCPE->hCoreCoder[0]->bwidth = get_next_indice( hCPE->hCoreCoder[0], 2 ); + hCPE->hCoreCoder[0]->bwidth = get_next_indice_fx( hCPE->hCoreCoder[0], 2 ); } BREAK; default: /* this is what has been done for all modes previously, may need adaptation in the future */ hCPE->element_mode = hCPE->last_element_mode; + move16(); BREAK; } } @@ -1977,35 +1820,42 @@ static void read_stereo_mode_and_bwidth_fx( ELSE { sts = hCPE->hCoreCoder; + test(); IF( st_ivas->hMCT && NE_16( hCPE->cpe_id, 0 ) ) { sts[0]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth; + move16(); sts[1]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth; + move16(); } ELSE { /* read stereo technology info */ + test(); IF( LT_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) && st_ivas->hMCT == NULL ) { - hCPE->element_mode = add( get_next_indice( sts[0], NBITS_ELEMENT_MODE ), IVAS_CPE_DFT ); + hCPE->element_mode = add( get_next_indice_fx( sts[0], NBITS_ELEMENT_MODE ), IVAS_CPE_DFT ); } ELSE { hCPE->element_mode = IVAS_CPE_MDCT; + move16(); } /* read the bandwidth */ IF( LT_32( hCPE->element_brate, MIN_BRATE_FB_STEREO ) ) { /* WB and SWB are supported */ - sts[0]->bwidth = add( get_next_indice( sts[0], 1 ), WB ); + sts[0]->bwidth = add( get_next_indice_fx( sts[0], 1 ), WB ); sts[1]->bwidth = sts[0]->bwidth; + move16(); } ELSE { /* WB, SWB and FB are supported */ - sts[0]->bwidth = get_next_indice( sts[0], NBITS_BWIDTH ); + sts[0]->bwidth = get_next_indice_fx( sts[0], NBITS_BWIDTH ); sts[1]->bwidth = sts[0]->bwidth; + move16(); } } } @@ -2027,30 +1877,38 @@ static void stereo_mode_combined_format_dec_fx( { Word32 element_brate_ref; - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { element_brate_ref = hCPE->element_brate; + move32(); - IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && ( ( EQ_16( st_ivas->nchan_ism, 3 ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_96k ) ) || ( EQ_16( st_ivas->nchan_ism, 4 ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_128k ) ) ) ) { IF( !st_ivas->bfi ) { /* read OMASA stereo mode signalling */ - IF( get_next_indice( hCPE->hCoreCoder[0], NBITS_ELEMENT_MODE ) ) + IF( get_next_indice_fx( hCPE->hCoreCoder[0], NBITS_ELEMENT_MODE ) ) { hCPE->element_mode = IVAS_CPE_MDCT; + move16(); } ELSE { hCPE->element_mode = IVAS_CPE_DFT; + move16(); } } IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { hCPE->element_brate = IVAS_64k; + move32(); hCPE->brate_surplus = L_sub( hCPE->brate_surplus, L_sub( hCPE->element_brate, element_brate_ref ) ); } } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 8a64bf714..344465320 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -879,21 +879,21 @@ static ivas_error ivas_dirac_rend_config_fx( { FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set16_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); } } IF( hDirACRend->buffer_energy_fx == NULL ) { - IF( ( hDirACRend->buffer_energy_fx = (Word16 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set16_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); + set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); #ifdef TRUE for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { @@ -3601,8 +3601,8 @@ void ivas_dirac_dec_render_sf( int16_t index, num_freq_bands; /* local copies of azi, ele, diffuseness */ - int16_t azimuth[CLDFB_NO_CHANNELS_MAX]; - int16_t elevation[CLDFB_NO_CHANNELS_MAX]; + Word16 azimuth[CLDFB_NO_CHANNELS_MAX]; + Word16 elevation[CLDFB_NO_CHANNELS_MAX]; float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; #ifdef IVAS_FLOAT_FIXED Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX]; @@ -3749,7 +3749,8 @@ void ivas_dirac_dec_render_sf( { st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth, st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_q ); st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth, st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_q ); - st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); + f2me( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth, &st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx, &st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth, st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_q ); } @@ -3788,17 +3789,17 @@ void ivas_dirac_dec_render_sf( ELSE { floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); - IF(hDirACRend->masa_stereo_type_detect) - { - IF(hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db == -INFINITY) - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = MIN_32; - } - ELSE - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = floatToFixed(hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db, Q21); - } - } + IF( hDirACRend->masa_stereo_type_detect ) + { + IF( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db == -INFINITY ) + { + hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = MIN_32; + } + ELSE + { + hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db, Q21 ); + } + } } BREAK; case 1: @@ -3806,6 +3807,23 @@ void ivas_dirac_dec_render_sf( BREAK; } } + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) + { + Word16 val = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + FOR( i = 0; i < 32; i++ ) + { + Word16 exp1 = 0, exp2 = 0, exp3 = 0; + f2me_buf( hDirACRend->buffer_intensity_real[0][i], hDirACRend->buffer_intensity_real_fx[0][i], &exp1, hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + f2me_buf( hDirACRend->buffer_intensity_real[1][i], hDirACRend->buffer_intensity_real_fx[1][i], &exp2, hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + f2me_buf( hDirACRend->buffer_intensity_real[2][i], hDirACRend->buffer_intensity_real_fx[2][i], &exp3, hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + hDirACRend->q_buffer_intensity_real[i] = sub( 31, s_max( s_max( exp1, exp2 ), exp3 ) ); + scale_sig32( hDirACRend->buffer_intensity_real_fx[0][i], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band], sub( hDirACRend->q_buffer_intensity_real[i], sub( 31, exp1 ) ) ); + scale_sig32( hDirACRend->buffer_intensity_real_fx[1][i], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band], sub( hDirACRend->q_buffer_intensity_real[i], sub( 31, exp2 ) ) ); + scale_sig32( hDirACRend->buffer_intensity_real_fx[2][i], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band], sub( hDirACRend->q_buffer_intensity_real[i], sub( 31, exp3 ) ) ); + f2me_buf( &hDirACRend->buffer_energy[i * hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]], &hDirACRend->buffer_energy_fx[i * hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]], &hDirACRend->q_buffer_energy[i], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + hDirACRend->q_buffer_energy[i] = sub( 31, hDirACRend->q_buffer_energy[i] ); + } + } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); @@ -4191,6 +4209,54 @@ void ivas_dirac_dec_render_sf( } } + /*-----------------------------------------------------------------* + * Compute DirAC parameters at decoder side + *-----------------------------------------------------------------*/ + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) + { + Copy( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) ); + Copy( &hSpatParamRendCom->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) ); + IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + { + num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + move16(); + rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx ); + } + + /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */ + IF( EQ_16( hDirACRend->index_buffer_intensity, 0 ) ) + { + hDirACRend->index_buffer_intensity = 1; + } + ELSE + { + hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( idiv1616( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */ + } + + index = hDirACRend->index_buffer_intensity; + move16(); + num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + move16(); + + computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + q_cldfb, num_freq_bands, + hDirACRend->buffer_intensity_real_fx[0][sub( index, 1 )], + hDirACRend->buffer_intensity_real_fx[1][sub( index, 1 )], + hDirACRend->buffer_intensity_real_fx[2][sub( index, 1 )], + &hDirACRend->q_buffer_intensity_real[sub( index, 1 )] ); + + computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][sub( index, 1 )], + hDirACRend->buffer_intensity_real_fx[1][sub( index, 1 )], + hDirACRend->buffer_intensity_real_fx[2][sub( index, 1 )], + hDirACRend->q_buffer_intensity_real[sub( index, 1 )], + num_freq_bands, azimuth, elevation ); + + Copy32( reference_power_fix, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); + hDirACRend->q_buffer_energy[sub( index, 1 )] = DirAC_mem.reference_power_q; + move16(); + + computeDiffuseness_fixed( hDirACRend->buffer_intensity_real_fx, hDirACRend->buffer_energy_fx, num_freq_bands, hSpatParamRendCom->diffuseness_vector_fx[md_idx], hDirACRend->q_buffer_intensity_real, hDirACRend->q_buffer_energy, &hSpatParamRendCom->q_diffuseness_vector ); + } ////////////////////////////////////////////// to be removed /////////////////////////////////////////////////////////////// IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) && EQ_16( slot_idx, 0 ) ) { @@ -4256,7 +4322,7 @@ void ivas_dirac_dec_render_sf( fixedToFloat_arrL32( Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][slot_idx], Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1][slot_idx], Q6, CLDFB_NO_CHANNELS_MAX ); st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_q ); st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_q ); - st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth = me2f( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ) ); st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_q ); } @@ -4328,7 +4394,14 @@ void ivas_dirac_dec_render_sf( BREAK; } } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) + { + fixedToFloat_arrL32( hDirACRend->buffer_intensity_real_fx[0][index - 1], hDirACRend->buffer_intensity_real[0][index - 1], hDirACRend->q_buffer_intensity_real[index - 1], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + fixedToFloat_arrL32( hDirACRend->buffer_intensity_real_fx[1][index - 1], hDirACRend->buffer_intensity_real[1][index - 1], hDirACRend->q_buffer_intensity_real[index - 1], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + fixedToFloat_arrL32( hDirACRend->buffer_intensity_real_fx[2][index - 1], hDirACRend->buffer_intensity_real[2][index - 1], hDirACRend->q_buffer_intensity_real[index - 1], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + fixedToFloat_arrL32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->diffuseness_vector[md_idx], hSpatParamRendCom->q_diffuseness_vector, hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + fixedToFloat_arrL32( &hDirACRend->buffer_energy_fx[( index - 1 ) * num_freq_bands], &hDirACRend->buffer_energy[( index - 1 ) * num_freq_bands], hDirACRend->q_buffer_energy[index - 1], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); + } #else float dirEne; float surCohEner; @@ -4820,7 +4893,6 @@ void ivas_dirac_dec_render_sf( return; } } -#endif /*-----------------------------------------------------------------* * Compute DirAC parameters at decoder side @@ -4860,7 +4932,7 @@ void ivas_dirac_dec_render_sf( computeDiffuseness( hDirACRend->buffer_intensity_real, hDirACRend->buffer_energy, num_freq_bands, hSpatParamRendCom->diffuseness_vector[md_idx] ); } - +#endif /*-----------------------------------------------------------------* * frequency domain decorrelation diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 82b54b48d..11a4f80ce 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1387,7 +1387,7 @@ ivas_error ivas_masa_decode_fx( create_masa_ext_out_meta_fx( hMasa, hQMetaData, st_ivas->nchan_transport ); } -#if 1 /* fix to float */ +#if 0 /* fix to float */ if ( st_ivas->hSpatParamRendCom != NULL ) { for ( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index dd50a7ff1..c11abc9a2 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -539,103 +539,7 @@ ivas_error ivas_mct_dec( { if ( st_ivas->sba_dirac_stereo_flag && ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ) { -#ifdef IVAS_FLOAT_FIXED - Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 q = 11; - for ( int p = 0; p < L_FRAME48k; p++ ) - { - synth_fx[n][p] = (Word32) ( synth[n][p] * ( 1u << q ) ); - - if ( p < NS2SA( hCPE->hCoreCoder[n]->output_Fs, STEREO_DFT32MS_OVL_NS ) ) - { - hCPE->output_mem_fx[0][p] = (Word32) ( hCPE->output_mem[0][p] * ( 1u << q ) ); - hCPE->output_mem_fx[1][p] = (Word32) ( hCPE->output_mem[1][p] * ( 1u << q ) ); - } - - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); - } - } - if ( !( NE_16( hCPE->hCoreCoder[n]->core, TCX_20_CORE ) && NE_16( hCPE->hCoreCoder[n]->core, TCX_10_CORE ) ) ) - { - for ( int k = 0; k < output_frame; k++ ) - { - hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->hHQ_core->old_out[k] * ( 1u << q ) ); - //if ( k < 111 ) - //{ - // hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1u << q ) ); - //} - if ( k < HQ_DELTA_MAX * HQ_DELAY_COMP ) - { - hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1u << q ) ); - } - } - } - if ( !( ( hCPE->hCoreCoder[n]->element_mode != IVAS_CPE_DFT && !( st_ivas->sba_dirac_stereo_flag && hCPE->hCoreCoder[n]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[n]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) - { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); - } - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - //for ( int p = 0; p < 111; p++ ) - //{ - // hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[p] * ( 1u << q ) ); - //} - - ivas_post_proc_fx( NULL, hCPE, n, synth_fx[n], NULL, output_frame, 1 ); - - for ( int p = 0; p < L_FRAME48k; p++ ) - { - synth[n][p] = (float) synth_fx[n][p] / ( 1u << q ); - - if ( p < NS2SA( hCPE->hCoreCoder[n]->output_Fs, STEREO_DFT32MS_OVL_NS ) ) - { - hCPE->output_mem[0][p] = (float) hCPE->output_mem_fx[0][p] / ( 1u << q ); - hCPE->output_mem[1][p] = (float) hCPE->output_mem_fx[1][p] / ( 1u << q ); - } - - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); - } - } - //if ( !( NE_16( hCPE->hCoreCoder[n]->core, TCX_20_CORE ) && NE_16( hCPE->hCoreCoder[n]->core, TCX_10_CORE ) ) ) - //{ - // for ( int k = 0; k < 111; k++ ) - // { - // hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1u << q ); - // } - //} - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - if ( !( ( hCPE->hCoreCoder[n]->element_mode != IVAS_CPE_DFT && !( st_ivas->sba_dirac_stereo_flag && hCPE->hCoreCoder[n]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[n]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) - { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); - } - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - } -#else ivas_post_proc( NULL, hCPE, n, synth[n], NULL, output_frame, 1 ); -#endif // IVAS_FLOAT_FIXED } /* Postprocessing for ACELP/MDCT core switching and synchronization */ diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4c0440547..1ad0d9a19 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -424,14 +424,20 @@ typedef struct stereo_dec_cng int16_t nr_corr_frames; /* correlation frame counter */ int16_t nr_sid_frames; /* SID frame counter */ int16_t last_act_element_mode; /* Element mode of last active frame */ +#ifndef IVAS_FLOAT_FIXED float olapBufferSynth22[FFTLEN]; /* overlap buffer for secondary channel CNA */ +#endif Word16 olapBufferSynth22_fx[FFTLEN]; /* overlap buffer for secondary channel CNA */ Word32 olapBufferSynth22_32fx[FFTLEN]; /* overlap buffer for secondary channel CNA */ int16_t flag_cna_fade; /* flag enabling CNA fade out */ +#ifndef IVAS_FLOAT_FIXED float maskingNoiseS[L_FRAME16k]; /* masking noise (CNA) for secondary channel */ +#endif Word16 maskingNoiseS_fx[L_FRAME16k]; /* masking noise (CNA) for secondary channel */ int16_t enableSecCNA; /* flag enabling secondary channel CNA */ +#ifndef IVAS_FLOAT_FIXED float c_PS_LT; /* long term cross-correlation between primary and secondary channel */ +#endif Word16 c_PS_LT_fx; /* long term cross-correlation between primary and secondary channel */ // Assumed Q15 for initialization. Can be modified later if reqd. const int16_t *frameSize; /* Frame size in samples */ const int16_t *fftlen; /* FFT length used for the decomposition */ @@ -461,8 +467,11 @@ typedef struct stereo_td_dec_data_structure int16_t tdm_LRTD_flag; int16_t flag_skip_DMX; /* flag that indicates whether the TD downmixing is skipped */ +#ifndef IVAS_FLOAT_FIXED float TCX_old_syn_Overl[L_FRAME16k / 2]; /* past ovrl buffer for possible switching from TD stereo ACELP to MDCT stereo TCX frame */ - Word32 TCX_old_syn_Overl_fx[L_FRAME16k / 2]; /* past ovrl buffer for possible switching from TD stereo ACELP to MDCT stereo TCX frame */ +#else + Word32 TCX_old_syn_Overl_fx[L_FRAME16k / 2]; /* past ovrl buffer for possible switching from TD stereo ACELP to MDCT stereo TCX frame */ /* Q11 */ +#endif float prevSP_ratio; /* previous SP ratio */ Word32 prevSP_ratio_fx; /* previous SP ratio */ diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index de5c02b79..063908d25 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -1487,15 +1487,18 @@ void stereo_cng_dec_update( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { - IF( hCPE->hCoreCoder[0]->core_brate > SID_2k40 ) + IF( GT_32( hCPE->hCoreCoder[0]->core_brate, SID_2k40 ) ) { hCPE->hStereoCng->last_act_element_mode = hCPE->element_mode; - IF( hCPE->hStereoCng->active_frame_counter > SKIP_XFADE_FRAMES ) + move16(); + IF( GT_16( hCPE->hStereoCng->active_frame_counter, SKIP_XFADE_FRAMES ) ) { hCPE->hStereoCng->xfade_frame_counter = 0; + move16(); hCPE->hStereoCng->xfade_length = 0; + move16(); } - IF( hCPE->hStereoCng->active_frame_counter < MAX_FRAME_COUNTER ) + IF( LT_16( hCPE->hStereoCng->active_frame_counter, MAX_FRAME_COUNTER ) ) { hCPE->hStereoCng->active_frame_counter++; } @@ -1503,25 +1506,30 @@ void stereo_cng_dec_update( ELSE { hCPE->hStereoCng->active_frame_counter = 0; - IF( hCPE->hStereoCng->xfade_frame_counter < MAX_FRAME_COUNTER ) + move16(); + IF( LT_16( hCPE->hStereoCng->xfade_frame_counter, MAX_FRAME_COUNTER ) ) { hCPE->hStereoCng->xfade_frame_counter++; } } - IF( hCPE->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - IF( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) + test(); + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { hCPE->hStereoCng->prev_sid_nodata = 1; + move16(); } ELSE { hCPE->hStereoCng->prev_sid_nodata = 0; + move16(); } } hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->active_frame_counter = hCPE->hStereoCng->active_frame_counter; + move16(); return; } @@ -2344,11 +2352,13 @@ void stereo_cng_init_dec( hStereoCng->nr_dft_frames = 0; hStereoCng->nr_corr_frames = 0; hStereoCng->nr_sid_frames = 0; - set_f( hStereoCng->olapBufferSynth22, 0.0f, FFTLEN ); hStereoCng->flag_cna_fade = 0; +#ifndef IVAS_FLOAT_FIXED + set_f( hStereoCng->olapBufferSynth22, 0.0f, FFTLEN ); set_zero( hStereoCng->maskingNoiseS, L_FRAME16k ); - hStereoCng->enableSecCNA = 0; hStereoCng->c_PS_LT = 0.5f; +#endif + hStereoCng->enableSecCNA = 0; hStereoCng->frameSize = frameSize; hStereoCng->last_act_element_mode = IVAS_CPE_DFT; @@ -2393,10 +2403,10 @@ void stereo_cng_init_dec_fx( move16(); #if 1 - set_f( hStereoCng->olapBufferSynth22, 0.0f, FFTLEN ); + //set_f( hStereoCng->olapBufferSynth22, 0.0f, FFTLEN ); set_f( hStereoCng->coh, 0.5f, STEREO_DFT_BAND_MAX + 1 ); set_zero( hStereoCng->cm, STEREO_DFT_BAND_MAX ); - hStereoCng->c_PS_LT = 0.5f; + //hStereoCng->c_PS_LT = 0.5f; #endif return; diff --git a/lib_dec/ivas_stereo_ica_dec.c b/lib_dec/ivas_stereo_ica_dec.c index 3c0cf6fa8..0286ac027 100644 --- a/lib_dec/ivas_stereo_ica_dec.c +++ b/lib_dec/ivas_stereo_ica_dec.c @@ -85,19 +85,11 @@ void stereo_tca_dec_fx( { IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { -#if 0 - // to be deleted next MR - hCPE->hStereoDftDmx->targetGain = 1.0f; -#endif hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; move32(); } /* save the target gain for next frame */ -#if 0 - // to be deleted next MR - hCPE->hStereoDftDmx->prevTargetGain = hCPE->hStereoDftDmx->targetGain; -#endif hCPE->hStereoDftDmx->prevTargetGain_fx = hCPE->hStereoDftDmx->targetGain_fx; move32(); } @@ -126,11 +118,12 @@ void stereo_tca_dec_fx( Copy32( bufChanR_fx + output_frame, hStereoTCA->memChanR_fx, L_DEC_MEM_LEN_ICA ); /* TCA parameter de-quantize */ - dsFactor = (Word16) ( output_Fs / 8000 ); + dsFactor = extract_l( output_Fs / 8000 ); tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); hStereoTCA->corrLagStats = s_min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); bothChannelShift = 0; + move16(); test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { @@ -186,7 +179,7 @@ void stereo_tca_dec_fx( IF( NE_16( currentNCShift, 0 ) ) { - currentNCShift = add( mult( 19660, prevNCShift ), mult( 13106, currentNCShift ) ); + currentNCShift = add( mult( 19660 /* 0.6 in Q15 */, prevNCShift ), mult( 13106 /* 0.4 in Q15 */, currentNCShift ) ); } prevNCShift = hStereoTCA->interp_dec_prevNCShift; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 989d3a3ea..2c965c287 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -59,6 +59,7 @@ * Allocate CoreCoder TCX modules *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static ivas_error allocate_CoreCoder_TCX( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) @@ -132,8 +133,7 @@ static ivas_error allocate_CoreCoder_TCX( return IVAS_ERR_OK; } - -#ifdef IVAS_FLOAT_FIXED +#else static ivas_error allocate_CoreCoder_TCX_fx( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) @@ -228,13 +228,14 @@ static ivas_error allocate_CoreCoder_TCX_fx( } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------* * Function allocate_CoreCoder() * * Allocate CoreCoder modules *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static ivas_error allocate_CoreCoder( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) @@ -317,9 +318,7 @@ static ivas_error allocate_CoreCoder( return error; } -#endif - -#ifdef IVAS_FLOAT_FIXED +#else static ivas_error allocate_CoreCoder_fx( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) @@ -456,6 +455,7 @@ static void deallocate_CoreCoder_TCX( * Deallocate CoreCoder modules *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void deallocate_CoreCoder( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) @@ -504,7 +504,7 @@ static void deallocate_CoreCoder( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void deallocate_CoreCoder_fx( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) @@ -2136,83 +2136,7 @@ void synchro_synthesis( if ( hCPE->element_mode != IVAS_CPE_MDCT ) { -#ifdef IVAS_FLOAT_FIXED - Word32 *output_fx[2]; - Word16 q = 11; - Word32 op[2][L_FRAME48k]; - output_fx[0] = op[0]; - output_fx[1] = op[1]; - - for ( int p = 0; p < L_FRAME48k; p++ ) - { - output_fx[0][p] = (Word32) ( output[0][p] * ( 1u << q ) ); - output_fx[1][p] = (Word32) ( output[1][p] * ( 1u << q ) ); - - if ( p < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ) - { - hCPE->output_mem_fx[0][p] = (Word32) ( hCPE->output_mem[0][p] * ( 1u << q ) ); - hCPE->output_mem_fx[1][p] = (Word32) ( hCPE->output_mem[1][p] * ( 1u << q ) ); - } - - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); - } - } - if ( !( ( hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[0]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) - { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); - } - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - //for ( int p = 0; p < 111; p++ ) - //{ - // hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[p] * ( 1u << q ) ); - //} - - ivas_post_proc_fx( NULL, hCPE, 0, output_fx[0], output_fx, output_frame, sba_dirac_stereo_flag ); - - for ( int p = 0; p < L_FRAME48k; p++ ) - { - output[0][p] = (float) output_fx[0][p] / ( 1u << q ); - output[1][p] = (float) output_fx[1][p] / ( 1u << q ); - - if ( p < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ) - { - hCPE->output_mem[0][p] = (float) hCPE->output_mem_fx[0][p] / ( 1u << q ); - hCPE->output_mem[1][p] = (float) hCPE->output_mem_fx[1][p] / ( 1u << q ); - } - - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); - } - } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - if ( !( ( hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[0]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) - { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); - } - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - } -#else ivas_post_proc( NULL, hCPE, 0, output[0], output, output_frame, sba_dirac_stereo_flag ); -#endif // IVAS_FLOAT_FIXED } /* zero padding in order to synchronize the upmixed DFT stereo synthesis with the TD/MDCT stereo synthesis */ @@ -2409,46 +2333,7 @@ void synchro_synthesis( { mvr2r( sts[n]->prev_synth_buffer + delay_comp_DFT, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, delay_diff ); delay_signal_float( output[n], output_frame, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, delay_diff ); -#ifdef IVAS_FLOAT_FIXED - Word32 *output_fx[2]; - Word32 op[2][L_FRAME48k]; - Word16 q = 11; - output_fx[0] = op[0]; - output_fx[1] = op[1]; - for ( int p = 0; p < L_FRAME48k; p++ ) - { - output_fx[0][p] = (Word32) ( output[0][p] * ( 1u << q ) ); - output_fx[1][p] = (Word32) ( output[1][p] * ( 1u << q ) ); - - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); - } - } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - //for ( int p = 0; p < 111; p++ ) - //{ - // hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[p] * ( 1u << q ) ); - //} - - ivas_post_proc_fx( NULL, hCPE, n, output_fx[n], output_fx, output_frame, 0 ); - - for ( int p = 0; p < L_FRAME48k; p++ ) - { - output[0][p] = (float) output_fx[0][p] / ( 1u << q ); - output[1][p] = (float) output_fx[1][p] / ( 1u << q ); - - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); - } - } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; -#else ivas_post_proc( NULL, hCPE, n, output[n], output, output_frame, 0 ); -#endif // IVAS_FLOAT_FIXED delay_signal_float( output[n], output_frame, sts[n]->prev_synth_buffer, delay_comp_DFT ); mvr2r( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, sts[n]->prev_synth_buffer + delay_comp_DFT, delay_diff ); } @@ -2530,15 +2415,6 @@ void synchro_synthesis_fx( sts = hCPE->hCoreCoder; output_Fs = sts[0]->output_Fs; - IF( hCPE->hStereoDft != NULL ) - { - output_q = hCPE->hStereoDft->q_dft; - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - Scale_sig32( hCPE->prev_hb_synth_fx[n], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - output_q ) ); - } - } - use_cldfb_for_last_dft = 0; IF( ( hCPE->element_mode != IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_24k4 ) /* note: this is to mimic the DFT stereo condition "hCPE->hStereoDft->hConfig->res_cod_mode == 0" in last frame */ || ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) @@ -2657,13 +2533,13 @@ void synchro_synthesis_fx( { case 16000: inv_fade_len_fx = 71582792; - break; + BREAK; case 32000: inv_fade_len_fx = 35791396; - break; + BREAK; case 48000: inv_fade_len_fx = 23860930; - break; + BREAK; default: assert( 0 ); } @@ -2701,15 +2577,15 @@ void synchro_synthesis_fx( case 16000: inv_fade_len_1_fx = 71582792; inv_fade_len_2_fx = 107374184; - break; + BREAK; case 32000: inv_fade_len_1_fx = 35791396; inv_fade_len_2_fx = 53687092; - break; + BREAK; case 48000: inv_fade_len_1_fx = 23860930; inv_fade_len_2_fx = 35791396; - break; + BREAK; default: assert( 0 ); } @@ -2814,13 +2690,13 @@ void synchro_synthesis_fx( { case 16000: tmpF_fx = 71582792; - break; + BREAK; case 32000: tmpF_fx = 35791396; - break; + BREAK; case 48000: tmpF_fx = 23860930; - break; + BREAK; default: assert( 0 ); } @@ -2865,13 +2741,13 @@ void synchro_synthesis_fx( { case 16000: step_fx = 33554432; - break; + BREAK; case 32000: step_fx = 16777216; - break; + BREAK; case 48000: step_fx = 11184811; - break; + BREAK; default: assert( 0 ); } @@ -2917,13 +2793,13 @@ void synchro_synthesis_fx( { case 16000: tmpF_fx = 107374184; - break; + BREAK; case 32000: tmpF_fx = 53687092; - break; + BREAK; case 48000: tmpF_fx = 35791396; - break; + BREAK; default: assert( 0 ); } @@ -2943,13 +2819,13 @@ void synchro_synthesis_fx( { case 16000: tmpF_fx = 71582792; - break; + BREAK; case 32000: tmpF_fx = 35791396; - break; + BREAK; case 48000: tmpF_fx = 23860930; - break; + BREAK; default: assert( 0 ); } @@ -2967,13 +2843,13 @@ void synchro_synthesis_fx( { case 16000: tmpF_fx = 107374184; - break; + BREAK; case 32000: tmpF_fx = 53687092; - break; + BREAK; case 48000: tmpF_fx = 35791396; - break; + BREAK; default: assert( 0 ); } @@ -2989,85 +2865,6 @@ void synchro_synthesis_fx( } } - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - IF( hCPE->hStereoDft != NULL ) - { - Scale_sig32( hCPE->prev_hb_synth_fx[n], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), Q11 - output_q ); - } - } - - - IF( hCPE->hStereoDft != NULL ) - { - IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - //hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - // hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); - } - } - } - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); - } - } - IF( hCPE->hCoreCoder[n] != NULL ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - //hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - //hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); - } - } - //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) - //{ - // hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); - //} - //FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - //{ - // hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); - //} - IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - //hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << output_q ); - } - } - } - IF( hCPE->input_mem[n] != NULL ) - { - FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - { - hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); - } - } - //FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - //{ - // hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); - //} - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); - } - } - - return; } @@ -3919,7 +3716,6 @@ void stereo_mdct2dft_update( return; } #else - void stereo_mdct2dft_update_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 */ @@ -3944,13 +3740,13 @@ void stereo_mdct2dft_update_fx( { case 16000: tmpF_fx = 53687092; - break; + BREAK; case 32000: tmpF_fx = 26843546; - break; + BREAK; case 48000: tmpF_fx = 17895698; - break; + BREAK; } for ( i = 0; i < fade_len; i++ ) { @@ -3974,25 +3770,25 @@ void stereo_mdct2dft_update_fx( { case 80: tmpF_fx = 71582792; - break; + BREAK; case 160: tmpF_fx = 35791396; - break; + BREAK; case 256: tmpF_fx = 22369622; - break; + BREAK; case 320: tmpF_fx = 17895698; - break; + BREAK; case 512: tmpF_fx = 11184811; - break; + BREAK; case 640: tmpF_fx = 8947849; - break; + BREAK; case 960: tmpF_fx = 5965232; - break; + BREAK; default: assert( 0 ); } @@ -4016,6 +3812,9 @@ void stereo_mdct2dft_update_fx( return; } #endif + + +#ifndef IVAS_FLOAT_FIXED static float ncross_corr_self( float *signal, const int16_t x, @@ -4051,7 +3850,7 @@ static float ncross_corr_self( return c_c; } - +#else static Word32 ncross_corr_self_fx( Word32 *signal_fx, const Word16 x, @@ -4063,7 +3862,7 @@ static Word32 ncross_corr_self_fx( Word32 c_c_fx_return; Word16 c_c_fx_q; Word64 energy_xy_fx, energy_x_fx, energy_y_fx; - uint16_t j; + UWord16 j; Word32 *signal_a_fx, *signal_b_fx; Word32 temp_x, temp_y; Word16 headroom_left_x, headroom_left_y; @@ -4071,11 +3870,14 @@ static Word32 ncross_corr_self_fx( Word16 x_q, y_q; Word16 res_q; c_c_fx = 0; + move64(); energy_x_fx = 0; + move64(); energy_y_fx = 0; + move64(); signal_a_fx = &signal_fx[x]; signal_b_fx = &signal_fx[y]; - FOR ( j = 0; j < corr_len; j += subsampling ) + FOR( j = 0; j < corr_len; j += subsampling ) { c_c_fx += ( (Word64) ( signal_a_fx[j] ) * ( signal_b_fx[j] ) ); energy_x_fx += (Word64) ( signal_a_fx[j] ) * ( signal_a_fx[j] ); @@ -4084,19 +3886,19 @@ static Word32 ncross_corr_self_fx( headroom_left_x = W_norm( energy_x_fx ); headroom_left_y = W_norm( energy_y_fx ); - IF ( headroom_left_x < 32 ) + IF( headroom_left_x < 32 ) { - energy_x_fx = W_shr( energy_x_fx, (Word16)( 32 - headroom_left_x ) ); - x_q = (Word16)( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_x ) ) ); + energy_x_fx = W_shr( energy_x_fx, (Word16) ( 32 - headroom_left_x ) ); + x_q = (Word16) ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_x ) ) ); } ELSE { x_q = 31 - ( 2 * OUTPUT_Q ); } - IF ( headroom_left_y < 32 ) + IF( headroom_left_y < 32 ) { - energy_y_fx = W_shr( energy_y_fx, (Word16)( 32 - headroom_left_y ) ); - y_q = (Word16)( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_y ) ) ); + energy_y_fx = W_shr( energy_y_fx, (Word16) ( 32 - headroom_left_y ) ); + y_q = (Word16) ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_y ) ) ); } ELSE { @@ -4105,16 +3907,16 @@ static Word32 ncross_corr_self_fx( x_inv_q = x_q; y_inv_q = y_q; - - temp_x = Sqrt32((Word32)energy_x_fx, &x_q ); - if ( x_q < 0 ) + + temp_x = Sqrt32( (Word32) energy_x_fx, &x_q ); + IF( x_q < 0 ) { temp_x = L_shr( temp_x, -1 * x_q ); x_q = 0; } - temp_y = Sqrt32((Word32)energy_y_fx, &y_q ); - IF ( y_q < 0 ) + temp_y = Sqrt32( (Word32) energy_y_fx, &y_q ); + IF( y_q < 0 ) { temp_y = L_shr( temp_y, -1 * y_q ); y_q = 0; @@ -4123,7 +3925,7 @@ static Word32 ncross_corr_self_fx( energy_xy_fx = Mpy_32_32( temp_x, temp_y ); res_q = y_q + x_q; - IF ( ( energy_xy_fx < L_shr( ONE_IN_Q31, (Word16)res_q ) ) || energy_xy_fx == 0 ) + IF( ( energy_xy_fx < L_shr( ONE_IN_Q31, (Word16) res_q ) ) || energy_xy_fx == 0 ) { energy_xy_fx = ONE_IN_Q31; /* conceal silent frames */ res_q = 0; @@ -4131,27 +3933,29 @@ static Word32 ncross_corr_self_fx( } ELSE { - Word32 temp_x_inv = ISqrt32( (Word32)energy_x_fx, &x_inv_q ); - Word32 temp_y_inv = ISqrt32((Word32)energy_y_fx, &y_inv_q ); + Word32 temp_x_inv = ISqrt32( (Word32) energy_x_fx, &x_inv_q ); + Word32 temp_y_inv = ISqrt32( (Word32) energy_y_fx, &y_inv_q ); Word16 headroom_left_c_c; - energy_xy_fx = (Word32)Mpy_32_32( temp_x_inv, temp_y_inv ); + energy_xy_fx = (Word32) Mpy_32_32( temp_x_inv, temp_y_inv ); res_q = x_inv_q + y_inv_q; headroom_left_c_c = W_norm( c_c_fx ); c_c_fx_q = OUTPUT_Q * 2; IF( headroom_left_c_c < 32 ) { - c_c_fx = W_shr( c_c_fx, (Word16)(32 - headroom_left_c_c) ); + c_c_fx = W_shr( c_c_fx, (Word16) ( 32 - headroom_left_c_c ) ); c_c_fx_q = c_c_fx_q - ( 32 - headroom_left_c_c ); } - c_c_fx = (Word64)Mpy_32_32( (Word32)c_c_fx, (Word32)energy_xy_fx ); - c_c_fx_q = (Word16)c_c_fx_q + ( 31 - res_q ) - 31; - c_c_fx = (Word32)W_shl_sat_l( c_c_fx, (Word16)(31 - c_c_fx_q) ); + c_c_fx = (Word64) Mpy_32_32( (Word32) c_c_fx, (Word32) energy_xy_fx ); + c_c_fx_q = (Word16) c_c_fx_q + ( 31 - res_q ) - 31; + c_c_fx = (Word32) W_shl_sat_l( c_c_fx, (Word16) ( 31 - c_c_fx_q ) ); } - c_c_fx_return = (Word32)c_c_fx; + c_c_fx_return = (Word32) c_c_fx; return c_c_fx_return; } -#ifndef IVAS_FLOAT_FIXED +#endif + + /*-------------------------------------------------------------------* * Function smooth_dft2td_transition() * @@ -4159,6 +3963,7 @@ static Word32 ncross_corr_self_fx( * switching from DFT stereo to TD stereo *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void smooth_dft2td_transition( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *output[CPE_CHANNELS], /* i/o: synthesis @external Fs */ @@ -4304,12 +4109,11 @@ void smooth_dft2td_transition( return; } -#endif -#ifdef IVAS_FLOAT_FIXED +#else void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs */ - const Word16 output_frame /* i : output frame lenght */ + const Word16 output_frame /* i : output frame lenght */ ) { @@ -4318,63 +4122,73 @@ void smooth_dft2td_transition_fx( Word32 flen_fx, ftmp_corr_fx, fmaxcorr_fx, fac_fs_fx; Word32 tmp_out_fx[L_FRAME48k + L_FRAME48k / 2], tmp_out2_fx[L_FRAME48k], *ptO2_fx, *ptO_fx, *pt1_fx, *ptE_fx; - IF ( hCPE == NULL ) + IF( hCPE == NULL ) { return; } /* initialization */ sts = hCPE->hCoreCoder; - IF ( ( hCPE->element_mode == IVAS_CPE_TD && ( hCPE->last_element_mode == IVAS_CPE_DFT || hCPE->last_element_mode == IVAS_CPE_MDCT ) && ( sts[0]->clas_dec == VOICED_CLAS && sts[0]->coder_type < TRANSITION && sts[0]->coder_type > UNVOICED && sts[0]->last_coder_type > UNVOICED && sts[1]->coder_type > UNVOICED ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) && ( EQ_16( sts[0]->clas_dec, VOICED_CLAS ) && LT_16( sts[0]->coder_type, TRANSITION ) && GT_16( sts[0]->coder_type, UNVOICED ) && GT_16( sts[0]->last_coder_type, UNVOICED ) && GT_16( sts[1]->coder_type, UNVOICED ) ) ) ) { /* length of OVA */ - ilen = output_frame / 2; + ilen = shr( output_frame, 1 ); /* correlation length */ corr_len = output_frame / 20; subsampl = 4; - FOR ( ch = 0; ch < hCPE->nchan_out; ch++ ) + FOR( ch = 0; ch < hCPE->nchan_out; ch++ ) { /* core to external sampling frequency ratio */ - Word16 q = norm_l(output_frame); - Word32 check = BASOP_Util_Divide3232_Scale(output_frame, sts[ch]->L_frame, &q); - fac_fs_fx = check * (1 << (26 - (15 - q))); + Word16 q = norm_l( output_frame ); + Word32 check = BASOP_Util_Divide3232_Scale( output_frame, sts[ch]->L_frame, &q ); + fac_fs_fx = check * ( 1 << ( 26 - ( 15 - q ) ) ); /* Find minimum and maximum pitch*/ - ipit_min = minimum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx) + 4; - ipit_max = maximum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx) + 4; - ipit_min = (Word16)L_shr(L_add(Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_min], fac_fs_fx ), ONE_IN_Q10 ),11); - ipit_max = (Word16)L_shr(L_add(Mpy_32_32(sts[ch]->old_pitch_buf_fx[ipit_max], fac_fs_fx), ONE_IN_Q10),11); + ipit_min = minimum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ) + 4; + ipit_max = maximum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ) + 4; + ipit_min = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_min], fac_fs_fx ), ONE_IN_Q10 ), 11 ); + ipit_max = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_max], fac_fs_fx ), ONE_IN_Q10 ), 11 ); - IF ( ( ipit_max + corr_len ) > ilen ) /*ensure the search is performed on the available memory*/ + IF( GT_16( add( ipit_max, corr_len ), ilen ) ) /*ensure the search is performed on the available memory*/ { - continue; + CONTINUE; } - lsearch = ipit_max - ipit_min + corr_len; - lsearch = min( lsearch, output_frame / 4 ); + lsearch = add( sub( ipit_max, ipit_min ), corr_len ); + lsearch = s_min( lsearch, shr( output_frame, 2 ) ); /* ptr init for search of the best correlation in the past frame */ ptE_fx = hCPE->prev_synth_chs_fx[ch] + output_frame - ipit_max - corr_len; idiff = 0; + move16(); fmaxcorr_fx = -ONE_IN_Q31; - FOR ( i = 0; i < lsearch; i++ ) + move32(); + FOR( i = 0; i < lsearch; i++ ) { - ftmp_corr_fx = ncross_corr_self_fx(ptE_fx, i, ipit_max, corr_len, subsampl); - IF (ftmp_corr_fx > fmaxcorr_fx) + ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); + IF( GT_32( ftmp_corr_fx, fmaxcorr_fx ) ) { idiff = i; + move16(); } - fmaxcorr_fx = max( fmaxcorr_fx, ftmp_corr_fx ); + fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); } - ipit = ipit_max - idiff; + ipit = sub( ipit_max, idiff ); ptO_fx = tmp_out_fx + output_frame; /* If the correlation is too low, don't use the prediction */ - IF ( fmaxcorr_fx < DFT2TD_CORR_THRESH_FX ) + IF( LT_32( fmaxcorr_fx, DFT2TD_CORR_THRESH_FX ) ) { Copy32( &output_fx[ch][0], ptO_fx, ilen ); } @@ -4382,89 +4196,102 @@ void smooth_dft2td_transition_fx( { Copy32( hCPE->prev_synth_chs_fx[ch], tmp_out_fx, output_frame ); pt1_fx = tmp_out_fx + output_frame - ipit; - FOR ( i = 0; i < ilen; i++ ) + FOR( i = 0; i < ilen; i++ ) { ptO_fx[i] = pt1_fx[i]; + move32(); } } /* Set buffer for the reserved buffer of the current frame */ ptO2_fx = tmp_out2_fx + output_frame - ilen; set32_fx( tmp_out2_fx + output_frame - ilen, 0, ilen ); - FOR ( i = 0; i < output_frame; i++ ) + FOR( i = 0; i < output_frame; i++ ) { tmp_out2_fx[i] = output_fx[ch][output_frame - 1 - i]; + move32(); } /* ptr init for search of the best correlation of the current frame */ ptE_fx = ptO2_fx - ( ipit_max + corr_len ); idiff = 0; + move16(); fmaxcorr_fx = -ONE_IN_Q31; - FOR ( i = 0; i < lsearch; i++ ) + move32(); + FOR( i = 0; i < lsearch; i++ ) { - ftmp_corr_fx = ncross_corr_self_fx(ptE_fx, i, ipit_max, corr_len, subsampl); - IF (ftmp_corr_fx > fmaxcorr_fx) + ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); + IF( GT_32( ftmp_corr_fx, fmaxcorr_fx ) ) { - idiff = i; + idiff = i; + move16(); } - fmaxcorr_fx = max( fmaxcorr_fx, ftmp_corr_fx); + fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); } - ipit = ipit_max - idiff; + ipit = sub( ipit_max, idiff ); /* If the correlation is too low, don't use the prediction */ - IF ( fmaxcorr_fx > DFT2TD_CORR_THRESH_FX ) + IF( GT_32( fmaxcorr_fx, DFT2TD_CORR_THRESH_FX ) ) { pt1_fx = tmp_out2_fx + output_frame - ilen - ipit; - FOR ( i = 0; i < ilen; i++ ) + FOR( i = 0; i < ilen; i++ ) { ptO2_fx[i] = pt1_fx[i]; + move32(); } } /* perform OVA between predicted signals */ - SWITCH (ilen) - { - case 160: - flen_fx = 13421772; - break; - case 320: - flen_fx = 6710886; - break; - case 480: - flen_fx = 4473924; - break; - default: - assert(0); - break; - } - FOR ( i = 0; i < 4; i++ ) - { - Word64 temp_a = W_shr(((4 - i) * (Word64)output_fx[ch][i] + i * ptO_fx[i]), 2)* (ilen - i); + SWITCH( ilen ) + { + case 160: + flen_fx = 13421772; + move32(); + BREAK; + case 320: + flen_fx = 6710886; + move32(); + BREAK; + case 480: + flen_fx = 4473924; + move32(); + BREAK; + default: + assert( 0 ); + BREAK; + } + FOR( i = 0; i < 4; i++ ) + { + Word64 temp_a = W_shr( ( ( 4 - i ) * (Word64) output_fx[ch][i] + i * ptO_fx[i] ), 2 ) * ( ilen - i ); Word64 temp_b = tmp_out2_fx[output_frame - 1 - i] * i; - output_fx[ch][i] = (Word32)W_shr((W_add(temp_a, temp_b) * flen_fx), 31); + output_fx[ch][i] = (Word32) W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ); + move32(); } - FOR ( ; i < ilen - 4; i++ ) + FOR( ; i < ilen - 4; i++ ) { - Word64 temp_a = (Word64)ptO_fx[i] * (ilen - i); - Word64 temp_b = (Word64)tmp_out2_fx[output_frame - 1 - i] * i; - output_fx[ch][i] = (Word32)W_shr((W_add(temp_a, temp_b) * flen_fx), 31); + Word64 temp_a = (Word64) ptO_fx[i] * ( ilen - i ); + Word64 temp_b = (Word64) tmp_out2_fx[output_frame - 1 - i] * i; + output_fx[ch][i] = (Word32) W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ); + move32(); } j = 0; - FOR ( ; i < ilen; i++ ) + move16(); + FOR( ; i < ilen; i++ ) { - Word64 temp_a = (Word64)ptO_fx[i] * (ilen - i); - Word64 temp_b = W_shr((W_add((Word64)(4 - j) * tmp_out2_fx[output_frame - 1 - i], (Word64)j * output_fx[ch][i]) * i), 2); - output_fx[ch][i] = (Word32)W_shr((W_add(temp_a, temp_b) * flen_fx), 31); + Word64 temp_a = (Word64) ptO_fx[i] * ( ilen - i ); + Word64 temp_b = W_shr( ( W_add( (Word64) ( 4 - j ) * tmp_out2_fx[output_frame - 1 - i], (Word64) j * output_fx[ch][i] ) * i ), 2 ); + output_fx[ch][i] = (Word32) W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ); + move32(); j++; } } } - ELSE IF ( hCPE->element_mode == IVAS_CPE_DFT ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /* Updates */ - FOR ( ch = 0; ch < hCPE->nchan_out; ch++ ) + FOR( ch = 0; ch < hCPE->nchan_out; ch++ ) { Copy32( output_fx[ch], hCPE->prev_synth_chs_fx[ch], output_frame ); } diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 2bdbb72b2..d0202a9e6 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -43,6 +43,7 @@ #include "ivas_cnst.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * stereo_td_init_dec() * @@ -75,6 +76,7 @@ void stereo_td_init_dec( return; } +#endif void stereo_td_init_dec_fx( @@ -102,7 +104,6 @@ void stereo_td_init_dec_fx( hStereoTD->tdm_LRTD_flag = 1; } - set_f( hStereoTD->TCX_old_syn_Overl, 0.0f, L_FRAME16k / 2 ); set32_fx( hStereoTD->TCX_old_syn_Overl_fx, 0, L_FRAME16k / 2 ); return; diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 21cbd69b8..f9fb1e649 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -418,10 +418,10 @@ typedef struct tonalmdctconceal Word16 secondLastPowerSpectrum_exp; - float scaleFactorsBackground_flt[FDNS_NPTS]; //Word16 scaleFactorsBackground[FDNS_NPTS]; Word32 scaleFactorsBackground_fx[FDNS_NPTS]; #ifndef IVAS_FLOAT_FIXED + float scaleFactorsBackground_flt[FDNS_NPTS]; float scf_fadeout_flt; #endif Word16 scf_fadeout; diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index e87dd91cb..ff1de4d86 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -99,9 +99,9 @@ ivas_error TonalMDCTConceal_Init_ivas( hTonalMDCTConc->nSamplesCore = nSamplesCore; hTonalMDCTConc->nScaleFactors = nScaleFactors; - set_zero( hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS ); set32_fx( hTonalMDCTConc->scaleFactorsBackground_fx, 0, FDNS_NPTS ); #ifndef IVAS_FLOAT_FIXED + set_zero( hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS ); hTonalMDCTConc->scf_fadeout_flt = 1.0f; #endif PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 ); diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index aef6dc7d6..76e22164a 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -70,6 +70,14 @@ Word16 slot_fx[4] = {32767, 16384, 10922 ,8192}; #define ADAPT_HTPROTO_ILD_LIM_DB0 1.0f #define ADAPT_HTPROTO_ILD_LIM_DB1 4.0f #define ADAPT_HTPROTO_ROT_LIM_0 0.4f +#ifdef IVAS_FLOAT_FIXED +#define ADAPT_HTPROTO_ROT_LIM_0_FX 429496736 // Q30 +#define TWO_POINT_FIVE_IN_Q13 20480 // Q13 +#define ADAPT_HTPROTO_IIR_FAC_FX 26689 // Q15 +#define LOG_10_BASE_2_Q29 1783446528 // Q29 +#define TAN_30_FX 17157 //Q15 +#define INV_TAN30_FX 28377 //Q14 +#endif #define ADAPT_HTPROTO_ROT_LIM_1 0.8f #define MAX_GAIN_CACHE_SIZE ( ( MASA_MAXIMUM_DIRECTIONS * 3 ) + MAX_NUM_OBJECTS ) /* == different calls to get gains */ @@ -111,11 +119,15 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked, const int16_t nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData ); -static void ivas_dirac_dec_binaural_process_output( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, const int16_t processReverb, const int16_t subframe ); - #ifdef IVAS_FLOAT_FIXED static void ivas_dirac_dec_binaural_process_output_fx(DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], Word32 *output_fx[], Word16 *q_out, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 q_inp, const Word16 max_band_decorr, const Word16 numInChannels, const Word16 processReverb, const Word16 subframe, const Word16 q_mat); + +static void adaptTransportSignalsHeadtracked_fx(COMBINED_ORIENTATION_HANDLE hHeadTrackData, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 q_inp, const Word16 nBins, const Word16 nSlots, Word32 Rmat[3][3]); + +static void ivas_dirac_dec_binaural_check_and_switch_transports_headtracked_fx(COMBINED_ORIENTATION_HANDLE hHeadTrackData, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nBins, const Word16 nSlots, Word32 Rmat[3][3]); #endif +static void ivas_dirac_dec_binaural_process_output( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, const int16_t processReverb, const int16_t subframe ); + static void adaptTransportSignalsHeadtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nBins, const int16_t nSlots, float Rmat[3][3] ); @@ -1179,7 +1191,7 @@ static void ivas_dirac_dec_binaural_internal( numInChannels = add(numInChannels, st_ivas->nchan_ism); } - Rmat_fx[0][0] = 32768; // 1 in Q15 + Rmat_fx[0][0] = ONE_IN_Q31; move32(); Rmat_fx[0][1] = 0; move32(); @@ -1188,7 +1200,7 @@ static void ivas_dirac_dec_binaural_internal( Rmat_fx[1][0] = 0; move32(); - Rmat_fx[1][1] = 32768; // 1 in Q15 + Rmat_fx[1][1] = ONE_IN_Q31; move32(); Rmat_fx[1][2] = 0; move32(); @@ -1197,7 +1209,7 @@ static void ivas_dirac_dec_binaural_internal( move32(); Rmat_fx[2][1] = 0; move32(); - Rmat_fx[2][2] = 32768; // 1 in Q15 + Rmat_fx[2][2] = ONE_IN_Q31; move32(); @@ -1399,21 +1411,44 @@ static void ivas_dirac_dec_binaural_internal( ivas_omasa_preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, subframe ); } - if ( hCombinedOrientationData ) + IF( hCombinedOrientationData ) { - for ( i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { - for ( j = 0; j < 3; j++ ) + FOR( j = 0; j < 3; j++ ) { - Rmat[i][j] = hCombinedOrientationData->Rmat[hCombinedOrientationData->subframe_idx][i][j]; +#ifdef IVAS_FLOAT_FIXED + Rmat_fx[i][j] = hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i][j]; // Q30// +#endif + Rmat[i][j] = hCombinedOrientationData->Rmat[hCombinedOrientationData->subframe_idx][i][j]; } } - if ( nchan_transport == 2 ) + IF( EQ_16( nchan_transport, 2 ) ) { - adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); +#ifdef IVAS_FLOAT_FIXED + Word16 q_inp = Q6; + FOR( Word16 cha = 0; cha < 2; cha++ ) + FOR( slot = 0; slot < 4; slot++ ) + FOR( Word16 ind = 0; ind < 60; ind++ ) + { + Cldfb_RealBuffer_in_fx[cha][slot][ind] = float_to_fix( Cldfb_RealBuffer_in[cha][slot][ind], q_inp ); + Cldfb_ImagBuffer_in_fx[cha][slot][ind] = float_to_fix( Cldfb_ImagBuffer_in[cha][slot][ind], q_inp ); + } + adaptTransportSignalsHeadtracked_fx( hCombinedOrientationData, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_inp, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat_fx ); + ivas_dirac_dec_binaural_check_and_switch_transports_headtracked_fx( hCombinedOrientationData, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat_fx ); + FOR( Word16 cha = 0; cha < 2; cha++ ) + FOR( slot = 0; slot < 4; slot++ ) + FOR( Word16 ind = 0; ind < 60; ind++ ) + { + Cldfb_RealBuffer_in[cha][slot][ind] = fix_to_float( Cldfb_RealBuffer_in_fx[cha][slot][ind], q_inp ); + Cldfb_ImagBuffer_in[cha][slot][ind] = fix_to_float( Cldfb_ImagBuffer_in_fx[cha][slot][ind], q_inp ); + } +#else + adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); +#endif } } @@ -2673,6 +2708,245 @@ static void ivas_dirac_dec_binaural_process_output( } #endif +#ifdef IVAS_FLOAT_FIXED +static void adaptTransportSignalsHeadtracked_fx( + COMBINED_ORIENTATION_HANDLE hHeadTrackData, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word16 q_inp, + const Word16 nBins, + const Word16 nSlots, + Word32 Rmat[3][3] ) +{ + Word16 slot, ch, bin, louderCh; + Word32 mono_factor_ILD, mono_factor; + Word32 y_val, mono_factor_rotation, ene_proc, ene_target, ILD; + Word16 max_band; + Word32 eqVal; + Word16 band_idx, bin_lo, bin_hi, norm, shift = 31; + Word16 q_chEneIIR = 0, q_procChEneIIR = 0; + Word32 temp_div; + Word16 e_div; + + FOR( Word16 i = 0; i < 6; i++ ) + { + FOR( Word16 j = 0; j < nSlots; j++ ) + { + norm = s_min( L_norm_arr( inRe_fx[i][j], nBins ), L_norm_arr( inIm_fx[i][j], nBins ) ); + shift = s_min( norm, shift ); + } + } + + /* Determine head-orientation-based mono factor. + Rmat[1][1] entry informs how close the ears are aligned according to transport signals. */ + + y_val = L_sub( ONE_IN_Q30, L_abs( Rmat[1][1] ) ); // Q30 + mono_factor_rotation = Mpy_32_16_1( L_sub( y_val, ADAPT_HTPROTO_ROT_LIM_0_FX ), TWO_POINT_FIVE_IN_Q13 ); // Q28 + mono_factor_rotation = L_max( 0, L_min( ONE_IN_Q28, mono_factor_rotation ) ); + + IF( EQ_32( mono_factor_rotation, ONE_IN_Q28 ) ) + { + mono_factor_rotation = ONE_IN_Q31; + } + ELSE + { + mono_factor_rotation = L_shl( mono_factor_rotation, 3 ); // Q31 + } + + /* Adapt transport signals in frequency bands */ + /* optimization grouping CLDFB bins into MASA bands (they are readily available in ROM and suitable for the task) AND group CLDFB slots into sub-frames */ + + max_band = 0; + WHILE( max_band < MASA_FREQUENCY_BANDS && MASA_band_grouping_24[max_band] < nBins ) + { + max_band = add( max_band, 1 ); + } + + shift = sub( shift, 5 ); + // 5 is gaurded bits needed// + Word32 re, img, temp; + Word16 q_temp = 2 * ( q_inp + shift ) - 31; + FOR( band_idx = 0; band_idx < max_band; band_idx++ ) + { + Word32 ch_nrg[2]; /* storage for input signal channel energies */ + bin_lo = MASA_band_grouping_24[band_idx]; + bin_hi = s_min( MASA_band_grouping_24[band_idx + 1], (Word16) nBins ); + + FOR( ch = 0; ch < 2; ch++ ) + { + ch_nrg[ch] = 0; + FOR( slot = 0; slot < nSlots; slot++ ) + { + FOR( bin = bin_lo; bin < bin_hi; bin++ ) + { + re = L_shl( inRe_fx[ch][slot][bin], shift ); + img = L_shl( inIm_fx[ch][slot][bin], shift ); + + ch_nrg[ch] = L_add( ch_nrg[ch], ( L_add( Mpy_32_32( re, re ), Mpy_32_32( img, img ) ) ) ); // 2(q_inp +shift) -31 + } + } + hHeadTrackData->chEneIIR_fx[ch][band_idx] = Mpy_32_16_1( hHeadTrackData->chEneIIR_fx[ch][band_idx], ADAPT_HTPROTO_IIR_FAC_FX ); + temp = Mpy_32_16_1( ch_nrg[ch], sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); + IF( LT_16( hHeadTrackData->q_chEneIIR, q_temp ) ) + { + hHeadTrackData->chEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp, hHeadTrackData->q_chEneIIR ) ), hHeadTrackData->chEneIIR_fx[ch][band_idx] ); + } + ELSE + { + hHeadTrackData->chEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->chEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_chEneIIR, q_temp ) ), temp ); + } + + hHeadTrackData->chEneIIR[ch][band_idx] = fixedToFloat_32( hHeadTrackData->chEneIIR_fx[ch][band_idx], s_min( hHeadTrackData->q_chEneIIR, q_temp ) ); + } + q_chEneIIR = s_min( hHeadTrackData->q_chEneIIR, q_temp ); + /* Determine ILD */ + + IF( EQ_32( L_max( 1, hHeadTrackData->chEneIIR_fx[0][band_idx] ), L_max( 1, hHeadTrackData->chEneIIR_fx[1][band_idx] ) ) ) + { + ILD = 0; + } + ELSE + { + temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( L_max( 1, hHeadTrackData->chEneIIR_fx[0][band_idx] ), L_max( 1, hHeadTrackData->chEneIIR_fx[1][band_idx] ), &e_div ) ); + + temp = BASOP_Util_Log2( temp_div ); // Q25 + IF( GE_16( e_div, 0 ) ) + temp = L_add( temp, L_shl( e_div, 25 ) ); // Q25 + ELSE + temp = L_sub( temp, L_shl( abs( e_div ), 25 ) ); // Q25 + + temp = Mpy_32_32( temp, 646462464 ); // logx base 10 = 0.30103* logx base 2// + ILD = L_abs( Mpy_32_16_1( temp, 20480 ) ); // Q21 + } + IF( GT_32( hHeadTrackData->chEneIIR_fx[1][band_idx], hHeadTrackData->chEneIIR_fx[0][band_idx] ) ) + { + louderCh = 1; + } + ELSE + { + louderCh = 0; + } + + /* Determine ILD-based mono factor */ + mono_factor_ILD = Mpy_32_16_1( L_sub( ILD, ONE_IN_Q21 ), 10911 ); // Q23 + + mono_factor_ILD = L_max( 0, L_min( ONE_IN_Q21, mono_factor_ILD ) ); + + IF( EQ_32( mono_factor_ILD, ONE_IN_Q21 ) ) + mono_factor_ILD = ONE_IN_Q31; + ELSE + mono_factor_ILD = L_shl( mono_factor_ILD, 10 ); // Q31 + + /* Combine mono factors */ + mono_factor = Mpy_32_32( mono_factor_ILD, mono_factor_rotation ); // Q31 + + /* Mix original audio and sum signal according to determined mono factor */ + FOR( ch = 0; ch < 2; ch++ ) + { + IF( NE_16( ch, louderCh ) ) + { + Word32 band_nrg = 0; + + FOR( slot = 0; slot < nSlots; slot++ ) + { + FOR( bin = bin_lo; bin < bin_hi; bin++ ) + { + /* mono sum signal with the computed weight + rest from the original channel */ + inRe_fx[ch][slot][bin] = L_add( ( Mpy_32_32( mono_factor, L_add( inRe_fx[0][slot][bin], inRe_fx[1][slot][bin] ) ) ), ( Mpy_32_32( L_sub( ONE_IN_Q31, mono_factor ), inRe_fx[ch][slot][bin] ) ) ); + inIm_fx[ch][slot][bin] = L_add( ( Mpy_32_32( mono_factor, L_add( inIm_fx[0][slot][bin], inIm_fx[1][slot][bin] ) ) ), ( Mpy_32_32( L_sub( ONE_IN_Q31, mono_factor ), inIm_fx[ch][slot][bin] ) ) ); + re = L_shl( inRe_fx[ch][slot][bin], shift ); + img = L_shl( inIm_fx[ch][slot][bin], shift ); + band_nrg = L_add( band_nrg, ( L_add( Mpy_32_32( re, re ), Mpy_32_32( img, img ) ) ) ); // 2(q_inp +shift) -31 + } + } + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = Mpy_32_16_1( hHeadTrackData->procChEneIIR_fx[ch][band_idx], ADAPT_HTPROTO_IIR_FAC_FX ); + + hHeadTrackData->procChEneIIR[ch][band_idx] = fixedToFloat_32( hHeadTrackData->procChEneIIR_fx[ch][band_idx], hHeadTrackData->q_procChEneIIR ); + + if ( ( ch == 0 && band_idx == 1 ) || ( ch == 1 && band_idx == 0 ) ) + ch = ch; + + temp = Mpy_32_16_1( band_nrg, sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); + IF( LT_16( hHeadTrackData->q_procChEneIIR, q_temp ) ) + { + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp, hHeadTrackData->q_procChEneIIR ) ), hHeadTrackData->procChEneIIR_fx[ch][band_idx] ); + } + ELSE + { + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->procChEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_procChEneIIR, q_temp ) ), temp ); + } + } + ELSE + { + /* processed signal is input. use the original channel, so no need to compute new signals or signal energy */ + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = Mpy_32_16_1( hHeadTrackData->procChEneIIR_fx[ch][band_idx], ADAPT_HTPROTO_IIR_FAC_FX ); + + temp = Mpy_32_16_1( ch_nrg[ch], sub( 32767, ADAPT_HTPROTO_IIR_FAC_FX ) ); + IF( LT_16( hHeadTrackData->q_procChEneIIR, q_temp ) ) + { + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( temp, sub( q_temp, hHeadTrackData->q_procChEneIIR ) ), hHeadTrackData->procChEneIIR_fx[ch][band_idx] ); + } + ELSE + { + hHeadTrackData->procChEneIIR_fx[ch][band_idx] = L_add( L_shr( hHeadTrackData->procChEneIIR_fx[ch][band_idx], sub( hHeadTrackData->q_procChEneIIR, q_temp ) ), temp ); + } + } + + hHeadTrackData->procChEneIIR[ch][band_idx] = fixedToFloat_32( hHeadTrackData->procChEneIIR_fx[ch][band_idx], s_min( hHeadTrackData->q_procChEneIIR, q_temp ) ); + } + + q_procChEneIIR = s_min( hHeadTrackData->q_procChEneIIR, q_temp ); + + /* Equalize */ + ene_target = L_add( hHeadTrackData->chEneIIR_fx[0][band_idx], hHeadTrackData->chEneIIR_fx[1][band_idx] ); // q_chEneIIR// + + ene_proc = L_add( hHeadTrackData->procChEneIIR_fx[0][band_idx], hHeadTrackData->procChEneIIR_fx[1][band_idx] ); // q_procChEneIIR// + + temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( ene_target, L_max( 1, ene_proc ), &e_div ) ); + e_div = e_div + ( q_procChEneIIR - q_chEneIIR ); + + eqVal = Sqrt32( temp_div, &e_div ); + + Word16 comp_flag = BASOP_Util_Cmp_Mant32Exp( 1073741824, 3, eqVal, e_div ); + IF( EQ_16( comp_flag, -1 ) ) + eqVal = 1073741824; // 4inQ28 + ELSE + { + eqVal = L_shl( eqVal, sub( e_div, 3 ) ); // Q28 + } + + FOR( slot = 0; slot < nSlots; slot++ ) + { + FOR( ch = 0; ch < 2; ch++ ) + { + FOR( bin = bin_lo; bin < bin_hi; bin++ ) + { + if ( ( ch == 0 && slot == 0 ) ) + { + if ( bin == 1 ) + bin = bin; + } + + Word16 temp_shift = s_min( norm_l( inRe_fx[ch][slot][bin] ), norm_l( inIm_fx[ch][slot][bin] ) ); + re = L_shl( inRe_fx[ch][slot][bin], temp_shift ); + img = L_shl( inIm_fx[ch][slot][bin], temp_shift ); + + re = L_shr( Mpy_32_32( re, eqVal ), sub( temp_shift, 3 ) ); + img = L_shr( Mpy_32_32( img, eqVal ), sub( temp_shift, 3 ) ); + inRe_fx[ch][slot][bin] = re; // q_inp + inIm_fx[ch][slot][bin] = img; // q_inp + } + } + } + } + + + hHeadTrackData->q_chEneIIR = q_chEneIIR; + hHeadTrackData->q_procChEneIIR = q_procChEneIIR; + return; +} + +#else static void adaptTransportSignalsHeadtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -2787,6 +3061,153 @@ static void adaptTransportSignalsHeadtracked( return; } +#endif + +#ifdef IVAS_FLOAT_FIXED +static void ivas_dirac_dec_binaural_check_and_switch_transports_headtracked_fx( + COMBINED_ORIENTATION_HANDLE hHeadTrackData, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + const Word16 nBins, + const Word16 nSlots, + Word32 Rmat_fx[3][3] ) +{ + Word16 slot, bin, ch; + Word32 tmpVal; + Word16 norm, e_div, shift = 31; + Word32 Re, Im, temp_div; + + /* When not currently in prototype signal left-right switching procedure, check if such switching is needed */ + IF( EQ_16( (Word16) hHeadTrackData->lrSwitchedNext, (Word16) hHeadTrackData->lrSwitchedCurrent ) ) + { + Word32 thresholdDotProduct = 182536112; // 0.17 in Q30// /* Corresponds to 10-degree switching threshold */ + IF( EQ_16( (Word16) hHeadTrackData->lrSwitchedCurrent, 0 ) && ( LT_32( Rmat_fx[1][1], L_negate( thresholdDotProduct ) ) ) ) + { + hHeadTrackData->lrSwitchedNext = 1; + } + IF( EQ_16( (Word16) hHeadTrackData->lrSwitchedCurrent, 1 ) && ( GT_32( Rmat_fx[1][1], thresholdDotProduct ) ) ) + { + hHeadTrackData->lrSwitchedNext = 0; + } + } + + FOR( Word16 i = 0; i < 2; i++ ) + { + FOR( Word16 j = 0; j < nSlots; j++ ) + { + norm = s_min( L_norm_arr( inRe_fx[i][j], nBins ), L_norm_arr( inIm_fx[i][j], nBins ) ); + shift = s_min( norm, shift ); + } + } + + shift = sub( shift, 3 ); // guard bits// + /* When currently in interpolation */ + IF( NE_16( (Word16) hHeadTrackData->lrSwitchedNext, (Word16) hHeadTrackData->lrSwitchedCurrent ) ) + { + FOR( slot = 0; slot < nSlots; slot++ ) + { + Word32 switchOrderFactor, origOrderFactor; + Word16 e_switchOrderFactor, e_origOrderFactor; + + hHeadTrackData->lrSwitchInterpVal_fx = L_add( hHeadTrackData->lrSwitchInterpVal_fx, 2684354 ); /* Corresponds to 0.5 seconds interpolation time */ // Q14 + + IF( GT_32( hHeadTrackData->lrSwitchInterpVal_fx, 1072668096 ) ) + { + /* Stop interpolation, reset values */ + hHeadTrackData->lrSwitchInterpVal_fx = 0; + hHeadTrackData->lrSwitchedCurrent = hHeadTrackData->lrSwitchedNext; + } + + /* Gains for determining portion of switched channel order and original channel order */ + tmpVal = Mpy_32_16_1( hHeadTrackData->lrSwitchInterpVal_fx, (Word16) hHeadTrackData->lrSwitchedNext ); // Q15 + tmpVal = L_add( tmpVal, Mpy_32_16_1( L_sub( ONE_IN_Q30, hHeadTrackData->lrSwitchInterpVal_fx ), (Word16) hHeadTrackData->lrSwitchedCurrent ) ); // Q15 + + e_switchOrderFactor = 0; + e_origOrderFactor = 0; + IF( EQ_32( tmpVal, 32768 ) ) + tmpVal = ONE_IN_Q31; + ELSE + tmpVal = L_shl( tmpVal, 16 ); // Q31 + switchOrderFactor = Sqrt32( tmpVal, &e_switchOrderFactor ); + switchOrderFactor = L_shl( switchOrderFactor, e_switchOrderFactor ); // Q31 + origOrderFactor = Sqrt32( L_sub( ONE_IN_Q31, tmpVal ), &e_origOrderFactor ); // Q31 + origOrderFactor = L_shl( origOrderFactor, e_origOrderFactor ); + FOR( bin = 0; bin < nBins; bin++ ) + { + /* determine original order (1) signals and switched order (2) signals */ + Word32 re1[BINAURAL_CHANNELS], re2[BINAURAL_CHANNELS], im1[BINAURAL_CHANNELS], im2[BINAURAL_CHANNELS]; + + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + re1[ch] = Mpy_32_32( inRe_fx[ch][slot][bin], origOrderFactor ); // q_inp + re2[ch] = Mpy_32_32( inRe_fx[1 - ch][slot][bin], switchOrderFactor ); // q_inp + im1[ch] = Mpy_32_32( inIm_fx[ch][slot][bin], origOrderFactor ); // q_inp + im2[ch] = Mpy_32_32( inIm_fx[1 - ch][slot][bin], switchOrderFactor ); // q_inp + } + + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + Word32 eneRef, ene, eq; + + re1[ch] = L_shl( re1[ch], shift ); // q_inp+shift// + re2[ch] = L_shl( re2[ch], shift ); // q_inp+shift// + im1[ch] = L_shl( im1[ch], shift ); // q_inp+shift// + im2[ch] = L_shl( im2[ch], shift ); // q_inp+shift// + + /* Interpolate / mix original and switched order signals */ + Re = L_add( re1[ch], re2[ch] ); // q_inp+shift// + Im = L_add( im1[ch], im2[ch] ); // q_inp+shift// + + /* Equalize interpolated signals to preserve energy per bin */ + + eneRef = L_add( ( L_add( Mpy_32_32( re1[ch], re1[ch] ), Mpy_32_32( re2[ch], re2[ch] ) ) ), ( L_add( Mpy_32_32( im1[ch], im1[ch] ), Mpy_32_32( im2[ch], im2[ch] ) ) ) ); // 2*(q_inp+shift) -31// + ene = L_add( Mpy_32_32( Re, Re ), Mpy_32_32( Im, Im ) ); // 2*(q_inp+shift) -31// + + temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( eneRef, L_max( 1, ene ), &e_div ) ); + + eq = Sqrt32( temp_div, &e_div ); + + Word16 comp_flag = BASOP_Util_Cmp_Mant32Exp( 1073741824, 3, eq, e_div ); + IF( EQ_16( comp_flag, -1 ) ) + eq = 1073741824; // 4inQ28 + ELSE + { + eq = L_shl( eq, sub( e_div, 3 ) ); // Q28 + } + + Re = L_shr( Mpy_32_32( Re, eq ), sub( shift, 3 ) ); // q_inp + Im = L_shr( Mpy_32_32( Im, eq ), sub( shift, 3 ) ); // q_inp + + inRe_fx[ch][slot][bin] = Re; + inIm_fx[ch][slot][bin] = Im; + } + } + } + } + ELSE + { + /* If not in interpolation, but in switched prototype situation, then switch left and right channels */ + IF( hHeadTrackData->lrSwitchedCurrent == 1 ) + { + FOR( slot = 0; slot < nSlots; slot++ ) + { + FOR( bin = 0; bin < nBins; bin++ ) + { + tmpVal = inRe_fx[0][slot][bin]; + inRe_fx[0][slot][bin] = inRe_fx[1][slot][bin]; + inRe_fx[1][slot][bin] = tmpVal; + tmpVal = inIm_fx[0][slot][bin]; + inIm_fx[0][slot][bin] = inIm_fx[1][slot][bin]; + inIm_fx[1][slot][bin] = tmpVal; + } + } + } + } + + return; +} + +#endif static void ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, @@ -4106,6 +4527,14 @@ static void ivas_masa_ext_rend_parambin_internal( int16_t i, j; int16_t nchan_transport; +#ifdef IVAS_FLOAT_FIXED + Word32 *output_fx[MAX_OUTPUT_CHANNELS]; + Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 Cldfb_RealBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Rmat_fx[3][3]; +#endif + hDiracDecBin = hMasaExtRend->hDiracDecBin; assert( hDiracDecBin ); hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; @@ -4127,6 +4556,27 @@ static void ivas_masa_ext_rend_parambin_internal( /* The input channel number at this processing function (not nchan_transport) */ numInChannels = BINAURAL_CHANNELS; + Rmat_fx[0][0] = ONE_IN_Q31; + move32(); + Rmat_fx[0][1] = 0; + move32(); + Rmat_fx[0][2] = 0; + move32(); + + Rmat_fx[1][0] = 0; + move32(); + Rmat_fx[1][1] = ONE_IN_Q31; + move32(); + Rmat_fx[1][2] = 0; + move32(); + + Rmat_fx[2][0] = 0; + move32(); + Rmat_fx[2][1] = 0; + move32(); + Rmat_fx[2][2] = ONE_IN_Q31; + move32(); + Rmat[0][0] = 1.0f; Rmat[0][1] = 0.0f; Rmat[0][2] = 0.0f; @@ -4171,15 +4621,39 @@ static void ivas_masa_ext_rend_parambin_internal( { for ( j = 0; j < 3; j++ ) { +#ifdef IVAS_FLOAT_FIXED + Rmat_fx[i][j] = hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i][j]; // Q30// +#endif Rmat[i][j] = hCombinedOrientationData->Rmat[hCombinedOrientationData->subframe_idx][i][j]; } } - if ( nchan_transport == 2 ) + IF(EQ_16(nchan_transport, 2)) { - adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); +#ifdef IVAS_FLOAT_FIXED + Word16 q_inp = Q6; + FOR(Word16 cha = 0; cha < 2; cha++) + FOR(slot = 0; slot < 4; slot++) + FOR(Word16 ind = 0; ind < 60; ind++) + { + Cldfb_RealBuffer_in_fx[cha][slot][ind] = float_to_fix(Cldfb_RealBuffer_in[cha][slot][ind], q_inp); + Cldfb_ImagBuffer_in_fx[cha][slot][ind] = float_to_fix(Cldfb_ImagBuffer_in[cha][slot][ind], q_inp); + } + adaptTransportSignalsHeadtracked_fx(hCombinedOrientationData, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_inp, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat_fx); + + ivas_dirac_dec_binaural_check_and_switch_transports_headtracked_fx(hCombinedOrientationData, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat_fx); + FOR(Word16 cha = 0; cha < 2; cha++) + FOR(slot = 0; slot < 4; slot++) + FOR(Word16 ind = 0; ind < 60; ind++) + { + Cldfb_RealBuffer_in[cha][slot][ind] = fix_to_float(Cldfb_RealBuffer_in_fx[cha][slot][ind], q_inp); + Cldfb_ImagBuffer_in[cha][slot][ind] = fix_to_float(Cldfb_ImagBuffer_in_fx[cha][slot][ind], q_inp); + } +#else + adaptTransportSignalsHeadtracked(hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat); - ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); + ivas_dirac_dec_binaural_check_and_switch_transports_headtracked(hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat); +#endif } } @@ -4200,10 +4674,6 @@ static void ivas_masa_ext_rend_parambin_internal( //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef IVAS_FLOAT_FIXED - Word32 *output_fx[MAX_OUTPUT_CHANNELS]; - Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 Cldfb_RealBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word16 q_out; Word16 q_mat = 15; Word16 q_inp = Q6; diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 82b1c2dad..9662620c5 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1559,6 +1559,8 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx = hDirAC_mem->proto_power_smooth_fx; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = Q31; + set_s( hDirACRend->q_buffer_energy, Q31, CLDFB_NO_CHANNELS_MAX ); + set_s( hDirACRend->q_buffer_intensity_real, Q31, CLDFB_NO_CHANNELS_MAX ); #endif /* Target and smoothed nrg factors/gains */ @@ -4440,6 +4442,108 @@ void ivas_dirac_dec_compute_diffuse_proto( return; } + +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * computeDirectionAngles_fx() + * + *------------------------------------------------------------------------*/ + +void computeDirectionAngles_fx( + Word32 *intensity_real_x_fx, + Word32 *intensity_real_y_fx, + Word32 *intensity_real_z_fx, + Word16 q_intensity_real, + const Word16 num_frequency_bands, + Word16 *azimuth, + Word16 *elevation ) +{ + Word16 k; + Word32 intensityNorm; + Word32 x, y, z, radius; + Word32 temp; + Word16 res, q_intensityNorm, exp, q_temp; + Word16 q_x, q_y, q_z, exp1, exp2, exp3, q_tmp1, q_tmp2; + Word32 x_re, y_re, z_re, tmp1, tmp2; + + exp = 0; + move16(); + + FOR( k = 0; k < num_frequency_bands; ++k ) + { + exp1 = norm_l( intensity_real_x_fx[k] ); + exp2 = norm_l( intensity_real_y_fx[k] ); + exp3 = norm_l( intensity_real_z_fx[k] ); + x_re = L_shl( intensity_real_x_fx[k], exp1 ); + y_re = L_shl( intensity_real_y_fx[k], exp2 ); + z_re = L_shl( intensity_real_z_fx[k], exp3 ); + + tmp1 = Mpy_32_32( x_re, x_re ); + q_tmp1 = sub( add( add( q_intensity_real, exp1 ), add( q_intensity_real, exp1 ) ), 31 ); + tmp2 = Mpy_32_32( y_re, y_re ); + q_tmp2 = sub( add( add( q_intensity_real, exp2 ), add( q_intensity_real, exp2 ) ), 31 ); + + temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); + + tmp2 = Mpy_32_32( z_re, z_re ); + q_tmp2 = sub( add( add( q_intensity_real, exp3 ), add( q_intensity_real, exp3 ) ), 31 ); + + intensityNorm = BASOP_Util_Add_Mant32Exp( temp, exp, tmp2, sub( 31, q_tmp2 ), &exp ); + q_intensityNorm = sub( 31, exp ); + + IF( LE_32( intensityNorm, EPSILON_FX ) ) + { + intensityNorm = ONE_IN_Q30; + move32(); + x = ONE_IN_Q30; + move32(); + q_x = Q30; + move16(); + y = 0; + move32(); + q_y = Q30; + move16(); + z = 0; + move32(); + q_z = Q30; + move16(); + } + ELSE + { + temp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, intensityNorm, &exp ); + exp = sub( exp, sub( Q30, q_intensityNorm ) ); + temp = Sqrt32( temp, &exp ); + q_temp = sub( 31, exp ); + + x = Mpy_32_32( x_re, temp ); + q_x = sub( add( add( q_intensity_real, exp1 ), q_temp ), 31 ); + y = Mpy_32_32( y_re, temp ); + q_y = sub( add( add( q_intensity_real, exp2 ), q_temp ), 31 ); + z = Mpy_32_32( z_re, temp ); + q_z = sub( add( add( q_intensity_real, exp3 ), q_temp ), 31 ); + } + + tmp1 = Mpy_32_32( x, x ); + q_tmp1 = sub( add( q_x, q_x ), 31 ); + + tmp2 = Mpy_32_32( y, y ); + q_tmp2 = sub( add( q_y, q_y ), 31 ); + + temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); + radius = Sqrt32( temp, &exp ); + + res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); // Q13 + azimuth[k] = add( s_max( -23040, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ) / ONE_IN_Q7; // Q0; + move16(); + + res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); // Q13 + elevation[k] = add( s_max( -11520, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ) / ONE_IN_Q7; // Q0; + move16(); + } + + return; +} +//#else /*------------------------------------------------------------------------- * computeDirectionAngles() * @@ -4487,7 +4591,7 @@ void computeDirectionAngles( return; } - +#endif /*------------------------------------------------------------------------- * ivas_masa_init_stereotype_detection() @@ -4837,6 +4941,68 @@ void ivas_masa_stereotype_detection( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * computeIntensityVector_dec() + * + * + *------------------------------------------------------------------------*/ + +void computeIntensityVector_dec_fx( + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word16 q_cldfb, + const Word16 num_frequency_bands, + Word32 *intensity_real_x_fx, + Word32 *intensity_real_y_fx, + Word32 *intensity_real_z_fx, + Word16 *q_intensity_real ) +{ + /* + * W = a + ib; Y = c + id + * real(W*Y') = ac + bd + */ + Word16 i; + Word32 re1, re2, im1, im2; + Word16 min_q_shift; + + min_q_shift = Q31; + /* calculate the max possible shift for the buffers Cldfb_RealBuffer_fx and Cldfb_ImagBuffer_fx*/ + FOR( i = 0; i < 4; i++ ) + { + min_q_shift = s_min( min_q_shift, s_min( L_norm_arr( Cldfb_RealBuffer_fx[i][0], num_frequency_bands ), L_norm_arr( Cldfb_ImagBuffer_fx[i][0], num_frequency_bands ) ) ); + } + + min_q_shift = sub( min_q_shift, 1 ); // guard bits + + FOR( i = 0; i < num_frequency_bands; ++i ) + { + re1 = L_shl( Cldfb_RealBuffer_fx[0][0][i], min_q_shift ); + im1 = L_shl( Cldfb_ImagBuffer_fx[0][0][i], min_q_shift ); + re2 = L_shl( Cldfb_RealBuffer_fx[3][0][i], min_q_shift ); + im2 = L_shl( Cldfb_ImagBuffer_fx[3][0][i], min_q_shift ); + + intensity_real_x_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + move32(); + + re2 = L_shl( Cldfb_RealBuffer_fx[1][0][i], min_q_shift ); + im2 = L_shl( Cldfb_ImagBuffer_fx[1][0][i], min_q_shift ); + + intensity_real_y_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + move32(); + + re2 = L_shl( Cldfb_RealBuffer_fx[2][0][i], min_q_shift ); + im2 = L_shl( Cldfb_ImagBuffer_fx[2][0][i], min_q_shift ); + + intensity_real_z_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + move32(); + } + + *q_intensity_real = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + + return; +} +//#else /*------------------------------------------------------------------------- * computeIntensityVector_dec() * @@ -4869,7 +5035,7 @@ void computeIntensityVector_dec( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 2ec9ce5f6..f39eeaf80 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -422,6 +422,18 @@ void initDiffuseResponses_fx( ); #endif +#ifdef IVAS_FLOAT_FIXED +void computeIntensityVector_dec_fx( + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word16 q_cldfb, + const Word16 num_frequency_bands, + Word32 *intensity_real_x_fx, + Word32 *intensity_real_y_fx, + Word32 *intensity_real_z_fx, + Word16 *q_intensity_real +); +//#else void computeIntensityVector_dec( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -430,6 +442,7 @@ void computeIntensityVector_dec( float *intensity_real_y, float *intensity_real_z ); +#endif #ifdef IVAS_FLOAT_FIXED void protoSignalComputation_shd_fx( Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -577,6 +590,17 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( ); #endif +#ifdef IVAS_FLOAT_FIXED +void computeDirectionAngles_fx( + Word32 *intensity_real_x_fx, + Word32 *intensity_real_y_fx, + Word32 *intensity_real_z_fx, + Word16 q_intensity_real, + const Word16 num_frequency_bands, + Word16 *azimuth, + Word16 *elevation +); +//#else void computeDirectionAngles( float *intensity_real_x, float *intensity_real_y, @@ -585,6 +609,7 @@ void computeDirectionAngles( int16_t *azimuth, int16_t *elevation ); +#endif void ivas_masa_init_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 030c503e0..7d36ca793 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -1669,6 +1669,9 @@ ivas_error ivas_combined_orientation_open( ( *hCombinedOrientationData )->lrSwitchedNext = 0; ( *hCombinedOrientationData )->lrSwitchedCurrent = 0; ( *hCombinedOrientationData )->lrSwitchInterpVal = 0.0f; +#ifdef IVAS_FLOAT_FIXED + (*hCombinedOrientationData)->lrSwitchInterpVal_fx = 0; +#endif ( *hCombinedOrientationData )->isInterpolationOngoing = FALSE; ( *hCombinedOrientationData )->Quaternions_ext_interpolation_start = identity; ( *hCombinedOrientationData )->Quaternions_ext_interpolation_target = identity; @@ -1702,6 +1705,14 @@ ivas_error ivas_combined_orientation_open( set_zero( ( *hCombinedOrientationData )->chEneIIR[1], MASA_FREQUENCY_BANDS ); set_zero( ( *hCombinedOrientationData )->procChEneIIR[0], MASA_FREQUENCY_BANDS ); set_zero( ( *hCombinedOrientationData )->procChEneIIR[1], MASA_FREQUENCY_BANDS ); +#ifdef IVAS_FLOAT_FIXED + set_zero_fx((*hCombinedOrientationData)->chEneIIR_fx[0], MASA_FREQUENCY_BANDS); + set_zero_fx((*hCombinedOrientationData)->chEneIIR_fx[1], MASA_FREQUENCY_BANDS); + set_zero_fx((*hCombinedOrientationData)->procChEneIIR_fx[0], MASA_FREQUENCY_BANDS); + set_zero_fx((*hCombinedOrientationData)->procChEneIIR_fx[1], MASA_FREQUENCY_BANDS); + (*hCombinedOrientationData)->q_chEneIIR = Q31; + (*hCombinedOrientationData)->q_procChEneIIR = Q31; +#endif ( *hCombinedOrientationData )->isExtOrientationFrozen = 0; ( *hCombinedOrientationData )->isHeadRotationFrozen = 0; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 9a3b054f2..1d234c57b 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -226,6 +226,7 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure float **energy_ratio2; #ifdef IVAS_FLOAT_FIXED Word32 **diffuseness_vector_fx; + Word16 q_diffuseness_vector; Word32 **energy_ratio1_fx; Word32 **energy_ratio2_fx; #endif @@ -603,8 +604,10 @@ typedef struct ivas_dirac_rend_data_structure float *frequency_axis; float *diffuse_response_function; #ifdef IVAS_FLOAT_FIXED - Word16 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; - Word16 *buffer_energy_fx; + Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; + Word16 q_buffer_intensity_real[CLDFB_NO_CHANNELS_MAX]; + Word32 *buffer_energy_fx; + Word16 q_buffer_energy[CLDFB_NO_CHANNELS_MAX]; Word16 *diffuse_response_function_fx; Word16 diffuse_response_function_q; // Q15 Word16 *frequency_axis_fx; @@ -1095,6 +1098,13 @@ typedef struct ivas_combined_orientation_struct Word32 Rmat_prev_fx[3][3]; float chEneIIR[2][MASA_FREQUENCY_BANDS]; /* independent of the format. MASA bands are suitable for the task and readily available in ROM. */ float procChEneIIR[2][MASA_FREQUENCY_BANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 lrSwitchInterpVal_fx; + Word32 chEneIIR_fx[2][MASA_FREQUENCY_BANDS]; /* independent of the format. MASA bands are suitable for the task and readily available in ROM. */ + Word16 q_chEneIIR; + Word32 procChEneIIR_fx[2][MASA_FREQUENCY_BANDS]; + Word16 q_procChEneIIR; +#endif Word16 shd_rot_max_order; IVAS_VECTOR3 listenerPos[MAX_PARAM_SPATIAL_SUBFRAMES]; IVAS_QUATERNION Quaternion_frozen_ext; -- GitLab