diff --git a/lib_com/cnst.h b/lib_com/cnst.h index a77a8d8e0238ec05313f496099c3e155c1c6dccf..a1ec42fb9ea23d574405d905dfe0fd8f73c8bc2a 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -3008,6 +3008,8 @@ enum #define EVS_PI 3.14159265358979323846264338327950288f #define EVS_PI_FX 25736 /* pi in Q13 */ #define EVS_2PI_FX 51472 /* 2 * pi in Q13 */ +#define EVS_PI_FX_Q27 421657428 /* pi in Q28 */ +#define EVS_2PI_FX_Q27 843314856 /* 2 * pi in Q28 */ #define EVS_PI_BY_2_FX (Word16)(0x3244) //#define EVS_PI_FX (Word16)(0x6488) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 272cc4582d9c0301a752c14f51a2987195e9dd9a..ba197492c257d77ec79c58ad6ce8edb19cabd442 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -159,7 +159,7 @@ typedef struct stereo_dft_dec_data_struct #ifndef IVAS_FLOAT_FIXED float gipd[STEREO_DFT_DEC_DFT_NB]; #else - Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q13 */ + Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q27 */ #endif int16_t no_ipd_flag; /* flag to indicate when no IPD gets used */ @@ -197,9 +197,9 @@ typedef struct stereo_dft_dec_data_struct Word32 itd_xfade_target_fx; /* Q15 */ Word32 itd_xfade_prev_fx; /* Q15 */ - Word32 ipd_xfade_target_fx; /* Q13 */ - Word32 ipd_xfade_step_fx; /* Q13 */ - Word32 ipd_xfade_prev_fx; /* Q13 */ + Word32 ipd_xfade_target_fx; /* Q27 */ + Word32 ipd_xfade_step_fx; /* Q27 */ + Word32 ipd_xfade_prev_fx; /* Q27 */ Word32 res_pred_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* prediction gain for the residual HFs */ /* Q31 */ #endif int16_t res_pred_band_min; /* Band min for prediction of residual */ diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index d11dd6ba2e7c938db20bc51b4c50a4cdaf85a63b..2238d768f35a95e24be6bd67c9a412c29d38c1b5 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -838,14 +838,14 @@ void stereo_dft_dec_smooth_parameters_fx( #endif { Word16 q_val; - IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX ) ) + IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { - hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX ); + hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); - q_val = sub( q_val, Q2 ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); - IF( GT_16( q_val, 16 ) ) + IF( GT_16( q_val, 32 ) ) { assert( 0 ); } @@ -854,14 +854,14 @@ void stereo_dft_dec_smooth_parameters_fx( hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); } } - ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX ) ) + ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) { - hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX, 1 ) ); + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); - q_val = sub( q_val, Q2 ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); - IF( GT_16( q_val, 16 ) ) + IF( GT_16( q_val, 32 ) ) { assert( 0 ); } @@ -874,10 +874,10 @@ void stereo_dft_dec_smooth_parameters_fx( { hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); - q_val = sub( q_val, Q2 ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); - IF( GT_16( q_val, 16 ) ) + IF( GT_16( q_val, 32 ) ) { assert( 0 ); } @@ -1135,13 +1135,13 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); - IF( LT_32( diff_ipd, -EVS_PI_FX ) ) + IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) { - pgIpd[0] = L_add( L_add( pgIpd[0], EVS_PI_FX ), EVS_PI_FX ); + pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); } - ELSE IF( GT_32( diff_ipd, EVS_PI_FX ) ) + ELSE IF( GT_32( diff_ipd, EVS_PI_FX_Q27 ) ) { - pgIpd[0] = L_sub( L_sub( pgIpd[0], EVS_PI_FX ), EVS_PI_FX ); + pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); } IF( !hStereoDft->attackPresent ) @@ -1637,23 +1637,23 @@ void stereo_dft_dec_fx( IF( NE_32( pgIpd[0], 0 ) ) { Word32 theta = pgIpd[0]; - WHILE( GT_32( theta, EVS_2PI_FX ) ) + WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - WHILE( LT_32( theta, -EVS_2PI_FX ) ) + WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - IF( GT_32( theta, EVS_PI_FX ) ) + IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - ELSE IF( LT_32( theta, -EVS_PI_FX ) ) + ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - c0 = getCosWord16( extract_l( theta ) ); + c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) { c0 = MAX_16; @@ -1662,7 +1662,7 @@ void stereo_dft_dec_fx( { c0 = shl( c0, 1 ); } - s0 = getSinWord16( extract_l( theta ) ); + s0 = getSinWord16( (Word16) L_shr( theta, 14 ) ); FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ @@ -1902,23 +1902,23 @@ void stereo_dft_dec_fx( IF( NE_32( pgIpd[0], 0 ) ) { Word32 theta = pgIpd[0]; - WHILE( GT_32( theta, EVS_2PI_FX ) ) + WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - WHILE( LT_32( theta, -EVS_2PI_FX ) ) + WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - IF( GT_32( theta, EVS_PI_FX ) ) + IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - ELSE IF( LT_32( theta, -EVS_PI_FX ) ) + ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - c0 = getCosWord16( extract_l( theta ) ); + c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) { c0 = MAX_16; @@ -1927,7 +1927,7 @@ void stereo_dft_dec_fx( { c0 = shl( c0, 1 ); } - s0 = getSinWord16( extract_l( theta ) ); + s0 = getSinWord16( (Word16) L_shr( theta, 14 ) ); FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ @@ -2335,6 +2335,7 @@ static void stereo_dft_dequantize_ipd_fx( { Word16 i; Word16 delta_fx; + Word32 temp_out; IF( EQ_16( bits, 2 ) ) /* 2-bit phase quantization for the highest frequency band only */ { delta_fx = ( EVS_PI_FX ) >> 1; @@ -2355,7 +2356,8 @@ static void stereo_dft_dequantize_ipd_fx( FOR( i = 0; i < N; i++ ) { - *out_fx = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); + temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); + *out_fx = L_shl( temp_out, 14 ); } return; }