diff --git a/lib_com/ivas_agc_com_fx.c b/lib_com/ivas_agc_com_fx.c index db5ae0d2147176fd1dcb793ba0bf888d5bca3b12..26bbe659034fa8f93c7b5b09be6bc4df7075811d 100644 --- a/lib_com/ivas_agc_com_fx.c +++ b/lib_com/ivas_agc_com_fx.c @@ -58,35 +58,35 @@ *-----------------------------------------------------------------------------------------*/ void ivas_agc_initWindowFunc_fx( - Word16 *pWinFunc, + Word16 *pWinFunc, // o: Q15 const Word16 length ) { Word16 i; Word16 a; const Word16 *cos_val; - a = A_FX; /* for DBSTEP -6.f */ + a = A_FX; /* for DBSTEP -6.f */ // Q15 move16(); SWITCH( length ) { case 128: - cos_val = cos_pi_by_127; + cos_val = cos_pi_by_127; // Q15 BREAK; case 256: - cos_val = cos_pi_by_255; + cos_val = cos_pi_by_255; // Q15 BREAK; case 384: - cos_val = cos_pi_by_383; + cos_val = cos_pi_by_383; // Q15 BREAK; default: - cos_val = cos_pi_by_383; + cos_val = cos_pi_by_383; // Q15 BREAK; } FOR( i = 0; i < length; i++ ) { - pWinFunc[i] = add( MAX_16, extract_l( Mpy_32_16_1( L_sub( cos_val[i], MAX_16 ), a ) ) ); + pWinFunc[i] = add( MAX_16, extract_l( Mpy_32_16_1( L_sub( cos_val[i], MAX_16 ), a ) ) ); // Q15 + Q15 - 15 = Q15 move16(); } @@ -100,9 +100,9 @@ void ivas_agc_initWindowFunc_fx( *-----------------------------------------------------------------------------------------*/ void ivas_agc_calcGainParams_fx( - UWord16 *absEmin, - UWord16 *betaE, - UWord16 *maxAttExp, + UWord16 *absEmin, // o: Q0 + UWord16 *betaE, // o: Q0 + UWord16 *maxAttExp, // o: Q0 const Word16 numCoeffs ) { assert( numCoeffs == IVAS_SPAR_MAX_DMX_CHS ); diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 1356d695eccdec5054deb00d227fd83d73bcaa42..4f3aa5ae17f09ed0f6fdbf4957a0091ade3e34e8 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -45,44 +45,44 @@ #define PI_OVER_2 ( EVS_PI / 2.0f ) #define PI_OVER_180 ( EVS_PI / 180.0f ) -#define ONE_BY_PI_OVER_180_Q25 ( 1922527360 ) -#define PI_OVER_180_Q22 ( 73204 ) +#define ONE_BY_PI_OVER_180_Q25 ( 1922527360 ) // Q25 +#define PI_OVER_180_Q22 ( 73204 ) // Q22 #define _180_OVER_PI ( 180.0f / EVS_PI ) #ifdef IVAS_FLOAT_FIXED -#define _180_OVER_PI_Q25 1922527338 -#define PI_OVER_180_Q25 ( 585635 ) -#define _180_IN_Q22 (754974720) -#define _360_IN_Q22 (1509949440) -#define _180_OVER_PI_FX (Word32) (( 180.0f / EVS_PI ) *ONE_IN_Q10) -#define PI_OVER_180_Q15 ( 572 ) -#define _180_OVER_PI_Q9 ( 29335 ) -#define PI_OVER_4_Q29 421657440 -#define _180_OVER_PI_Q9 ( 29335 ) -#define PI_OVER_Q29 1686629760 -#define Q31_0_99 2126008811 -#define Q31_0_01 21474836 -#define PI_OVER_180_FX (Word32) (( EVS_PI / 180.0f ) * ONE_IN_Q31) +#define _180_OVER_PI_Q25 ( 1922527338 ) // Q25 +#define PI_OVER_180_Q25 ( 585635 ) // Q25 +#define _180_IN_Q22 ( 754974720 ) // Q22 +#define _360_IN_Q22 ( 1509949440 ) // Q22 +#define _180_OVER_PI_FX ( (Word32) ( ( 180.0f / EVS_PI ) * ONE_IN_Q10 ) ) +#define PI_OVER_180_Q15 ( 572 ) // Q15 +#define _180_OVER_PI_Q9 ( 29335 ) // Q9 +#define PI_OVER_4_Q29 ( 421657440 ) // Q29 +#define _180_OVER_PI_Q9 ( 29335 ) // Q9 +#define PI_OVER_Q29 ( 1686629760 ) // Q29 +#define Q31_0_99 ( 2126008811 ) // Q31 +#define Q31_0_01 ( 21474836 ) // Q31 +#define PI_OVER_180_FX ( (Word32) ( ( EVS_PI / 180.0f ) * ONE_IN_Q31 ) ) // Q31 #endif -#define PI_OVER_4_Q29 421657440 -#define PI_OVER_Q29 1686629760 -#define PI2_C_ADP_RATE_Q31 449767936 //(2.0f * EVS_PI * pOTR->centerAdaptationRate)// -#define PI2_C_Q28 1686629760 -#define OFF_C_ADP_RATE_Q31 268435456 -#define C_ADP_RATE_Q31 71582792 +#define PI_OVER_4_Q29 ( 421657440 ) // Q29 +#define PI_OVER_Q29 ( 1686629760 ) // Q29 +#define PI2_C_ADP_RATE_Q31 ( 449767936 ) // Q31 (2.0f * EVS_PI * pOTR->centerAdaptationRate) +#define PI2_C_Q28 ( 1686629760 ) // Q28 +#define OFF_C_ADP_RATE_Q31 ( 268435456 ) // Q31 +#define C_ADP_RATE_Q31 ( 71582792 ) // Q31 #define SQRT2 1.414213562373095f -#define SQRT2_FIXED 1518500250 // Q30 +#define SQRT2_FIXED 1518500250 // Q30 #define SQRT2_OVER_2 (SQRT2 / 2.0f) -#define SQRT2_OVER_2_FIXED 1518500250 // Q31 +#define SQRT2_OVER_2_FIXED 1518500250 // Q31 #define INV_SQRT2 7.071067811865475e-1f /* 1/sqrt(2) */ #define INV_SQRT3 0.577350269189626f /* 1/sqrt(3) */ -#define INV_SQRT2_FX 1518500224 /* 1/sqrt(2) in Q31 */ +#define INV_SQRT2_FX ( 1518500224 ) /* 1/sqrt(2) in Q31 */ #ifdef IVAS_FLOAT_FIXED -#define INV_SQRT2_FX_Q15 23170 /* 1/sqrt(2) Q15*/ -#define INV_SQRT3_FX 18918 /* 1/sqrt(3) Q15*/ +#define INV_SQRT2_FX_Q15 ( 23170 ) /* 1/sqrt(2) Q15 */ +#define INV_SQRT3_FX ( 18918 ) /* 1/sqrt(3) Q15 */ #endif #define LOG_10 2.30258509299f @@ -341,32 +341,32 @@ typedef enum #define ISM_AZIMUTH_NBITS 7 #define ISM_AZIMUTH_MIN -180.0f #define ISM_AZIMUTH_MAX 180.0f -#define ISM_AZIMUTH_MIN_FX -754974720 -#define ISM_AZIMUTH_MAX_FX 754974720 +#define ISM_AZIMUTH_MIN_FX ( -754974720 ) // Q22 +#define ISM_AZIMUTH_MAX_FX ( 754974720 ) // Q22 #define ISM_AZIMUTH_LOW_BORDER -140.0f #define ISM_AZIMUTH_HIGH_BORDER 135.0f -#define ISM_AZIMUTH_LOW_BORDER_FX -587202560 -#define ISM_AZIMUTH_HIGH_BORDER_FX 566231040 +#define ISM_AZIMUTH_LOW_BORDER_FX ( -587202560 ) // Q22 +#define ISM_AZIMUTH_HIGH_BORDER_FX ( 566231040 ) // Q22 #define ISM_ELEVATION_NBITS 6 #define ISM_ELEVATION_MIN -90.0f #define ISM_ELEVATION_MAX 90.0f -#define ISM_ELEVATION_MIN_FX -377487360 -#define ISM_ELEVATION_MAX_FX 377487360 +#define ISM_ELEVATION_MIN_FX ( -377487360 ) // Q22 +#define ISM_ELEVATION_MAX_FX ( 377487360 ) // Q22 #define ISM_ELEVATION_LOW_BORDER -70.0f #define ISM_ELEVATION_HIGH_BORDER 65.0f -#define ISM_ELEVATION_LOW_BORDER_FX -293601280 -#define ISM_ELEVATION_HIGH_BORDER_FX 272629760 +#define ISM_ELEVATION_LOW_BORDER_FX ( -293601280 ) // Q22 +#define ISM_ELEVATION_HIGH_BORDER_FX ( 272629760 ) // Q22 #define ISM_Q_STEP 2.5f -#define ISM_Q_STEP_FX 10485760 +#define ISM_Q_STEP_FX ( 10485760 ) // Q22 #define ISM_Q_STEP_BORDER 5.0f -#define ISM_Q_STEP_BORDER_FX 20971520 +#define ISM_Q_STEP_BORDER_FX ( 20971520 ) // Q22 #define ISM_RADIUS_NBITS 6 #define ISM_RADIUS_MIN 0.0f #define ISM_RADIUS_MIN_Q9 0 #define ISM_RADIUS_DELTA 0.25f /* Max radius = (2^ISM_RADIUS_NBITS-1)*0.25 = 15.75 */ -#define ISM_RADIUS_DELTA_Q8 64 +#define ISM_RADIUS_DELTA_Q8 64 // Q8 #define ISM_EXTENDED_METADATA_BRATE IVAS_64k #define ISM_METADATA_IS_NDP_BITS 1 #define ISM_EXTENDED_METADATA_BITS 1 @@ -388,21 +388,21 @@ typedef enum #define STEP_PARAM_ISM_POW_RATIO_NBITS_Q15 (4681) /* 1.0f / (float)((1 << PARAM_ISM_POW_RATIO_NBITS) - 1) */ /* ISM DTX */ -#define ISM_Q_STEP_FX 10485760 -#define ISM_Q_STEP_BORDER_FX 20971520 +#define ISM_Q_STEP_FX ( 10485760 ) // Q22 +#define ISM_Q_STEP_BORDER_FX ( 20971520 ) // Q22 #define ISM_DTX_COH_SCA_BITS 4 #define ISM_DTX_AZI_BITS_HIGH 8 #define ISM_DTX_ELE_BITS_HIGH 7 #define ISM_Q_STEP_HIGH (ISM_Q_STEP / 2) #define ISM_Q_STEP_BORDER_HIGH (ISM_Q_STEP_BORDER / 2) -#define ISM_Q_STEP_HIGH_FX 5 * (1 << (22-2)) -#define ISM_Q_STEP_BORDER_HIGH_FX 5 * (1 << (22-1)) +#define ISM_Q_STEP_HIGH_FX ( 5 * ( 1 << ( 22 - 2 ) ) ) // Q22 +#define ISM_Q_STEP_BORDER_HIGH_FX ( 5 * ( 1 << ( 22 - 1 ) ) ) // Q22 #define ISM_DTX_AZI_BITS_LOW 6 #define ISM_DTX_ELE_BITS_LOW 5 #define ISM_Q_STEP_LOW (ISM_Q_STEP * 2) #define ISM_Q_STEP_BORDER_LOW (ISM_Q_STEP_BORDER * 2) -#define ISM_Q_STEP_LOW_FX 5 * (1 << 22) -#define ISM_Q_STEP_BORDER_LOW_FX 10 * (1 << 22) +#define ISM_Q_STEP_LOW_FX ( 5 * (1 << 22) ) // Q22 +#define ISM_Q_STEP_BORDER_LOW_FX ( 10 * (1 << 22) ) // Q22 /* ISM modes */ typedef enum @@ -589,15 +589,15 @@ typedef enum #define STEREO_DFT_SIDEGAIN_NBITS 5 #define STEREO_DFT_FEC_THRESHOLD 10 #ifdef IVAS_FLOAT_FIXED -#define STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31 ( 195225786 ) -#define STEREO_DFT_BITDIFF_LP_FAC_Q31 ( 128849019 ) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ -#define STEREO_DFT_BITDIFF_ABS_SELECT_Q31 ( 1717986918 ) /* Constant to set tendency for selecting absolute coding mode */ +#define STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31 ( 195225786 ) // Q31 +#define STEREO_DFT_BITDIFF_LP_FAC_Q31 ( 128849019 ) // Q31 /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ +#define STEREO_DFT_BITDIFF_ABS_SELECT_Q31 ( 1717986918 ) // Q31 /* Constant to set tendency for selecting absolute coding mode */ #else #define STEREO_DFT_BITDIFF_LP_FAC (0.06f) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ #define STEREO_DFT_BITDIFF_ABS_SELECT (0.8f) /* Constant to set tendency for selecting absolute coding mode */ #endif #define STEREO_DFT_BITDIFF_INIT (12.0f) /* Init value for low-pass bit difference */ -#define STEREO_DFT_BITDIFF_INIT_FX (12288) /* Init value for low-pass bit difference in Q10*/ +#define STEREO_DFT_BITDIFF_INIT_FX (12288) // Q10 /* Init value for low-pass bit difference in Q10*/ #define STEREO_DFT_SIDE_GAIN_NBITS 5 #define STEREO_DFT_IPD_NBITS 3 @@ -619,8 +619,8 @@ typedef enum #define STEREO_DFT_COH_MAXBAND 6 #define STEREO_DFT_SID_GIPD_NBITS 2 #define STEREO_DFT_FD_FILT 0.9f -#define STEREO_DFT_FD_FILT_Q31 1932735283 -#define STEREO_DFT_FD_FILT_COMP_Q31 214748364 /* 1.0 - STEREO_DFT_FD_FILT */ +#define STEREO_DFT_FD_FILT_Q31 1932735283 // Q31 +#define STEREO_DFT_FD_FILT_COMP_Q31 214748364 // Q31 /* 1.0 - STEREO_DFT_FD_FILT */ #define STEREO_DFT_CNG_ITD_CNT 8 @@ -646,9 +646,9 @@ typedef enum #define STEREO_DFT_RES_GAINS_BITS 3 #define STEREO_DFT_RES_COD_SNR_MIN 10 -#define STEREO_DFT_RES_COD_SNR_MIN_Q25 335544320 +#define STEREO_DFT_RES_COD_SNR_MIN_Q25 335544320 // Q25 #define STEREO_DFT_RES_COD_SNR_MAX 40 -#define STEREO_DFT_RES_COD_SNR_MAX_Q25 1342177280 +#define STEREO_DFT_RES_COD_SNR_MAX_Q25 1342177280 // Q25 #define STEREO_DFT_L_SUBFR_8k 32 #define STEREO_DFT_NBPSF_PIT_MAX_8k NBPSF_PIT_MAX / 2 @@ -731,9 +731,9 @@ enum #define ECSQ_GLOBAL_GAIN_INDEX_ALL_ZERO 127 /* indicates that all values in the vector are zero */ #define ECLVQ_GLOBAL_GAIN_FACTOR ( 20.0f * 127.0f / 90.0f ) -#define ECLVQ_GLOBAL_GAIN_FACTOR_Q26 1893961218 +#define ECLVQ_GLOBAL_GAIN_FACTOR_Q26 1893961218 // Q26 #define ECLVQ_INV_GLOBAL_GAIN_FACTOR ( 1.0f / ( 20.0f * 127.0f / 90.0f ) ) -#define ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24 594468 +#define ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24 594468 // Q24 /* the currently defined configuration indexes are: 0: un-optimized using uniform 4 bit parameters (reserved) @@ -826,12 +826,12 @@ enum fea_names #define STEREO_BITS_TCA_CORRSTATS 5 /* target corrStats */ #define STEREO_BITS_TCA_GD 5 /* target gain */ #define STEREO_TCA_GDMIN -1.0f -#define STEREO_TCA_GDMIN_FX -32768 +#define STEREO_TCA_GDMIN_FX -32768 // Q15 #define STEREO_TCA_GDSTEP 0.05f -#define STEREO_TCA_GDSTEP_FX 819 +#define STEREO_TCA_GDSTEP_FX 819 // Q14 #ifdef IVAS_FLOAT_FIXED -#define STEREO_TCA_GDMIN_FX_Q14 (-16384) -#define STEREO_TCA_GDSTEP_FX_Q13 (410) +#define STEREO_TCA_GDMIN_FX_Q14 (-16384) // Q14 +#define STEREO_TCA_GDSTEP_FX_Q13 (410) // Q13 #endif #define STEREO_BITS_TCA ( STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS + STEREO_BITS_TCA_GD ) @@ -848,14 +848,14 @@ enum fea_names #define MAX_DELAYREGLEN 12 /* max regression length */ #define INV_MAX_DELAYREGLEN 0.083333333333333f /* (1/MAX_DELAYREGLEN) */ -#define INV_MAX_DELAYREGLEN_FX_Q15 2731 /* (1/MAX_DELAYREGLEN) */ +#define INV_MAX_DELAYREGLEN_FX_Q15 2731 // Q15 /* (1/MAX_DELAYREGLEN) */ #define MAX_INTERPOLATE 11 #define ADDED_MEM_DS 40 #define STEREO_L_TCA_OVLP_NS 5000000L /* overlap length of the ICA gain scaling */ -#define STEREO_DMX_GAIN_Q13 29066 /* calculated this -->"powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN )"*/ +#define STEREO_DMX_GAIN_Q13 29066 // Q13 /* calculated this -->"powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN )"*/ /*----------------------------------------------------------------------------------* * TD Stereo Constants *----------------------------------------------------------------------------------*/ @@ -913,7 +913,7 @@ enum fea_names #define SNS_MEANS_BITS_4_FRAC 14 #define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG 0.001f -#define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31 2147483 +#define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31 2147483 // Q31 #define MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME 2 * FRAMES_PER_SEC #define MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN 20 #define MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE 3 @@ -1009,7 +1009,7 @@ typedef enum #define DIRAC_DIFF_NUM_AMBI_COMP 4 #define DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS 8 #define DIRAC_GAIN_LIMIT 31.622776601683793f /* 30db gain limitiation */ -#define DIRAC_GAIN_LIMIT_Q26 ( 2122168614 ) /* 30db gain limitiation */ +#define DIRAC_GAIN_LIMIT_Q26 ( 2122168614 ) // Q26 /* 30db gain limitiation */ #define DIRAC_MAX_NUM_DECORR_FILTERS 22 #define DIRAC_MAX_DECORR_FILTER_LEN 20 #define DIRAC_DECORR_NUM_SPLIT_BANDS 3 @@ -1020,10 +1020,10 @@ typedef enum #define DIRAC_ONSET_BETA 0.995f #define DIRAC_ONSET_GAIN 4.0f #ifdef IVAS_FLOAT_FIXED -#define DIRAC_ONSET_ALPHA_FX 31129//Q15 -#define DIRAC_ONSET_BETA_FX 32604 //Q15 -#define ONE_DIRAC_ONSET_BETA_FX 163 //Q15 -#define DIRAC_ONSET_GAIN_FX 16384 //Q12 +#define DIRAC_ONSET_ALPHA_FX 31129 // Q15 +#define DIRAC_ONSET_BETA_FX 32604 // Q15 +#define ONE_DIRAC_ONSET_BETA_FX 163 // Q15 +#define DIRAC_ONSET_GAIN_FX 16384 // Q12 #endif #define DELAY_DIRAC_ENC_CMP_NS 9500000L /* Delay to be compensated on DirAC encoder */ @@ -1263,7 +1263,7 @@ enum #endif #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f -#define STEP_M2T_FX 214748365 +#define STEP_M2T_FX 214748365 // Q31 #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 #define MASA_LOWBITRATE_MODE_BITS 1 @@ -1306,16 +1306,16 @@ enum #define MASA_COHERENCE_TOLERANCE 0.1f #define MASA_COHERENCE_THRESHOLD 0.1f #ifdef IVAS_FLOAT_FIXED -#define MASA_COHERENCE_TOLERANCE_FX 419430/*0.1 Q22*/ +#define MASA_COHERENCE_TOLERANCE_FX 419430 // 0.1 in Q22 #define MASA_COHERENCE_THRESHOLD_FX 214748365 // 0.1 in Q31 #endif #define MASA_RATIO_TOLERANCE 0.1f #define MASA_RATIO_THRESHOLD 0.1f #define MASA_ANGLE_TOLERANCE 0.5f #ifdef IVAS_FLOAT_FIXED -#define MASA_RATIO_THRESHOLD_FX 214748365 // 0.1 in Q31 -#define MASA_RATIO_TOLERANCE_FX 419430/*0.1 Q22*/ -#define MASA_ANGLE_TOLERANCE_FX ONE_IN_Q21/*0.5f q22*/ +#define MASA_RATIO_THRESHOLD_FX 214748365 // 0.1 in Q31 +#define MASA_RATIO_TOLERANCE_FX 419430 // 0.1 in Q22 +#define MASA_ANGLE_TOLERANCE_FX ONE_IN_Q21 // 0.5 in Q22 #endif #define MASA_LIMIT_NO_BANDS_SUR_COH 8 #define MINIMUM_BIT_BUDGET_NORMAL_META 100 @@ -1331,16 +1331,16 @@ enum #define MASA_NO_POINTS_EQUATOR 430 #define MASA_NO_CIRCLES 121 #ifdef IVAS_FLOAT_FIXED -#define MASA_NO_CIRCLES_Q23 ( 1015021568 ) +#define MASA_NO_CIRCLES_Q23 ( 1015021568 ) // Q23 #endif #define MASA_ASIN_OFFSET 0.0064471690266724975f -#define MASA_ASIN_OFFSET_Q15 ( 211 ) +#define MASA_ASIN_OFFSET_Q15 ( 211 ) // Q15 #define MASA_NTOT2_FAC 32768.00566947353f -#define MASA_NTOT2_FAC_Q15 ( 1073741952 ) +#define MASA_NTOT2_FAC_Q15 ( 1073741952 ) // Q15 #define MASA_ANGLE_AT_EQUATOR 0.012894427382667f -#define MASA_ANGLE_AT_EQUATOR_Q31 ( 27690572 ) +#define MASA_ANGLE_AT_EQUATOR_Q31 ( 27690572 ) // Q31 #define MASA_ANGLE_AT_EQUATOR_DEG 0.738796268264740f -#define MASA_ANGLE_AT_EQUATOR_DEG_Q31 ( 1586552905l ) +#define MASA_ANGLE_AT_EQUATOR_DEG_Q31 ( 1586552905l ) // Q31 #define MASA_INV_ANGLE_AT_EQUATOR_DEG 1.353553128183453f #define MASA_STEREO_MIN_BITRATE IVAS_24k4 #define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ @@ -1406,8 +1406,8 @@ typedef enum #define MCMASA_MAX_ANA_CHANS 11 /* Maximum number of channels currently used in analysis of multichannel formats */ #ifdef IVAS_FLOAT_FIXED -#define MCMASA_MONOBITRATIO_64k_Q31 ( 536870912 ) -#define MCMASA_MONOBITRATIO_Q31 ( 644245095 ) +#define MCMASA_MONOBITRATIO_64k_Q31 ( 536870912 ) // Q31 +#define MCMASA_MONOBITRATIO_Q31 ( 644245095 ) // Q31 #else #define MCMASA_MONOBITRATIO 0.3f #define MCMASA_MONOBITRATIO_64k 0.25f @@ -1420,21 +1420,21 @@ typedef enum #define MCMASA_LFE_ALPHA 0.67f #define MCMASA_LFE_BETA 0.09f #ifdef IVAS_FLOAT_FIXED -#define MCMASA_LFE_1BIT_THRES_Q30 32212255 /* 0.03f in Q30 */ +#define MCMASA_LFE_1BIT_THRES_Q30 32212255 /* 0.03f in Q30 */ #define MCMASA_LFE_ALPHA_Q30 719407022 /* 0.67f in Q30 */ -#define MCMASA_LFE_BETA_Q30 96636764 /* 0.09f in Q30 */ +#define MCMASA_LFE_BETA_Q30 96636764 /* 0.09f in Q30 */ #endif #define MCMASA_LFE_THETA 1.3f #define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */ #ifdef IVAS_FLOAT_FIXED -#define MCMASA_LFE_SYNTH_ALPHA_Q15 (31129) +#define MCMASA_LFE_SYNTH_ALPHA_Q15 (31129) // Q15 #endif -#define MCMASA_LFE_ALPHA_Q15 (21954) -#define MCMASA_LFE_BETA_Q15 (2949) -#define MCMASA_LFE_BETA_Q14 (1474) -#define MCMASA_LFE_THETA_Q14 (21299) -#define MCMASA_LFE_QLOW_Q12 (-26624) -#define MCMASA_LFE_DELTA_Q11 (2048) +#define MCMASA_LFE_ALPHA_Q15 (21954) // Q15 +#define MCMASA_LFE_BETA_Q15 (2949) // Q15 +#define MCMASA_LFE_BETA_Q14 (1474) // Q14 +#define MCMASA_LFE_THETA_Q14 (21299) // Q14 +#define MCMASA_LFE_QLOW_Q12 (-26624) // Q12 +#define MCMASA_LFE_DELTA_Q11 (2048) // Q11 #define NUM_ELEVATED_SPEAKERS 4 @@ -1534,8 +1534,8 @@ typedef enum } PARAM_MC_SYNTHESIS_CONF; #ifdef IVAS_FLOAT_FIXED -#define PARAM_MC_REG_SX_FX (429496729) /* Regularization factor for mixing matrix calculation */ -#define PARAM_MC_REG_GHAT_FX (2147483) /* Regularization factor for mixing matrix calculation */ +#define PARAM_MC_REG_SX_FX (429496729) // Q31 /* Regularization factor for mixing matrix calculation */ +#define PARAM_MC_REG_GHAT_FX (2147483) // Q31 /* Regularization factor for mixing matrix calculation */ #endif #define PARAM_MC_REG_SX (0.2f) /* Regularization factor for mixing matrix calculation */ @@ -1572,7 +1572,7 @@ typedef enum #define PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT 4 /* Number of bits for ILD uniform coding */ #define PARAM_MC_DEFAULT_MIN_ILD (-92.0f) /* Default relative channel level for untransmitted channel energies */ #ifdef IVAS_FLOAT_FIXED -#define PARAM_MC_DEFAULT_MIN_ILD_FX (-23552) /* Default relative channel level for untransmitted channel energies *//*Q8*/ +#define PARAM_MC_DEFAULT_MIN_ILD_FX (-23552) // Q8 /* Default relative channel level for untransmitted channel energies */ #endif // IVAS_FLOAT_FIXED #define PARAM_MC_MAX_BITS 1024 /* Maximum number of bits for the Parametric MC metadata */ #define PARAM_MC_MAX_BAND_ABS_COV_ENC 10 @@ -1586,11 +1586,11 @@ typedef enum #define PARAM_MC_ENER_LIMIT_MAX_DELTA_FAC_FX_Q21 31457280 #define PARAM_MC_NUM_ATTACK_ILD_THRESH (3) #define PARAM_MC_LFE_ON_THRESH (8000.0f) -#define PARAM_MC_LFE_ON_THRESH_FX 8000 //Q0 +#define PARAM_MC_LFE_ON_THRESH_FX 8000 // Q0 #define PARAM_MC_BAND_TO_MDCT_BAND_RATIO 16 /* Ratio of resolution of CLDFB Bands to MDCT Bands */ #define PARAM_MC_SLOT_ENC_NS 2500000L #define PARAM_MC_MDFT_NO_SLOTS 8 -#define INV_PARAM_MC_MDFT_NO_SLOTS_FX 4096 //Q15 +#define INV_PARAM_MC_MDFT_NO_SLOTS_FX 4096 // Q15 #define PARAM_MC_CLDFB_TO_MDFT_FAC 2 /*----------------------------------------------------------------------------------* @@ -1638,7 +1638,7 @@ typedef enum #define IVAS_ZERO_PAD_LEN_MULT_FAC (0.5f) -#define IVAS_ZERO_PAD_LEN_MULT_FAC_fx 16384 //0.5*Q15 +#define IVAS_ZERO_PAD_LEN_MULT_FAC_fx 16384 // 0.5 in Q15 /* LFE PLC */ #define LFE_PLC_BUFLEN 240 @@ -1654,10 +1654,10 @@ typedef enum /*----------------------------------------------------------------------------------* * HO Dirac Constants *----------------------------------------------------------------------------------*/ -#define HODIRAC_BETA (214748368) /* 0.2f in Q30 */ -#define HODIRAC_FAC1 (951579008) /* 1.772454f in Q29 */ -#define HODIRAC_FAC2 (549393984) /* 1.023326f in Q29 */ -#define HODIRAC_FAC3 (317192992) /* 0.590818f in Q29 */ +#define HODIRAC_BETA (214748368) /* 0.2f in Q30 */ +#define HODIRAC_FAC1 (951579008) /* 1.772454f in Q29 */ +#define HODIRAC_FAC2 (549393984) /* 1.023326f in Q29 */ +#define HODIRAC_FAC3 (317192992) /* 0.590818f in Q29 */ /*----------------------------------------------------------------------------------* * Amplitude Panning (EFAP, VBAP) constants @@ -1704,9 +1704,9 @@ typedef enum #define HRTF_NUM_BINS 60 #define REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */ #define GAIN_LFE 1.88364911f /* Gain applied to LFE during renderering */ -#define GAIN_LFE_WORD32 2022552831 /* Gain applied to LFE during renderering */ +#define GAIN_LFE_WORD32 2022552831 // Q30 /* Gain applied to LFE during renderering */ #ifdef IVAS_FLOAT_FIXED -#define GAIN_LFE_FX 30862 /*Q.14 Gain applied to LFE during renderering */ +#define GAIN_LFE_FX 30862 // Q14 /* Gain applied to LFE during renderering */ #endif // IVAS_FLOAT_FIXED #define LOW_BIT_RATE_BINAURAL_EQ_BINS 17 /* Number of bins in an EQ applied at low bit rates in binauralization */ #define LOW_BIT_RATE_BINAURAL_EQ_OFFSET 14 /* Offset of bins where the low-bit-rate EQ starts*/ @@ -1755,11 +1755,11 @@ typedef enum #define LR_IAC_LENGTH_NR_FC ( RV_LENGTH_NR_FC ) -#define DEG_360_IN_Q22 (360 << Q22) -#define DEG_180_IN_Q22 (180 << Q22) -#define DEG_90_IN_Q22 (90 << Q22) -#define ONE_BY_360_Q31 ( 5965232 ) -#define ONE_BY_180_Q31 ( 11930465 ) +#define DEG_360_IN_Q22 ( 360 << Q22 ) // Q22 +#define DEG_180_IN_Q22 ( 180 << Q22 ) // Q22 +#define DEG_90_IN_Q22 ( 90 << Q22 ) // Q22 +#define ONE_BY_360_Q31 ( 5965232 ) // Q31 +#define ONE_BY_180_Q31 ( 11930465 ) // Q31 /* ----- Enums - TD Renderer ----- */ diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index d03d548b6c9369f5a119d252a8213a53ffafdbeb..5f9262803414504f25fda77c23033e84a4341ce9 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -52,8 +52,8 @@ * To calculate the update factor *-----------------------------------------------------------------------------------------*/ -static Word32 ivas_calculate_update_factor_fx( - Word32 *p_bin_to_band, +static Word32 ivas_calculate_update_factor_fx( // o: Q22 + Word32 *p_bin_to_band, // i: Q22 Word16 active_bins ) { Word32 update_factor_temp = 0; @@ -65,7 +65,7 @@ static Word32 ivas_calculate_update_factor_fx( update_factor_temp = L_add( update_factor_temp, p_bin_to_band[k] ); // Q22 } - return update_factor_temp; + return update_factor_temp; // Q22 } #else /*-----------------------------------------------------------------------------------------* @@ -99,8 +99,8 @@ static float ivas_calculate_update_factor( *-----------------------------------------------------------------------------------------*/ static void ivas_calculate_smoothning_factor_fx( - Word32 *Smoothing_factor, - Word32 update_factor, + Word32 *Smoothing_factor, // o: Q31 + Word32 update_factor, // i: Q22 const Word16 min_pool_size, const Word32 max_update_rate, const COV_SMOOTHING_TYPE smooth_mode, @@ -112,7 +112,7 @@ static void ivas_calculate_smoothning_factor_fx( move32(); move16(); - tmp = BASOP_Util_Divide3232_Scale( update_factor, L_shl( L_deposit_l( min_pool_size ), Q22 ), &exp_diff ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( update_factor, L_shl( L_deposit_l( min_pool_size ), Q22 ), &exp_diff ); // Q(31 - exp_diff) *Smoothing_factor = L_shl_sat( L_deposit_l( tmp ), add( Q16, exp_diff ) ); // Q31 move32(); @@ -120,12 +120,12 @@ static void ivas_calculate_smoothning_factor_fx( { IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { - smooth_fact = (Word32) ( ONE_IN_Q30 ); + smooth_fact = (Word32) ( ONE_IN_Q30 ); // 0.5 in Q31 move32(); } ELSE { - smooth_fact = (Word32) ( 1610612735 ); + smooth_fact = (Word32) ( 1610612735 ); // 0.75 in Q31 move32(); } @@ -138,7 +138,7 @@ static void ivas_calculate_smoothning_factor_fx( IF( GT_32( *Smoothing_factor, max_update_rate ) ) // Q31 { - *Smoothing_factor = max_update_rate; + *Smoothing_factor = max_update_rate; // Q31 move32(); } @@ -195,7 +195,7 @@ static void ivas_calculate_smoothning_factor( static void ivas_set_up_cov_smoothing_fx( ivas_cov_smooth_state_t *hCovState, ivas_filterbank_t *pFb, - const Word32 max_update_rate, + const Word32 max_update_rate, // i: Q31 const Word16 min_pool_size, const COV_SMOOTHING_TYPE smooth_mode, /* i : flag multichannel vs SPAR */ const Word32 ivas_total_brate ) @@ -209,7 +209,7 @@ static void ivas_set_up_cov_smoothing_fx( { Word16 active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; move16(); - update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins ); + update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins ); // Q22 ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); } } @@ -217,10 +217,10 @@ static void ivas_set_up_cov_smoothing_fx( { FOR( j = 0; j < pFb->filterbank_num_bands; j++ ) { - Word32 *p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[j]; + Word32 *p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[j]; // Q22 Word16 active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j]; move16(); - update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins ); + update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins ); // Q22 ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); } } @@ -471,8 +471,8 @@ void ivas_spar_covar_smooth_enc_close( static void ivas_compute_smooth_cov_fx( ivas_cov_smooth_state_t *hCovState, ivas_filterbank_t *pFb, - Word32 *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // i/o: Q(q_cov[i][j]) + Word32 *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // i: hCovState->q_cov_real_per_band[i][j][k] const Word32 fac, const Word16 start_band, const Word16 end_band, @@ -501,15 +501,15 @@ static void ivas_compute_smooth_cov_fx( { FOR( j = 0; j < num_ch; j++ ) { - set16_fx( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], sub( end_band, start_band ) ); + set16_fx( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], sub( end_band, start_band ) ); // assign q_cov[i][j] to hCovState->q_cov_real_per_band[i][j][k] } } FOR( i = 0; i < num_ch; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 - pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 + pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); // hCovState->q_cov_real_per_band[i][j][k] move32(); } } @@ -523,7 +523,7 @@ static void ivas_compute_smooth_cov_fx( { IF( EQ_16( i, j ) ) { - factor = fac; + factor = fac; // Q31 move32(); } ELSE @@ -535,25 +535,25 @@ static void ivas_compute_smooth_cov_fx( set16_fx( q_tmp, q_cov[i][j], sub( end_band, start_band ) ); FOR( k = start_band; k < non_sm_b_idx; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] - L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] - pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] + pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); // Q(31 - q_tmp[k]) move32(); - q_tmp[k] = sub( Q31, q_tmp[k] ); + q_tmp[k] = sub( Q31, q_tmp[k] ); // Q of pConv_buf[i][j][k] is now q_tmp[k] move16(); L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_tmp[k], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_tmp[k] - pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); + pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); // q_tmp[k] move32(); } - Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); + Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); // Q of pCov_buf[i][j][k] is hCovState->q_cov_real_per_band[i][j][j] } } FOR( i = 0; i < num_ch; i++ ) { FOR( k = non_sm_b_idx; k < end_band; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 - pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 + pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( hCovState->q_cov_real_per_band[i][i][k], Q31 ) ) ); // hCovState->q_cov_real_per_band[i][j][j] move32(); } } @@ -566,7 +566,7 @@ static void ivas_compute_smooth_cov_fx( { IF( EQ_16( i, j ) ) { - factor = fac; + factor = fac; // Q31 move32(); } ELSE @@ -577,17 +577,17 @@ static void ivas_compute_smooth_cov_fx( FOR( k = start_band; k < end_band; k++ ) { - L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] - L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] - pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] + pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); // Q(31 - q_tmp[k]) move32(); - q_tmp[k] = sub( Q31, q_tmp[k] ); + q_tmp[k] = sub( Q31, q_tmp[k] ); // Q of pConv_buf[i][j][k] is now q_tmp[k] move16(); L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_tmp[k], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_tmp[k] - pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); + pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); // q_tmp[k] move32(); } - Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); + Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); // Q of pCov_buf[i][j][k] is hCovState->q_cov_real_per_band[i][j][j] } } } @@ -697,9 +697,9 @@ static void ivas_compute_smooth_cov( *-----------------------------------------------------------------------------------------*/ void ivas_cov_smooth_process_fx( - ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - ivas_filterbank_t *pFb, /* i/o: FB handle */ + ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // Q(hCovState->q_cov_real_per_band[i][j][k]) + ivas_filterbank_t *pFb, /* i/o: FB handle */ const Word16 start_band, const Word16 end_band, const Word16 num_ch, @@ -715,7 +715,7 @@ void ivas_cov_smooth_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - Copy32( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); + Copy32( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); // Q of hCovState->pPrior_cov_real_fx[i][j][start_band + k] will be hCovState->q_cov_real_per_band[i][j][start_band + k] FOR( k = 0; k < num_bands; k++ ) { hCovState->q_prior_cov_real_per_band[i][j][start_band + k] = hCovState->q_cov_real_per_band[i][j][start_band + k]; diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index f07dcd4be547e26ecc44000ac8381d260e1ca9d4..8bc0f6749c0912bbc09778145e4a86d298ab92b1 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -240,8 +240,9 @@ ivas_error ivas_dirac_config_fx( move16(); move16(); - set_c( (Word8 *) hQMetaData->twoDirBands, (Word8) 1, hQMetaData->q_direction[0].cfg.nbands ); + set8_fx( (Word8 *) hQMetaData->twoDirBands, (Word8) 1, hQMetaData->q_direction[0].cfg.nbands ); hQMetaData->numTwoDirBands = (UWord8) hQMetaData->q_direction[0].cfg.nbands; + move16(); } } @@ -557,8 +558,9 @@ void ivas_dirac_config_bands_fx( IF( useLowerBandRes ) { Word16 step = DIRAC_LOW_BANDRES_STEP; + move16(); Word16 reduced_band; - FOR( ( band = add( enc_param_start_band, 2 ), reduced_band = add( enc_param_start_band, 1 ) ); band <= DIRAC_MAX_NBANDS; ( band = add( band, step ), reduced_band++ ) ) + FOR( ( band = enc_param_start_band + 2, reduced_band = enc_param_start_band + 1 ); band <= DIRAC_MAX_NBANDS; ( band += step, reduced_band++ ) ) { band_grouping[reduced_band] = band_grouping[band]; move16(); @@ -592,7 +594,7 @@ void ivas_dirac_config_bands_fx( } /* Limit the band range to band max */ - FOR( i = 0; i < add( nbands, 1 ); i++ ) + FOR( i = 0; i < nbands + 1; i++ ) { IF( GT_16( band_grouping[i], max_band ) ) { @@ -703,6 +705,7 @@ void ivas_get_dirac_sba_max_md_bits_fx( *bits_frame_nominal = extract_l( Mpy_32_32( sba_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); *metadata_max_bits = MAX16B; /* no limit */ + move16(); } Word32 var1 = L_mult0( *metadata_max_bits, nbands ); Word16 exp = 0; @@ -1000,14 +1003,14 @@ ivas_error ivas_dirac_sba_config( #ifdef IVAS_FLOAT_FIXED void computeDirectionVectors_fixed( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - Word32 *intensity_real_z, + Word32 *intensity_real_x, /* i: exp = i_e */ + Word32 *intensity_real_y, /* i: exp = i_e */ + Word32 *intensity_real_z, /* i: exp = i_e */ const Word16 enc_param_start_band, const Word16 num_frequency_bands, - Word32 *direction_vector_x, /*Q30*/ - Word32 *direction_vector_y, /*Q30*/ - Word32 *direction_vector_z, /*Q30*/ + Word32 *direction_vector_x, /* o: Q30*/ + Word32 *direction_vector_y, /* o: Q30*/ + Word32 *direction_vector_z, /* o: Q30*/ Word16 i_e /*Exponent of all the intensity buffers*/ ) { Word16 i; @@ -1071,22 +1074,22 @@ void computeDirectionVectors_fixed( *------------------------------------------------------------------------*/ void computeDirectionVectors_fx( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - Word32 *intensity_real_z, + Word32 *intensity_real_x, // i: Q( i_q ) + Word32 *intensity_real_y, // i: Q( i_q ) + Word32 *intensity_real_z, // i: Q( i_q ) const Word16 enc_param_start_band, const Word16 num_frequency_bands, - Word32 *direction_vector_x, - Word32 *direction_vector_y, - Word32 *direction_vector_z, - Word16 *i_q /*input/output Q*/ + Word32 *direction_vector_x, // o: Q( i_q ) + Word32 *direction_vector_y, // o: Q( i_q ) + Word32 *direction_vector_z, // o: Q( i_q ) + Word16 *i_q /*input/output Q*/ ) { Word16 i; Word32 intensityNorm; - Word16 sq = sub( 31, sub( 2 * ( *i_q ), 31 ) ); - Word16 sq1 = sub( 2 * ( *i_q ), 31 ); + Word16 sq = sub( 31, sub( shl( *i_q, 1 ), 31 ) ); + Word16 sq1 = sub( shl( *i_q, 1 ), 31 ); Word16 exp = sq; Word16 local_i_q = sq1; Word16 min_factor = 30; @@ -1136,7 +1139,7 @@ void computeDirectionVectors_fx( IF( LE_32( intensityNorm, EPSILON_FX ) ) { intensityNorm = L_shl( 1, min_factor ); - *( direction_vector_x++ ) = L_shl( 1, min_factor ); + *( direction_vector_x++ ) = L_shl( 1, min_factor ); // Q is min_factor *( direction_vector_y++ ) = 0; *( direction_vector_z++ ) = 0; intensity_real_x++; @@ -1149,13 +1152,13 @@ void computeDirectionVectors_fx( } ELSE { - intensityNorm = ISqrt32( intensityNorm, &exp ); // Q31-exp - Word32 temp = L_shr( Mpy_32_32( *( intensity_real_x++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_x++ ) = temp; // i_q + Q31-exp -31 = i_q -exp - temp = L_shr( Mpy_32_32( *( intensity_real_y++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_y++ ) = temp; // i_q + Q31-exp -31 = i_q -exp - temp = L_shr( Mpy_32_32( *( intensity_real_z++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); - *( direction_vector_z++ ) = temp; // i_q + Q31-exp-31 = i_q -exp + intensityNorm = ISqrt32( intensityNorm, &exp ); // Q31-exp + Word32 temp = L_shr( Mpy_32_32( *( intensity_real_x++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); // Q is min_factor + *( direction_vector_x++ ) = temp; // i_q + Q31-exp -31 = i_q -exp + temp = L_shr( Mpy_32_32( *( intensity_real_y++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); // Q is min_factor + *( direction_vector_y++ ) = temp; // i_q + Q31-exp -31 = i_q -exp + temp = L_shr( Mpy_32_32( *( intensity_real_z++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); // Q is min_factor + *( direction_vector_z++ ) = temp; // i_q + Q31-exp-31 = i_q -exp move32(); move32(); @@ -1222,10 +1225,10 @@ void computeDirectionVectors( *------------------------------------------------------------------------*/ void computeDiffuseness_fx( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], // i: Q(q_factor_intensity) + const Word32 *buffer_energy, // i: Q(q_factor_energy) const Word16 num_freq_bands, - Word32 *diffuseness, + Word32 *diffuseness, // o: exp(out_exp) Word16 q_factor_intensity, Word16 q_factor_energy, Word16 *out_exp /*Ouput Q*/ @@ -1272,7 +1275,7 @@ void computeDiffuseness_fx( /* intensity_slow.^2 + intensity_slow_abs*/ FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { - p_tmp = intensity_slow + imult1616( j, num_freq_bands ); + p_tmp = intensity_slow + j * num_freq_bands; FOR( k = 0; k < num_freq_bands; k++ ) { @@ -1282,7 +1285,8 @@ void computeDiffuseness_fx( move32(); } } - Word16 init_exp = sub( 31, sub( ( ( 2 * ( q_factor_intensity ) ) ), 31 ) ), exp; + Word16 init_exp = sub( 62, shl( q_factor_intensity, 1 ) ); // 31 - ( 2 * q_factor_intensity - 31 ) + Word16 exp; Word16 exp1 = 0, exp2; move16(); @@ -1291,6 +1295,7 @@ void computeDiffuseness_fx( FOR( i = 0; i < num_freq_bands; ++i ) { exp = init_exp; + move16(); Word32 temp = *( p_tmp++ ); move32(); tmp_1 = Sqrt32( temp, &exp ); @@ -1338,10 +1343,10 @@ void computeDiffuseness_fx( *------------------------------------------------------------------------*/ void computeDiffuseness_fixed( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], // i: Q(q_factor_intensity) + const Word32 *buffer_energy, // i: Q(q_factor_energy) const Word16 num_freq_bands, - Word32 *diffuseness, + Word32 *diffuseness, // o: exp(out_exp) Word16 *q_factor_intensity, Word16 *q_factor_energy, Word16 *q_diffuseness /*Ouput Q*/ @@ -1389,7 +1394,7 @@ void computeDiffuseness_fixed( FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) { /* Energy slow */ - p_tmp_c = buffer_energy + i_mult( i, num_freq_bands ); + p_tmp_c = buffer_energy + i * num_freq_bands; q_tmp = add( q_factor_energy[i], min_q_shift1 ); FOR( k = 0; k < num_freq_bands; k++ ) @@ -1418,12 +1423,12 @@ void computeDiffuseness_fixed( tmp = L_shl( 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 ) ) ); + intensity_slow[j * num_freq_bands + k] = L_add( intensity_slow[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 ); + intensity_slow[j * num_freq_bands + k] = L_add( L_shr( intensity_slow[j * num_freq_bands + k], sub( q_intensity, q_tmp ) ), tmp ); move32(); } } @@ -1439,7 +1444,7 @@ void computeDiffuseness_fixed( /* intensity_slow.^2 + intensity_slow_abs*/ FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { - p_tmp = intensity_slow + i_mult( j, num_freq_bands ); + p_tmp = intensity_slow + j * num_freq_bands; FOR( k = 0; k < num_freq_bands; k++ ) { @@ -1627,12 +1632,12 @@ float deindex_azimuth( } #ifdef IVAS_FLOAT_FIXED -Word32 deindex_azimuth_fx( - Word16 id_phi, /* i : index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ - const Word16 id_th, /* i : elevation index */ - const Word16 remap, /* i : remapping flag */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +Word32 deindex_azimuth_fx( /* o : output Q22 */ + Word16 id_phi, /* i : index */ + const Word16 no_bits, /* i : number of bits for the spherical grid */ + const Word16 id_th, /* i : elevation index */ + const Word16 remap, /* i : remapping flag */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { Word16 flag_delta; @@ -1643,12 +1648,12 @@ Word32 deindex_azimuth_fx( { IF( s_and( id_phi, 1 ) == 0 ) { - phi_hat_fx = cb_azi_chan_fx[shr( id_phi, 1 )]; + phi_hat_fx = cb_azi_chan_fx[id_phi / 2]; // Q22 move32(); } ELSE { - phi_hat_fx = L_negate( cb_azi_chan_fx[shr( add( id_phi, 1 ), 1 )] ); + phi_hat_fx = L_negate( cb_azi_chan_fx[( id_phi + 1 ) / 2] ); // Q22 } return phi_hat_fx; } @@ -1656,13 +1661,13 @@ Word32 deindex_azimuth_fx( IF( remap ) { - id_phi = add( ivas_qmetadata_dereorder_generic( id_phi ), shr( no_phi_masa[sub( no_bits, 1 )][id_th], 1 ) ); + id_phi = add( ivas_qmetadata_dereorder_generic( id_phi ), shr( no_phi_masa[no_bits - 1][id_th], 1 ) ); } - delta_phi_fx = Mpy_32_32( 1509949440, no_phi_masa_inv_fx[sub( no_bits, 1 )][id_th] ); // q = 22 + delta_phi_fx = Mpy_32_32( 1509949440, no_phi_masa_inv_fx[no_bits - 1][id_th] ); // q = 22 test(); test(); - IF( EQ_16( flag_delta, 1 ) && GT_16( no_phi_masa[sub( no_bits, 1 )][id_th], 2 ) && EQ_32( mc_format, MC_LS_SETUP_INVALID ) ) + IF( EQ_16( flag_delta, 1 ) && GT_16( no_phi_masa[no_bits - 1][id_th], 2 ) && EQ_32( mc_format, MC_LS_SETUP_INVALID ) ) { dd_fx = Mpy_32_32( delta_phi_fx, 1073741824 ); // q = 22 } @@ -1672,11 +1677,20 @@ Word32 deindex_azimuth_fx( move32(); } - id_phi = sub( id_phi, shr( no_phi_masa[sub( no_bits, 1 )][id_th], 1 ) ); - phi_hat_fx = L_add( id_phi * delta_phi_fx, dd_fx ); + id_phi = sub( id_phi, shr( no_phi_masa[no_bits - 1][id_th], 1 ) ); + phi_hat_fx = L_add( imult3216( delta_phi_fx, id_phi ), dd_fx ); IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) { - phi_hat_fx = companding_azimuth_fx( phi_hat_fx, mc_format, ( id_th * delta_theta_masa[no_bits - 3] > MC_MASA_THR_ELEVATION ), -1 ); + Word32 a = L_shr( imult3216( delta_theta_masa_fx[no_bits - 3], id_th ), 22 ); // Q22 -> Q0 + move32(); + Word16 flag = 0; + move16(); + if ( GT_32( a, MC_MASA_THR_ELEVATION ) ) + { + flag = 1; + move16(); + } + phi_hat_fx = companding_azimuth_fx( phi_hat_fx, mc_format, flag, -1 ); } return phi_hat_fx; } @@ -1731,8 +1745,8 @@ void deindex_spherical_component( #else void deindex_spherical_component_fx( const UWord16 sph_idx, /* i : spherical index */ - Word32 *az_fx, /* o : decoded azimuth value */ - Word32 *el_fx, /* o : decoded elevation value */ + Word32 *az_fx, /* o : decoded azimuth value Q22 */ + Word32 *el_fx, /* o : decoded elevation value Q22 */ UWord16 *az_idx, /* o : azimuth index */ UWord16 *el_idx, /* o : elevation index */ const UWord16 no_bits, /* i : number of bits for the spherical grid */ @@ -2478,12 +2492,12 @@ static uint16_t deindex_sph_idx_general( } #else static UWord16 deindex_sph_idx_general_fx( - const Word16 idx_sph, /* i : spherical index */ - const Word16 no_bits, /* i : number of bits in the spherical grid*/ - Word32 *theta_dec_fx, /* o : decoded elevation value */ - Word32 *phi_dec_fx, /* o : decoded azimuth value */ - UWord16 *p_id_phi, /* o : decoded azimuth index */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ + const Word16 idx_sph, /* i : spherical index */ + const Word16 no_bits, /* i : number of bits in the spherical grid */ + Word32 *theta_dec_fx, /* o : decoded elevation value Q22 */ + Word32 *phi_dec_fx, /* o : decoded azimuth value Q22 */ + UWord16 *p_id_phi, /* o : decoded azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { Word16 i; @@ -2594,7 +2608,7 @@ static UWord16 deindex_sph_idx_general_fx( q_id_th = norm_l( id_th ); id_th_fx = L_shl( id_th, q_id_th ); - *theta_dec_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[no_bits - 3] ), sub( 31, q_id_th ) ); + *theta_dec_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[no_bits - 3] ), sub( 31, q_id_th ) ); // Q22 move32(); IF( GE_32( *theta_dec_fx, 90 << Q22 ) ) @@ -2610,7 +2624,7 @@ static UWord16 deindex_sph_idx_general_fx( { *theta_dec_fx *= sign_theta; - *phi_dec_fx = deindex_azimuth_fx( id_phi, no_bits, id_th, 0, mc_format ); + *phi_dec_fx = deindex_azimuth_fx( id_phi, no_bits, id_th, 0, mc_format ); // Q22 move32(); *p_id_phi = id_phi; move16(); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 0a45a3600350761e1ae8842afa327f9ff377f73e..93ea0528df7005878bc12fe7267bda44f64dfc97 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -48,12 +48,20 @@ /*------------------------------------------------------------------------------------------* * Static functions declarations *------------------------------------------------------------------------------------------*/ -static void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ); +#ifdef IVAS_FLOAT_FIXED +static void ivas_cmult_fix( + Word32 in1_re, // i: Qx + Word32 in1_im, // i: Qx + Word32 in2_re, // i: Qx + Word32 in2_im, // i: Qx + Word32 *out1_re, // o: 2 * Qx - 31 + Word32 *out1_im // o: 2 * Qx - 31 +); static void ivas_get_active_bins_fx( const Word16 **pActive_bins, const Word16 **pActive_bins_abs, const Word16 **pStart_offset, const Word16 **pStart_offset_ab, const Word32 sampling_rate ); static void ivas_get_ld_fb_resp_fx( Word32 **ppIdeal_FRs_re_fx, Word32 **ppIdeal_FRs_im_fx, Word32 **ppNew_FRs_re_fx, Word32 **ppNew_FRs_im_fx, const Word16 *pActive_bins, const Word16 *pStart_offset, const Word16 num_bands, const Word16 delay, const Word32 sampling_rate ); static ivas_error ivas_filterbank_setup_fx( IVAS_FB_MIXER_HANDLE hFbMixer, const Word32 sampling_rate, Word16 *index ); static ivas_error ivas_fb_mixer_get_window_fx( const Word16 fade_len, const Word32 sampling_rate, const Word16 **pWindow ); - +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -643,10 +651,10 @@ void ivas_fb_mixer_pcm_ingest( } #else void ivas_fb_mixer_pcm_ingest_fx( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ - const Word16 frame_len, /* i : frame length */ + const Word16 frame_len, /* i : frame length */ const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], Word16 q_data_fix, Word16 *q_ppOut_pcm ) @@ -703,7 +711,7 @@ void ivas_fb_mixer_pcm_ingest_fx( FOR( i = 0; i < num_chs_ingest; i++ ) { Word16 q_shift = sub( L_norm_arr( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ) ), guard_bits ); - Scale_sig32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ), q_shift ); + Scale_sig32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ), q_shift ); // Qq_ppOut_pcm -> Qq_ppOut_pcm + q_shift q_ppOut_pcm[fb_cfg->remix_order[i]] = add( q_ppOut_pcm[fb_cfg->remix_order[i]], q_shift ); move16(); @@ -769,7 +777,7 @@ void ivas_fb_mixer_update_prior_input_fx( #ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_get_windowed_fr_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 *pcm_in_fx[], + Word32 *pcm_in_fx[], // i: Qx Word32 *frame_f_real_fx[], Word32 *frame_f_imag_fx[], const Word16 length, /* i : number of new samples in time slot */ @@ -791,27 +799,27 @@ void ivas_fb_mixer_get_windowed_fr_fx( FOR( ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) { - Copy32( &hFbMixer->ppFilterbank_prior_input_fx[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block_fx[offset], n_old_samples - offset ); - Copy32( pcm_in_fx[ch_idx], &fr_in_block_fx[n_old_samples], n_new_samples ); + Copy32( &hFbMixer->ppFilterbank_prior_input_fx[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block_fx[offset], sub( n_old_samples, offset ) ); // Qx + Copy32( pcm_in_fx[ch_idx], &fr_in_block_fx[n_old_samples], n_new_samples ); // Qx win_ptr_fx = hFbMixer->pAna_window_fx; /*Q15*/ FOR( j = offset; j < sub( shl( mdft_len, 1 ), length ); j++ ) { - fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( win_ptr_fx++ ) ) ); - move16(); + fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( win_ptr_fx++ ) ) ); // Qx + 15 - 15 = Qx + move32(); } FOR( j = rev_offset; j < shl( mdft_len, 1 ); j++ ) { - fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( --win_ptr_fx ) ) ); - move16(); + fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( --win_ptr_fx ) ) ); // Qx + 15 - 15 = Qx + move32(); } FOR( Word16 i = 0; i < shl( mdft_len, 1 ); i++ ) { - fr_in_block_fx[i] = L_shr( fr_in_block_fx[i], gb ); - move16(); + fr_in_block_fx[i] = L_shr( fr_in_block_fx[i], gb ); // Qx - gb + move32(); } ivas_mdft_fx( fr_in_block_fx, frame_f_real_fx[ch_idx], frame_f_imag_fx[ch_idx], shl( mdft_len, 1 ), mdft_len ); @@ -875,9 +883,9 @@ void ivas_fb_mixer_get_windowed_fr( #ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_cross_fading_fx( IVAS_FB_MIXER_HANDLE hFbMixer, - Word32 **ppOut_pcm_fx, - Word32 *pMdft_out_old_fx, - Word32 *pMdft_out_new_fx, + Word32 **ppOut_pcm_fx, // o: Qx + Word32 *pMdft_out_old_fx, // i: Qx + Word32 *pMdft_out_new_fx, // i: Qx const Word16 ch, const Word16 frame_len, const Word16 cf_offset ) @@ -893,19 +901,19 @@ void ivas_fb_mixer_cross_fading_fx( FOR( k = 0; k < fade_start_offset; k++ ) { - ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; + ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; // Qx move32(); } FOR( k = fade_start_offset; k < fade_end_offset; k++ ) { - ppOut_pcm_fx[ch][k] = L_add( Mpy_32_16_1( pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ), Mpy_32_16_1( pMdft_out_old_fx[k + cf_offset], sub( 32767, hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ) ) ); + ppOut_pcm_fx[ch][k] = L_add( Mpy_32_16_1( pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ), Mpy_32_16_1( pMdft_out_old_fx[k + cf_offset], sub( 32767, hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ) ) ); // Qx + Q15 - 15 = Qx move32(); } FOR( k = fade_end_offset; k < frame_len; k++ ) { - ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; // Qx move32(); } } @@ -916,7 +924,7 @@ void ivas_fb_mixer_cross_fading_fx( FOR( k = 0; k < frame_len; k++ ) { - ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; // Qx move32(); } } @@ -931,7 +939,14 @@ void ivas_fb_mixer_cross_fading_fx( * Filter bank process *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ) +void ivas_cmult_fix( + Word32 in1_re, // i: Qx + Word32 in1_im, // i: Qx + Word32 in2_re, // i: Qx + Word32 in2_im, // i: Qx + Word32 *out1_re, // o: 2 * Qx - 31 + Word32 *out1_im // o: 2 * Qx - 31 +) { *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); move32(); @@ -942,11 +957,11 @@ void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, void ivas_fb_mixer_process_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 ***mixer_mat_fx, /* i : mixer matrix */ - Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix Q-factor */ Word32 **ppOut_pcm_fx, /* o : output audio channels */ - Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + Word16 *q_ppOut_pcm_fx, /* o : output audio channels Q-factor */ const Word16 frame_len, /* i : frame length in samples */ - Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ) { ivas_filterbank_t *pFb = hFbMixer->pFb; @@ -984,8 +999,8 @@ void ivas_fb_mixer_process_fx( Word32 filterbank_mixer_bins_re_fx[L_FRAME48k]; Word32 filterbank_mixer_bins_im_fx[L_FRAME48k]; - Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; - Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; + Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; // Q(hFbMixer->q_ppFilterbank_inFR_re_fx) + Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; // Q(hFbMixer->q_ppFilterbank_inFR_im_fx) set_zero_fx( filterbank_mixer_bins_re_fx, frame_len ); set_zero_fx( filterbank_mixer_bins_im_fx, frame_len ); @@ -998,23 +1013,23 @@ void ivas_fb_mixer_process_fx( move16(); Word16 num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; move16(); - Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; + Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; // Q(hFbMixer->q_prior_mixer_fx) move32(); - pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; - pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; // Q30 + pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; // Q30 FOR( k = start_offset; k < num_bins + start_offset; k++ ) { - filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); + filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); // Q30 + hFbMixer->q_prior_mixer_fx - 31 - total_guard move32(); - filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); + filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); // Q30 + hFbMixer->q_prior_mixer_fx - 31 - total_guard move32(); /*filterbank_mixer_bins_im_fx q 30 */ /*mixer_const_fx q q_ppOut_pcm_fx */ pFilterbank_bin_to_band_re_fx++; pFilterbank_bin_to_band_im_fx++; } - hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; + hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; // Q(q_mixer_mat_fx) move32(); } Word16 res_q = 0; @@ -1029,21 +1044,21 @@ void ivas_fb_mixer_process_fx( Word16 q_check = s_min( q_pOut_fr_fx, res_q ); IF( NE_16( q_check, q_pOut_fr_fx ) ) { - pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); + pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); // q_pOut_fr_fx -> q_check move32(); - pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); + pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); // q_pOut_fr_fx -> q_check move32(); } IF( NE_16( q_check, res_q ) ) { - temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); - temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); + temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); // res_q -> q_check + temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); // res_q -> q_check } res_q = q_check; move16(); - pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); + pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); // res_q move32(); - pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); + pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); // res_q move32(); } q_pOut_fr_fx = res_q; @@ -1243,8 +1258,8 @@ static Word16 ivas_calculate_abs_fr_fx( FOR( i = 0; i < bands; i++ ) { - const Word32 *long_mdft_ptr_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; - const Word32 *long_mdft_ptr_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + const Word32 *long_mdft_ptr_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; // Q30 + const Word32 *long_mdft_ptr_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; // Q30 Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; move16(); @@ -1286,24 +1301,24 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 sq_abs_e; // Word32 real = L_shr( *long_mdft_ptr_re_fx, 3 ); // Q27 - Word32 real = *long_mdft_ptr_re_fx; // Q31 + Word32 real = *long_mdft_ptr_re_fx; // Q30 move32(); // Word32 imag = L_shr( *long_mdft_ptr_im_fx, 3 ); // Q27 - Word32 imag = *long_mdft_ptr_im_fx; // Q31 + Word32 imag = *long_mdft_ptr_im_fx; // Q30 Word16 real_exp, imag_exp; move32(); Word32 real_sq, imag_sq; - real_sq = Mpy_32_32( real, real ); + real_sq = Mpy_32_32( real, real ); // Q30 + Q30 - 31 = Q29 real_exp = 2; move32(); - imag_sq = Mpy_32_32( imag, imag ); + imag_sq = Mpy_32_32( imag, imag ); // Q30 + Q30 - 31 = Q29 imag_exp = 2; move32(); - sq_abs_fx = BASOP_Util_Add_Mant32Exp( real_sq, real_exp, imag_sq, imag_exp, &sq_abs_e ); // Q22 + sq_abs_fx = BASOP_Util_Add_Mant32Exp( real_sq, real_exp, imag_sq, imag_exp, &sq_abs_e ); // Q(31 - sq_abs_e) long_mdft_ptr_re_fx++; long_mdft_ptr_im_fx++; @@ -1311,6 +1326,8 @@ static Word16 ivas_calculate_abs_fr_fx( /* accumulate bin energies within a short stride bin */ short_stride_nrg_fx = L_add( short_stride_nrg_fx, L_shl( sq_abs_fx, sub( Q22, sub( Q31, sq_abs_e ) ) ) ); + short_stride_nrg_fx = L_add( short_stride_nrg_fx, L_shl( sq_abs_fx, sub( Q22, sub( Q31, sq_abs_e ) ) ) ); // Q(31 - sq_abs_e) -> Q22 + move32(); IF( !( ( j + 1 ) % num_bins_per_short_stride_bin ) ) { @@ -1328,8 +1345,8 @@ static Word16 ivas_calculate_abs_fr_fx( IF( !( ( j + 1 ) % num_bins_per_cldfb_band ) ) { Word32 temp = Sqrt32( cldfb_nrg_fx, &cldfb_nrg_e ); - temp = L_shl( temp, sub( cldfb_nrg_e, Q9 ) ); // Q22 - pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j / num_bins_per_cldfb_band][i] = temp; + temp = L_shl( temp, sub( cldfb_nrg_e, Q9 ) ); // Q22 + pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j / num_bins_per_cldfb_band][i] = temp; // Q22 move32(); cldfb_nrg_fx = 0; move32(); @@ -1344,7 +1361,7 @@ static Word16 ivas_calculate_abs_fr_fx( tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], short_stride_max_per_spar_band_fx, &exp_diff ); short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 move32(); - short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], 1258291 ), 0 ); // 0.3f * ONE_IN_Q22c + short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], 1258291 ), 0 ); // 0.3f * ONE_IN_Q22 move32(); tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], 2936012, &exp_diff ); // 0.7f * ONE_IN_Q22 short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 @@ -1360,12 +1377,12 @@ static Word16 ivas_calculate_abs_fr_fx( pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[i] = j; move16(); - pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band]; + pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band]; // Q22 index[i] = idx_short_stride_bin_to_band; move16(); } - pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band] = short_stride_pow_spec_fx[j]; + pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band] = short_stride_pow_spec_fx[j]; // Q22 move32(); idx_short_stride_bin_to_band = add( idx_short_stride_bin_to_band, 1 ); @@ -1390,18 +1407,20 @@ static Word16 ivas_calculate_abs_fr_fx( FOR( i = 0; i < bands; i++ ) { - sum_over_spar_bands_fx = L_add( sum_over_spar_bands_fx, pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] ); + sum_over_spar_bands_fx = L_add( sum_over_spar_bands_fx, pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] ); // Q22 + move32(); IF( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] > max_spar_band_contribution_fx ) { - max_spar_band_contribution_fx = pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i]; + max_spar_band_contribution_fx = pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i]; // Q22 move32(); pFb->fb_bin_to_band.p_cldfb_map_to_spar_band[j] = i; move16(); } } - sum_over_spar_bands_fx = L_max( sum_over_spar_bands_fx, EPSILON_FX ); + sum_over_spar_bands_fx = L_max( sum_over_spar_bands_fx, EPSILON_FX ); // Q22 + move32(); FOR( i = 0; i < bands; i++ ) { @@ -1435,9 +1454,9 @@ static Word16 ivas_calculate_abs_fr_fx( /*Commented logic is for calculating number of active bands, can be removed if not needed */ FOR( i = 0; i < bands; i++ ) { - const Word32 *pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; + const Word32 *pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; // Q30 move32(); - const Word32 *pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + const Word32 *pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; // Q30 move32(); Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; @@ -1459,11 +1478,11 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 exp_diff = 0; move16(); Word32 real = L_shr( *pFilterbank_bin_to_band_re_fx, 3 ); // Q27 - Word32 imag = L_shr( *pFilterbank_bin_to_band_im_fx, 3 ); + Word32 imag = L_shr( *pFilterbank_bin_to_band_im_fx, 3 ); // Q27 Word32 real_sq, imag_sq; - real_sq = Mpy_32_32( real, real ); - imag_sq = Mpy_32_32( imag, imag ); + real_sq = Mpy_32_32( real, real ); // Q27 + Q27 - 31 = Q23 + imag_sq = Mpy_32_32( imag, imag ); // Q27 + Q27 - 31 = Q23 temp_fx = L_add( L_shr( real_sq, 1 ), L_shr( imag_sq, 1 ) ); // Q22 @@ -1476,7 +1495,8 @@ static Word16 ivas_calculate_abs_fr_fx( pFilterbank_bin_to_band_re_fx++; pFilterbank_bin_to_band_im_fx++; - temp_fx = L_sub( temp_fx, 1258291 ); + temp_fx = L_sub( temp_fx, 1258291 ); // 0.3 in Q22 + move32(); if ( temp_fx < 0 ) { @@ -1488,13 +1508,13 @@ static Word16 ivas_calculate_abs_fr_fx( test(); IF( LT_16( j, add( abs_active_bins, abs_start_offset ) ) && GE_16( j, abs_start_offset ) && NE_16( alloc_fb_resp, -1 ) ) { - pFb->fb_bin_to_band.pFb_bin_to_band_fx[i][idx] = temp_fx; + pFb->fb_bin_to_band.pFb_bin_to_band_fx[i][idx] = temp_fx; // Q22 move32(); idx = add( idx, 1 ); } - ppFilterbank_FRs_s_fx[j] = L_add( ppFilterbank_FRs_s_fx[j], temp_fx ); + ppFilterbank_FRs_s_fx[j] = L_add( ppFilterbank_FRs_s_fx[j], temp_fx ); // Q22 move32(); } } @@ -1503,7 +1523,7 @@ static Word16 ivas_calculate_abs_fr_fx( { if ( ppFilterbank_FRs_s_fx[i] < 0 ) { - ppFilterbank_FRs_s_fx[i] = 419430; + ppFilterbank_FRs_s_fx[i] = 419430; // 0.1 in Q22 move32(); } } @@ -1710,8 +1730,8 @@ static ivas_error ivas_filterbank_setup_fx( FOR( j = 0; j < pFb->filterbank_num_bands; j++ ) { - pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; - pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; + pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; // Q30 + pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; // Q30 offset = add( offset, pFb->fb_consts.pFilterbank_bins_per_band[j] ); } @@ -1744,13 +1764,13 @@ static ivas_error ivas_filterbank_setup_fx( IF( j < start_diff_band_non48k ) { - pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; - pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; + pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = &pAll_fb_fr_fx[0][offset]; // Q30 + pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = &pAll_fb_fr_fx[1][offset]; // Q30 } ELSE { - Copy32( &pAll_fb_fr_fx[0][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j], num_active_bins ); - Copy32( &pAll_fb_fr_fx[1][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j], num_active_bins ); + Copy32( &pAll_fb_fr_fx[0][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j], num_active_bins ); // Q30 + Copy32( &pAll_fb_fr_fx[1][offset], pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j], num_active_bins ); // Q30 } offset = add( offset, pAll_bins_per_band_48k[j] ); @@ -1759,8 +1779,8 @@ static ivas_error ivas_filterbank_setup_fx( FOR( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ ) { - ppFilterbank_FRs_re_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; - ppFilterbank_FRs_im_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; + ppFilterbank_FRs_re_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; // Q30 + ppFilterbank_FRs_im_temp_fx[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; // Q30 active_bins_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_per_band[j]; start_offset_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_start_offset[j]; @@ -1775,8 +1795,8 @@ static ivas_error ivas_filterbank_setup_fx( FOR( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ ) { - pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; - pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; + pFb->fb_consts.ppFilterbank_FRs_fx[0][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j]; // Q30 + pFb->fb_consts.ppFilterbank_FRs_fx[1][j] = (const Word32 *) pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j]; // Q30 } /******************************************** Calculate abs fr ****************************************************/ @@ -1875,10 +1895,10 @@ static const Word32 *ivas_get_cheby_ramp_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_ld_fb_resp_fx( - Word32 **ppIdeal_FRs_re_fx, - Word32 **ppIdeal_FRs_im_fx, - Word32 **ppNew_FRs_re_fx, - Word32 **ppNew_FRs_im_fx, + Word32 **ppIdeal_FRs_re_fx, // i: Q30 + Word32 **ppIdeal_FRs_im_fx, // i: Q30 + Word32 **ppNew_FRs_re_fx, // o: Q30 + Word32 **ppNew_FRs_im_fx, // o: Q30 const Word16 *pActive_bins, const Word16 *pStart_offset, const Word16 num_bands, @@ -1931,18 +1951,18 @@ static void ivas_get_ld_fb_resp_fx( { set32_fx( scratch2_fx, 0, shl( frame_len, 1 ) ); - Copy32( ppIdeal_FRs_re_fx[b], &scratch2_fx[pStart_offset[b]], pActive_bins[b] ); + Copy32( ppIdeal_FRs_re_fx[b], &scratch2_fx[pStart_offset[b]], pActive_bins[b] ); // Q30 Copy32( ppIdeal_FRs_im_fx[b], &scratch2_fx[frame_len + pStart_offset[b]], pActive_bins[b] ); // Q30 Word16 guard_bits = sub( L_norm_arr( scratch2_fx, shl( L_FRAME32k, 1 ) ), find_guarded_bits_fx( shl( frame_len, 1 ) ) ); - Scale_sig32( scratch2_fx, shl( L_FRAME32k, 1 ), guard_bits ); + Scale_sig32( scratch2_fx, shl( L_FRAME32k, 1 ), guard_bits ); // Q30 + guard_bits ivas_imdft_fx( scratch2_fx, &scratch2_fx[frame_len], scratch1_fx, frame_len ); FOR( Word16 x = 0; x < shl( L_FRAME32k, 1 ); x++ ) { - scratch2_fx[x] = L_shr( scratch2_fx[x], guard_bits ); - scratch1_fx[x] = L_shr( scratch1_fx[x], guard_bits ); + scratch2_fx[x] = L_shr( scratch2_fx[x], guard_bits ); // (Q30 + guard_bits) - guard_bits = Q30 + scratch1_fx[x] = L_shr( scratch1_fx[x], guard_bits ); // (Q30 + guard_bits) - guard_bits = Q30 move32(); move32(); @@ -1953,21 +1973,21 @@ static void ivas_get_ld_fb_resp_fx( FOR( s = delay; s < frame_len + delay; s++ ) { - scratch2_fx[sub( s, delay )] = Mpy_32_32( scratch1_fx[s], L_sub( ONE_IN_Q31, han_win_fx[sub( s, delay )] ) ); // Q(30 + 31 - 31) == Q30 + scratch2_fx[s - delay] = Mpy_32_32( scratch1_fx[s], L_sub( ONE_IN_Q31, han_win_fx[s - delay] ) ); // Q(30 + 31 - 31) == Q30 move32(); } FOR( ; s < 2 * frame_len; s++ ) { - scratch2_fx[sub( s, delay )] = Mpy_32_32( scratch1_fx[s], han_win_fx[sub( s, add( frame_len, delay ) )] ); // Q30 + scratch2_fx[s - delay] = Mpy_32_32( scratch1_fx[s], han_win_fx[s - ( frame_len + delay )] ); // Q30 move32(); } FOR( s = 0; s < delay; s++ ) { - scratch2_fx[add( sub( shl( frame_len, 1 ), delay ), s )] = L_negate( Mpy_32_32( scratch1_fx[s], han_win_fx[add( sub( frame_len, delay ), s )] ) ); // Q30 + scratch2_fx[( ( ( frame_len * 2 ) - delay ) + s )] = L_negate( Mpy_32_32( scratch1_fx[s], han_win_fx[( frame_len - delay ) + s] ) ); // Q30 move32(); } @@ -1975,7 +1995,7 @@ static void ivas_get_ld_fb_resp_fx( FOR( s = 0; s < delay + 1; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], pCheby_fx[sub( delay, s )] ); // Q30 + scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], pCheby_fx[delay - s] ); // Q30 move32(); } @@ -1993,31 +2013,31 @@ static void ivas_get_ld_fb_resp_fx( FOR( ; s < 2 * frame_len; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], L_sub( ONE_IN_Q31, pCheby_fx[sub( s, sub( shl( frame_len, 1 ), delay ) )] ) ); // Q30 + scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], L_sub( ONE_IN_Q31, pCheby_fx[s - ( 2 * frame_len - delay )] ) ); // Q30 move32(); } /*IR - pre ring + post ring*/ FOR( s = 1; s < 2 * frame_len; s++ ) { - scratch2_fx[s] = L_sub( L_sub( scratch2_fx[s] /*pre ring*/, scratch1_fx[s] /*post ring*/ ), scratch1_fx[sub( shl( frame_len, 1 ), s )] ); + scratch2_fx[s] = L_sub( L_sub( scratch2_fx[s] /*pre ring*/, scratch1_fx[s] /*post ring*/ ), scratch1_fx[frame_len * 2 - s] ); move32(); } FOR( s = 0; s < 2 * frame_len - delay; s++ ) { - scratch1_fx[add( s, delay )] = scratch2_fx[s]; + scratch1_fx[s + delay] = scratch2_fx[s]; move32(); } FOR( ; s < 2 * frame_len; s++ ) { - scratch1_fx[sub( s, sub( shl( frame_len, 1 ), delay ) )] = L_negate( scratch2_fx[s] ); + scratch1_fx[( s - ( ( frame_len * 2 ) - delay ) )] = L_negate( scratch2_fx[s] ); move32(); } /* apply final window*/ - const Word32 *sine_till_delay = ivas_sine_delay_32_fx; + const Word32 *sine_till_delay = ivas_sine_delay_32_fx; // Q30 Word16 offset = 1; Word16 delay_16 = 0; @@ -2032,7 +2052,7 @@ static void ivas_get_ld_fb_resp_fx( FOR( s = 0; s < delay; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_delay[add( s, imult1616( offset, delay_16 ) )] ); + scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_delay[s + offset * delay_16] ); // Q30 + Q30 - 31 = Q29 offset = add( offset, 1 ); scratch1_fx[s] = L_shl( scratch1_fx[s], 1 ); // Q30 @@ -2045,16 +2065,18 @@ static void ivas_get_ld_fb_resp_fx( IF( EQ_16( delay, IVAS_FB_1MS_16K_SAMP ) ) { sine_till_frame_len = ivas_sine_frame_len_640_del_16_fx; // Q30 + move32(); } ELSE { sine_till_frame_len = ivas_sine_frame_len_640_del_32_fx; // Q30 + move32(); } Word16 iterator = 0; move16(); FOR( s = 2 * delay; s < frame_len + 1; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_frame_len[iterator] ); + scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_frame_len[iterator] ); // Q30 + Q30 - 31 = Q29 iterator = add( iterator, 1 ); scratch1_fx[s] = L_shl( scratch1_fx[s], 1 ); // Q30 @@ -2072,8 +2094,8 @@ static void ivas_get_ld_fb_resp_fx( /*compute frequency response*/ ivas_mdft_fx( scratch1_fx, scratch2_fx, &scratch2_fx[frame_len], shl( frame_len, 1 ), frame_len ); - Copy32( &scratch2_fx[pStart_offset[b]], ppNew_FRs_re_fx[b], pActive_bins[b] ); - Copy32( &scratch2_fx[add( frame_len, pStart_offset[b] )], ppNew_FRs_im_fx[b], pActive_bins[b] ); + Copy32( &scratch2_fx[pStart_offset[b]], ppNew_FRs_re_fx[b], pActive_bins[b] ); // Q30 + Copy32( &scratch2_fx[( frame_len + pStart_offset[b] )], ppNew_FRs_im_fx[b], pActive_bins[b] ); // Q30 } return; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6b5cf78687388e0f52f142d1b04a3f20d741a85b..bf819845cb6735d455d4bef5254da5cf239e5ba6 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -789,7 +789,7 @@ void ivas_renderer_select( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -ivas_error ivas_mc_enc_config( +ivas_error ivas_mc_enc_config_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index b93158e31ba0db121ae98ea02f27fb23489b7719..eff881370b46dc53af3bdfd06272f34e53be5e8a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -253,13 +253,13 @@ void ivas_agc_read_bits_fx( // ivas_agc_com_fx.c void ivas_agc_initWindowFunc_fx( - Word16 *pWinFunc, + Word16 *pWinFunc, // o: Q15 const Word16 length ); void ivas_agc_calcGainParams_fx( - UWord16 *absEmin, - UWord16 *betaE, - UWord16 *maxAttExp, + UWord16 *absEmin, // o: Q0 + UWord16 *betaE, // o: Q0 + UWord16 *maxAttExp, // o: Q0 const Word16 numCoeffs ); void ivas_transient_det_process_fx( @@ -3836,12 +3836,12 @@ void ivas_fb_mixer_pcm_ingest_fx( void ivas_fb_mixer_process_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ - Word16 *q_mixer_mat_fx, /* i : mixer matrix */ - Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ - Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + Word32 ***mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix Q-factor */ + Word32 **ppOut_pcm_fx, /* o : output audio channels */ + Word16 *q_ppOut_pcm_fx, /* o : output audio channels Q-factor */ const Word16 frame_len, /* i : frame length in samples */ - Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); Word16 ivas_get_num_bands_from_bw_idx( @@ -5333,6 +5333,24 @@ void ivas_create_fullr_dmx_mat_fx( const Word16 active_w, ivas_spar_md_com_cfg *hMdCfg ); +void ivas_get_spar_md_from_dirac_enc_fx( + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 + const Word16 n_ts, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ + Word16 *q_mixer_mat_fx, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const Word16 start_band, + const Word16 end_band, + const Word16 order, + const Word16 dtx_vad, + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 + const UWord8 useLowerRes, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ); + void ivas_get_spar_md_from_dirac_fx( Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 4b206e1cac795f01615f84d1012807cf4dce2ecc..236d608590bf4d998dfe873f2bdd8eee81ce3fc9 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2250,11 +2250,19 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_postpred_cov_re_per_value[i][j] = q_tmp_re; move16(); - q_tmp_re = W_norm( tmp_re ); - postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /* q_tmp_re+ q_postpred_cov_re_per_value[i][j] -32*/ - move32(); - q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); - move16(); + IF( tmp_re == 0 ) + { + postpred_cov_re[i][j] = W_extract_l( tmp_re ); /* q_tmp_re*/ + move32(); + } + ELSE + { + q_tmp_re = W_norm( tmp_re ); + postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /* q_tmp_re+ q_postpred_cov_re_per_value[i][j] -32*/ + move32(); + q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); + move16(); + } *q_postpred_cov_re = s_min( *q_postpred_cov_re, q_postpred_cov_re_per_value[i][j] ); move16(); } @@ -4067,7 +4075,8 @@ Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762 #define ONE_BY_THREE_Q31 715827882 #define ONE_BY_FIVE_Q31 429496729 #define ONE_BY_SEVEN_Q31 306783378 -void ivas_get_spar_md_from_dirac_fx( + +void ivas_get_spar_md_from_dirac_enc_fx( Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 @@ -4093,7 +4102,9 @@ void ivas_get_spar_md_from_dirac_fx( Word32 response_avg_fx[MAX_OUTPUT_CHANNELS]; Word32 response_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; Word32 cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word16 q_cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word16 *p_q_Cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 q_dm_fv_re_fx = 0; Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; @@ -4132,10 +4143,8 @@ void ivas_get_spar_md_from_dirac_fx( FOR( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) { pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; - move32(); } ppMixer_mat_fx[i] = pMixer_mat_fx[i]; - move32(); } test(); @@ -4155,43 +4164,38 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // q25 + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[1] = 0; move32(); FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { - P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // q25 + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[2] = 0; move32(); FOR( ; i < ( num_ch - ndm ); i++ ) { - P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // q25 + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // q25 + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 move32(); FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 move32(); - IF( P_dir_fact_fx[idx] == 0 ) - { - P_dir_fact_fx[idx] = 0; - move32(); - } - ELSE + IF( P_dir_fact_fx[idx] != 0 ) { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[0], IVAS_FIX_EPS ) ); // q15 move32(); @@ -4202,13 +4206,8 @@ void ivas_get_spar_md_from_dirac_fx( FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 - IF( P_dir_fact_fx[idx] == 0 ) - { - P_dir_fact_fx[idx] = 0; - move32(); - } - ELSE + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + IF( P_dir_fact_fx[idx] != 0 ) { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[1], IVAS_FIX_EPS ) ); // q15 move32(); @@ -4219,14 +4218,9 @@ void ivas_get_spar_md_from_dirac_fx( FOR( ; i < ( num_ch - ndm ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // q25 + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 move32(); - IF( P_dir_fact_fx[idx] == 0 ) - { - P_dir_fact_fx[idx] = 0; - move32(); - } - ELSE + IF( P_dir_fact_fx[idx] != 0 ) { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[2], IVAS_FIX_EPS ) ); // q15 move32(); @@ -4434,6 +4428,560 @@ void ivas_get_spar_md_from_dirac_fx( /*normalize 3rd order*/ norm_fx = 0; + move32(); + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + { + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 + } + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) + { + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q + } + ELSE + { + norm_fx = EPSILON_FX; + move32(); + } + IF( norm_q < 0 ) + { + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 + norm_q = 0; + move16(); + } + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + { + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) + { + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + move32(); + move32(); + } + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) + { + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 + move32(); + } + ELSE + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + move32(); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + } + } + } + } + + FOR( i = add( FOA_CHANNELS, 1 ); i < num_ch; i++ ) + { + response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; // q30 + move32(); + } + + + en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30=>q31 + en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); // q31 + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + IF( EQ_16( i, j ) ) + { + IF( i == 0 ) + { + cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; // 1 q30 + move32(); + } + ELSE + { + Word32 en_ratio_fac_sq = 0; + move32(); + cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); // q30 + move32(); + + IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) + { + cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); // q30 + move32(); + test(); + IF( ( GE_16( i, ndm ) ) && ( EQ_16( dtx_vad, 1 ) ) ) + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); // q30 + move32(); + } + ELSE + { + IF( LT_16( i, foa_ch ) ) + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31 /*1 q31*/, en_ratio_fac_sq ), ONE_BY_THREE_Q31 /*1/3 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 + move32(); + } + ELSE IF( LT_16( i, hoa2_ch ) ) + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 + move32(); + } + ELSE + { + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 + move32(); + } + } + } + ELSE + { + IF( LT_16( i, foa_ch ) ) + { + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 /*1/3 q31*/ ), 1 ) ); // q30 + move32(); + } + ELSE IF( LT_16( i, hoa2_ch ) ) + { + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ), 1 ) ); // q30 + move32(); + } + ELSE + { + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ), 1 ) ); // q30 + move32(); + } + } + } + } + ELSE + { + cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); // q30 + move32(); + } + } + } + } + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; // q30 + p_q_Cov_real_fx[i][j] = q_cov_real_dirac_fx[i][j]; // q30 + set16_fx( q_cov_real_dirac_fx[i][j], Q30, IVAS_MAX_NUM_BANDS ); + } + } + + test(); + active_w = ( EQ_16( dyn_active_w_flag, 1 ) ) || ( EQ_16( hSpar_md_cfg->active_w, 1 ) ); + ivas_compute_spar_params_enc_fx( pCov_real_fx, p_q_Cov_real_fx, dm_fv_re_fx, &q_dm_fv_re_fx, i_ts, ppMixer_mat_fx, &q_ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale_fx, q_Wscale, 1, dyn_active_w_flag ); + + IF( mixer_mat_fx != NULL ) + { + if ( *q_mixer_mat_fx == 0 ) + { + *q_mixer_mat_fx = q_ppMixer_mat; + move16(); + } + FOR( band = start_band; band < end_band; band++ ) + { + ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); + + FOR( i = 0; i < ndm; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); // q_mixer_mat_fx + move32(); + } + } + + FOR( i = ndm; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = 0; + move32(); + } + } + + test(); + IF( ( EQ_16( ndm, 1 ) ) && ( Wscale_d != NULL ) ) + { + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); // q_mixer_mat_fx + move32(); + } + } + } + } + } + + return; +} + + +void ivas_get_spar_md_from_dirac_fx( + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 + const Word16 n_ts, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ + Word16 *q_mixer_mat_fx, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const Word16 start_band, + const Word16 end_band, + const Word16 order, + const Word16 dtx_vad, + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 + const UWord8 useLowerRes, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ) +{ + + Word16 num_ch, band, i, j; + Word16 block, ch; + Word16 azimuth, elevation; + + Word32 response_avg_fx[MAX_OUTPUT_CHANNELS]; + Word32 response_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; + Word32 cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word16 q_dm_fv_re_fx = 0; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; + Word32 mixer_mat_local_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; + Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 q_ppMixer_mat = 0; + Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; + Word16 active_w; + move16(); + move16(); + + Word16 ndm, foa_ch, hoa2_ch; + Word32 P_dir_fact_fx[IVAS_SPAR_MAX_CH - 1]; + const Word16 *remix_order; + + set16_fx( q_Wscale, 0, IVAS_MAX_NUM_BANDS ); + set32_fx( Wscale_fx, 0, IVAS_MAX_NUM_BANDS ); + remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; + + num_ch = ivas_sba_get_nchan_metadata_fx( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); + + hoa2_ch = ivas_sba_get_nchan_metadata_fx( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); + foa_ch = FOA_CHANNELS; + move16(); + diff_norm_order1_fx = 3; + move32(); + diff_norm_order2_fx = 5; + move32(); + diff_norm_order3_fx = 7; + move32(); + + FOR( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) + { + FOR( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) + { + pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; + } + ppMixer_mat_fx[i] = pMixer_mat_fx[i]; + } + + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GE_16( start_band, 6 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) || ( useLowerRes && GE_16( start_band, 3 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) ) + { + Word32 P_norm_fx[3]; + Word16 idx; + + ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; + move16(); + P_norm_fx[0] = 0; + move32(); + FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) + { + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 + move32(); + } + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 + move32(); + + P_norm_fx[1] = 0; + move32(); + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) + { + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 + move32(); + } + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 + move32(); + + P_norm_fx[2] = 0; + move32(); + FOR( ; i < ( num_ch - ndm ); i++ ) + { + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 + move32(); + } + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 + move32(); + + FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ ) + { + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + move32(); + IF( P_dir_fact_fx[idx] != 0 ) + { + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[0], IVAS_FIX_EPS ) ); // q15 + move32(); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 + move32(); + } + } + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) + { + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + IF( P_dir_fact_fx[idx] != 0 ) + { + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[1], IVAS_FIX_EPS ) ); // q15 + move32(); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 + move32(); + } + } + FOR( ; i < ( num_ch - ndm ); i++ ) + { + idx = sub( remix_order[i + ndm], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); // 2*q_P_re - 31 + move32(); + IF( P_dir_fact_fx[idx] != 0 ) + { + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[2], IVAS_FIX_EPS ) ); // q15 + move32(); + P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); // q30 + move32(); + } + } + } + + FOR( Word16 i_ts = 0; i_ts < n_ts; i_ts++ ) + { + FOR( band = start_band; band < end_band; band++ ) + { + ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); + + /*SPAR from DirAC*/ + set32_fx( response_avg_fx, 0, MAX_OUTPUT_CHANNELS ); + + IF( GT_16( n_ts, 1 ) ) + { + IF( ele_dirac_fx[band][i_ts] < 0 ) + { + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 + } + ELSE + { + elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); // q0 + } + IF( azi_dirac_fx[band][i_ts] < 0 ) + { + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 + } + ELSE + { + azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); // q0 + } + ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); + } + ELSE IF( useLowerRes ) + { + IF( ele_dirac_fx[band][0] < 0 ) + { + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); // q0 + } + ELSE + { + elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); // q0 + } + IF( azi_dirac_fx[band][0] < 0 ) + { + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); // q0 + } + ELSE + { + azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); // q0 + } + ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); + } + ELSE + { + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + IF( ele_dirac_fx[band][block] < 0 ) + { + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); // q0 + } + ELSE + { + elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); // q0 + } + IF( azi_dirac_fx[band][block] < 0 ) + { + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); // q0 + } + ELSE + { + azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); // q0 + } + ivas_dirac_dec_get_response_fx( azimuth, elevation, &( response_fx[block][0] ), order, Q30 ); + } + + /* average responses in all subframes*/ + { + Word32 norm_fx; + Word16 norm_q; + Word16 num_ch_order, hoa2_ch_order; + + num_ch_order = ivas_sba_get_nchan_fx( order, 0 ); + hoa2_ch_order = ivas_sba_get_nchan_fx( SBA_HOA2_ORDER, 0 ); + + FOR( ch = 0; ch < num_ch_order; ch++ ) + { + Word64 temp = 0; + move64(); + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); // q30 + } + response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); // q30 + move32(); + } + + /*normalize 1st order*/ + norm_fx = 0; + move32(); + norm_q = 0; + move16(); + FOR( ch = 1; ch < foa_ch; ch++ ) + { + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 + } + + norm_q = sub( 31, ( sub( add( 30, 30 ), 31 ) ) ); + IF( norm_fx ) + { + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q + } + ELSE + { + norm_fx = EPSILON_FX; + move32(); + } + IF( norm_q <= 0 ) + { + norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); // q=31 + norm_q = 0; + move16(); + } + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 + FOR( ch = 1; ch < foa_ch; ch++ ) + { + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) + { + IF( response_avg_fx[ch] != 0 ) + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + move32(); + } + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + } + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) + { + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 + move32(); + } + ELSE + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + move32(); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + } + } + + /*normalize 2nd order*/ + norm_fx = 0; + move32(); + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + { + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 + } + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) + { + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q + } + ELSE + { + norm_fx = EPSILON_FX; + move32(); + } + IF( norm_q < 0 ) + { + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 + norm_q = 0; + move16(); + } + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + { + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) + { + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + move32(); + move32(); + } + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) + { + response_avg_fx[ch] = ONE_IN_Q30; // q30 + move32(); + } + ELSE + { + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 + move32(); + move32(); + } + } + + /*normalize 3rd order*/ + norm_fx = 0; + move32(); FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index 829f4e5e8ae7560ef4aac4a5028d38f3609ca118..e408d6b96c4bcef59851e1f186c666e98003e56b 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -59,7 +59,7 @@ Word32 table_596[N_MAX_SHIFT_CHANGE + 1] = { 0, 2441216, 1220608, 813738, 610304, 488243, 406869, 348745, 305152, 271246, 244121, 221928, 203434, 187785, 174372, 162747, 152576, 143600, 135623, 128485, 122060 -}; // Q21 +}; // Q12 Word32 inv_table_596[N_MAX_SHIFT_CHANGE + 1] = { 0, 7206320, 14412641, 21618962, 28825283, 36031605, 43237924, 50444244, @@ -77,53 +77,53 @@ Word32 table_298[N_MAX_SHIFT_CHANGE + 1] = { 0, 1220608, 610304, 406869, 305152, 244121, 203434, 174372, 152576, 135623, 122060, 110964, 101717, 93892, 87186, 81373, 76288, 71800, 67811, 64242, 61030 -}; +}; // Q12 Word32 inv_table_298[N_MAX_SHIFT_CHANGE + 1] = { 0, 14412641, 28825283, 43237924, 57650567, 72063211, 86475849, 100888489, 115301135, 129713778, 144126422, 158539056, 172951698, 187364347, 201776979, 216189627, 230602270, 245014919, 259427557, 273840192, 288252845 -}; +}; // Q31 Word32 tableD1_298[N_MAX_SHIFT_CHANGE + 1] = { 0, 1731, 13849, 46741, 110794, 216396, 373932, 593791, 886359, 1262023, 1731170, 2304187, 2991462, 3803381, 4750330, 5842699, 7090873, 8505240, 10096185, 11874096, 13849363 -}; +}; // Q35 Word32 table_290[N_MAX_SHIFT_CHANGE + 1] = { 0, 1187840, 593920, 395946, 296960, 237568, 197973, 169691, 148480, 131982, 118784, 107985, 98986, 91372, 84845, 79189, 74240, 69872, 65991, 62517, 59392 -}; +}; // Q12 Word32 inv_table_290[N_MAX_SHIFT_CHANGE + 1] = { 0, 14810232, 29620464, 44430697, 59240928, 74051160, 88861394, 103671628, 118481856, 133292091, 148102320, 162912554, 177722789, 192533022, 207343256, 222153473, 236963712, 251773958, 266584183, 281394409, 296204640 -}; +}; // Q31 Word32 tableD1_290[N_MAX_SHIFT_CHANGE + 1] = { 0, 1878, 15027, 50717, 120219, 234803, 405740, 644300, 961755, 1369374, 1878428, 2500187, 3245924, 4126907, 5154407, 6339694, - 7694041, 9228719, 10954993, 12884138, 15027425 }; + 7694041, 9228719, 10954993, 12884138, 15027425 }; // Q35 Word32 table_145[N_MAX_SHIFT_CHANGE + 1] = { 0, 593920, 296960, 197973, 148480, 118784, 98986, 84845, 74240, 65991, 59392, 53992, 49493, 45686, 42422, 39594, 37120, 34936, 32995, 31258, 29696 -}; +}; // Q12 Word32 inv_table_145[N_MAX_SHIFT_CHANGE + 1] = { 0, 29620464, 59240928, 88861394, 118481856, 148102320, 177722789, 207343256, 236963712, 266584183, 296204640, 325825109, 355445578, 385066045, 414686513, 444306946, 473927425, 503547916, 533168367, 562788819, 592409281 -}; +}; // Q31 Word32 tableD1_145[N_MAX_SHIFT_CHANGE + 1] = { 0, 15027, 120219, 405740, 961755, 1878428, 3245924, 5154407, 7694041, 10954993, 15027425, 20001503, 25967392, 33015256, 41235259, 50717555, - 61552334, 73829752, 87639951, 103073111, 120219402 }; + 61552334, 73829752, 87639951, 103073111, 120219402 }; // Q35 #ifdef IVAS_FLOAT_FIXED static void interpTargetChannel_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt ) + Word32 *target_fx, // qsynth + const Word16 prevShift, // Q0 + const Word16 currShift, // Q0 + const Word16 L_shift_adapt ) // Q0 { Word16 i, j, k, /*m,*/ d, N, signShift, lim1, lim2; const Word32 *win_fx; @@ -160,43 +160,43 @@ static void interpTargetChannel_fx( SWITCH( N ) { case 596: - table_pointer = table_596; - inv_table_pointer = inv_table_596; - table_D1_pointer = tableD1_596; + table_pointer = table_596; // Q12 + inv_table_pointer = inv_table_596; // Q31 + table_D1_pointer = tableD1_596; // Q35 BREAK; case 298: - table_pointer = table_298; - inv_table_pointer = inv_table_298; - table_D1_pointer = tableD1_298; + table_pointer = table_298; // Q12 + inv_table_pointer = inv_table_298; // Q31 + table_D1_pointer = tableD1_298; // Q35 BREAK; case 290: - table_pointer = table_290; - inv_table_pointer = inv_table_290; - table_D1_pointer = tableD1_290; + table_pointer = table_290; // Q12 + inv_table_pointer = inv_table_290; // Q31 + table_D1_pointer = tableD1_290; // Q35 BREAK; case 145: - table_pointer = table_145; - inv_table_pointer = inv_table_145; - table_D1_pointer = tableD1_145; + table_pointer = table_145; // Q12 + inv_table_pointer = inv_table_145; // Q31 + table_D1_pointer = tableD1_145; // Q35 BREAK; default: assert( 0 ); } - factor_fx = table_pointer[L_abs( d )]; + factor_fx = table_pointer[abs( d )]; // Q12 move32(); - interp_factor2_fx = L_shr( factor_fx, 1 ); - spread_factor2_fx = inv_table_pointer[L_abs( d )]; + interp_factor2_fx = L_shr( factor_fx, 1 ); // Q12 + spread_factor2_fx = inv_table_pointer[abs( d )]; // Q31 move32(); /* start from (target - N - d + 1) : (extra lag = step1) :to: (target - 1 - d) : (extra lag = d) */ /* sinc interp by a factor of 2 */ - win_fx = ica_sincInterp2_fx + SINC_ORDER1; - ptr1_fx = target_fx; + win_fx = ica_sincInterp2_fx + SINC_ORDER1; // Q31 + ptr1_fx = target_fx; // qsynth ptr2_fx = tempBuff1_fx + ( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; - FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < imult1616( ( add( add( N, N_MAX_SHIFT_CHANGE ), 1 ) ), INTERP_FACTOR1 ); i++ ) + FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < ( N + N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i++ ) { IF( s_and( i, 0x1 ) ) { @@ -210,38 +210,38 @@ static void interpTargetChannel_fx( FOR( j = lim1; j <= lim2; j++ ) { - ptr2_fx[i] = L_add( Mpy_32_32( win_fx[sub( imult1616( j, INTERP_FACTOR1 ), i )], ptr1_fx[j] ), ptr2_fx[i] ); + ptr2_fx[i] = L_add( Mpy_32_32( win_fx[j * INTERP_FACTOR1 - i], ptr1_fx[j] ), ptr2_fx[i] ); // qsynth move32(); } } ELSE { - ptr2_fx[i] = ptr1_fx[shr( i, 1 )]; + ptr2_fx[i] = ptr1_fx[i / 2]; // qsynth move32(); } } /* cubic spline interp */ - ptr1_fx = ptr2_fx; - ptr2_fx = tempBuff2_fx; + ptr1_fx = ptr2_fx; // qsynth + ptr2_fx = tempBuff2_fx; // qsynth - tempD1_fx = W_deposit32_l( table_D1_pointer[L_abs( d )] ); - tempD2_fx = W_mult0_32_32( 3, table_D1_pointer[L_abs( d )] ); + tempD1_fx = W_deposit32_l( table_D1_pointer[abs( d )] ); // Q35 + tempD2_fx = W_mult0_32_32( 3, table_D1_pointer[abs( d )] ); // Q35 IF( EQ_16( signShift, 1 ) ) { - tempF1_fx = ONE_IN_Q12; + tempF1_fx = ONE_IN_Q12; // Q12 move32(); } ELSE { - tempF1_fx = -ONE_IN_Q12; + tempF1_fx = -ONE_IN_Q12; // Q12 move32(); } - tempF1_fx = L_sub( imult3216( factor_fx, d ), tempF1_fx ); + tempF1_fx = L_sub( imult3216( factor_fx, d ), tempF1_fx ); // Q12 FOR( k = 0; k < sub( N, 1 ); k++ ) { - Word32 local = L_sub( W_extract_l( W_shr( W_mult0_32_32( tempF1_fx, spread_factor2_fx ), 31 ) ), ONE_IN_Q12 ); + Word32 local = L_sub( W_extract_l( W_shr( W_mult0_32_32( tempF1_fx, spread_factor2_fx ), 31 ) ), ONE_IN_Q12 ); // Q12 Word32 sign_local; IF( local > 0 ) { @@ -253,7 +253,7 @@ static void interpTargetChannel_fx( sign_local = -1; move32(); } - Word32 local_int = W_extract_l( W_shr( W_abs( local ), 12 ) ); + Word32 local_int = W_extract_l( W_shr( W_abs( local ), 12 ) ); // Q0 Word32 res_a1, res_a2, res_a3; Word32 res_b1, res_b2, res_b3; Word32 res_c1, res_c2, res_c3; @@ -262,79 +262,79 @@ static void interpTargetChannel_fx( Word64 res_a, res_b, res_c, res_d; Word64 tempa, tempb; Word64 mult_a_D1, mult_b_D2; - local_int = W_extract_l( W_mult0_32_32( sign_local, local_int ) ); - local_int_scaled = W_deposit32_l( L_shl( local_int, 12 ) ); - lim1 = extract_l( local_int ); - if ( W_sub( local_int_scaled, local ) > 0 ) + local_int = W_extract_l( W_mult0_32_32( sign_local, local_int ) ); // Q0 + local_int_scaled = W_deposit32_l( L_shl( local_int, 12 ) ); // Q12 + lim1 = extract_l( local_int ); // Q0 + IF( W_sub( local_int_scaled, local ) > 0 ) // Q21 { - lim1 = sub( lim1, 1 ); + lim1 = sub( lim1, 1 ); // Q0 } - y_fx[0] = ptr1_fx[lim1]; + y_fx[0] = ptr1_fx[lim1]; // qsynth move32(); - y_fx[1] = ptr1_fx[add( lim1, 1 )]; + y_fx[1] = ptr1_fx[lim1 + 1]; // qsynth move32(); - y_fx[2] = ptr1_fx[add( lim1, 2 )]; + y_fx[2] = ptr1_fx[lim1 + 2]; // qsynth move32(); - y_fx[3] = ptr1_fx[add( lim1, 3 )]; + y_fx[3] = ptr1_fx[lim1 + 3]; // qsynth move32(); - x_fx[0] = imult3216( interp_factor2_fx, lim1 ); + x_fx[0] = imult3216( interp_factor2_fx, lim1 ); // Q12 move32(); - x_fx[1] = L_add( x_fx[0], interp_factor2_fx ); + x_fx[1] = L_add( x_fx[0], interp_factor2_fx ); // Q12 move32(); - x_fx[2] = L_add( x_fx[1], interp_factor2_fx ); + x_fx[2] = L_add( x_fx[1], interp_factor2_fx ); // Q12 move32(); - x_fx[3] = L_add( x_fx[2], interp_factor2_fx ); + x_fx[3] = L_add( x_fx[2], interp_factor2_fx ); // Q12 move32(); - 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 = W_shr( W_mult0_32_32( res_a1, res_a2 ), 12 ) * res_a3; - res_a = ( y_fx[3] * W_shr( res_a, 16 ) ); + res_a1 = L_sub( tempF1_fx, x_fx[0] ); // Q12 + res_a2 = L_sub( tempF1_fx, x_fx[1] ); // Q12 + res_a3 = L_sub( tempF1_fx, x_fx[2] ); // Q12 + res_a = W_shr( W_mult0_32_32( res_a1, res_a2 ), 12 ) * res_a3; // Q24 + res_a = ( y_fx[3] * W_shr( res_a, 16 ) ); // qsynth+8 - 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 = W_shr( W_mult0_32_32( res_b1, res_b2 ), 12 ) * res_b3; - res_b = ( y_fx[0] * W_shr( res_b, 16 ) ); + res_b1 = L_sub( tempF1_fx, x_fx[1] ); // Q12 + res_b2 = L_sub( tempF1_fx, x_fx[2] ); // Q12 + res_b3 = L_sub( tempF1_fx, x_fx[3] ); // Q12 + res_b = W_shr( W_mult0_32_32( res_b1, res_b2 ), 12 ) * res_b3; // Q24 + res_b = ( y_fx[0] * W_shr( res_b, 16 ) ); // qsynth+8 - 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 = W_shr( W_mult0_32_32( res_c1, res_c2 ), 12 ) * res_c3; - res_c = ( y_fx[1] * W_shr( res_c, 16 ) ); + res_c1 = L_sub( tempF1_fx, x_fx[0] ); // Q12 + res_c2 = L_sub( tempF1_fx, x_fx[2] ); // Q12 + res_c3 = L_sub( tempF1_fx, x_fx[3] ); // Q12 + res_c = W_shr( W_mult0_32_32( res_c1, res_c2 ), 12 ) * res_c3; // Q24 + res_c = ( y_fx[1] * W_shr( res_c, 16 ) ); // qsynth+8 - 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 = W_shr( W_mult0_32_32( res_d1, res_d2 ), 12 ) * res_d3; - res_d = ( y_fx[2] * W_shr( res_d, 16 ) ); + res_d1 = L_sub( tempF1_fx, x_fx[0] ); // Q12 + res_d2 = L_sub( tempF1_fx, x_fx[1] ); // Q12 + res_d3 = L_sub( tempF1_fx, x_fx[3] ); // Q12 + res_d = W_shr( W_mult0_32_32( res_d1, res_d2 ), 12 ) * res_d3; // Q24 + res_d = ( y_fx[2] * W_shr( res_d, 16 ) ); // qsynth+8 - tempa = W_sub( res_a, res_b ); - tempb = W_sub( res_c, res_d ); + tempa = W_sub( res_a, res_b ); // qsynth+8 + tempb = W_sub( res_c, res_d ); // qsynth+8 - mult_a_D1 = W_shr( ( tempD1_fx * W_shr( tempa, 14 ) ), 15 ); - mult_b_D2 = W_shr( ( tempD2_fx * W_shr( tempb, 14 ) ), 15 ); + mult_a_D1 = W_shr( ( tempD1_fx * W_shr( tempa, 14 ) ), 15 ); // Q38 + mult_b_D2 = W_shr( ( tempD2_fx * W_shr( tempb, 14 ) ), 15 ); // Q38 ptr2_fx[k] = W_extract_l( ( W_shr( W_add( mult_a_D1, mult_b_D2 ), 14 ) ) ); // 38-14 move32(); IF( EQ_16( signShift, 1 ) ) { - tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, ONE_IN_Q12 ) ) ); + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, ONE_IN_Q12 ) ) ); // Q12 move32(); } ELSE { - tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, -ONE_IN_Q12 ) ) ); + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, -ONE_IN_Q12 ) ) ); // Q12 move32(); } } - ptr1_fx = target_fx; - Copy32( ptr2_fx, ptr1_fx, sub( N, 1 ) ); + ptr1_fx = target_fx; // qsynth + Copy32( ptr2_fx, ptr1_fx, sub( N, 1 ) ); // qsynth return; } @@ -347,10 +347,10 @@ static void interpTargetChannel_fx( * ---------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void targetCh_AlignStereoDFT_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt ) + Word32 *target_fx, // qsynth + const Word16 prevShift, // Q0 + const Word16 currShift, // Q0 + const Word16 L_shift_adapt ) // Q0 { Word16 i; Word32 winSlope_fx, alpha_fx; @@ -359,10 +359,10 @@ static void targetCh_AlignStereoDFT_fx( Word32 fadeOutBuff_fx[L_SHIFT_ADAPT_MAX]; Word32 fadeInBuff_fx[L_SHIFT_ADAPT_MAX]; - d = negate( sub( currShift, prevShift ) ); + d = negate( sub( currShift, prevShift ) ); // Q0 - Copy32( target_fx + d, fadeOutBuff_fx, L_shift_adapt ); - Copy32( target_fx, fadeInBuff_fx, L_shift_adapt ); + Copy32( target_fx + d, fadeOutBuff_fx, L_shift_adapt ); // qsynth + Copy32( target_fx, fadeInBuff_fx, L_shift_adapt ); // qsynth IF( L_shift_adapt > 0 ) { @@ -370,37 +370,37 @@ static void targetCh_AlignStereoDFT_fx( SWITCH( L_shift_adapt ) { case 596: - winSlope_fx = 3603160; + winSlope_fx = 3603160; /* ( 1 / 596 ) in Q31 */ // Q31 move32(); BREAK; case 298: - winSlope_fx = 7206320; + winSlope_fx = 7206320; /* ( 1 / 298 ) in Q31 */ // Q31 move32(); BREAK; case 290: - winSlope_fx = 7405116; + winSlope_fx = 7405116; /* ( 1 / 290 ) in Q31 */ // Q31 move32(); BREAK; case 145: - winSlope_fx = 14810232; + winSlope_fx = 14810232; /* ( 1 / 145 ) in Q31 */ // Q31 move32(); BREAK; default: - winSlope_fx = ONE_IN_Q31; + winSlope_fx = ONE_IN_Q31; // Q31 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] ) ); + 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] ) ); // qsynth move32(); - alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); + alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); // Q31 } } ELSE { - Copy32( fadeInBuff_fx, target_fx, L_shift_adapt ); + Copy32( fadeInBuff_fx, target_fx, L_shift_adapt ); // qsynth } return; @@ -414,11 +414,11 @@ static void targetCh_AlignStereoDFT_fx( * ---------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void adjustTargetSignal_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt, - const Word16 method ) + Word32 *target_fx, // qsynth + const Word16 prevShift, // Q0 + const Word16 currShift, // Q0 + const Word16 L_shift_adapt, // Q0 + const Word16 method ) // Q0 { /* inter-frame shift variation and target shifting */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 4bead686b55632d07b4536c2543e5b65902a3dc7..089a92b5387ef05833b3efdbf9b80cd8c122cc95 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4047,20 +4047,25 @@ Word16 getTcxLpcShapedAri( ); // tcx_mdct_window.c -void mdct_window_sine( PWord16 *window, Word16 n ); +void mdct_window_sine( + PWord16 *window, /* Qx */ + Word16 n /* Q0 */ +); void mdct_window_sine_IVAS_updated( - PWord16 *window, - const int32_t Fs, - const int16_t n, - const int16_t window_type, - const int16_t element_mode ); + PWord16 *window, /* Qx */ + const Word32 Fs, /* Q0 */ + const Word16 n, /* Q0 */ + const Word16 window_type, /* Q0 */ + const Word16 element_mode /* Q0 */ +); void mdct_window_aldo( - Word16 *window1, - PWord16 *window1_trunc, - PWord16 *window2, - Word16 n ); + Word16 *window1, /* Q15 */ + PWord16 *window1_trunc, /* Q15 */ + PWord16 *window2, /* Q15 */ + Word16 n /* Q0 */ +); // tcx_utils.c Word16 getInvFrameLen( const Word16 L_frame ); /* returns 1/L_frame in Q21 format */ @@ -5578,53 +5583,58 @@ void phase_dispersion( // tcx_ltp_fx.c void tcx_ltp_get_lpc( - Word16 *x, - const Word16 L, - Word16 *A, - const Word16 order ); + Word16 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word16 *A, /* Qx */ + const Word16 order /* Q0 */ +); void tcx_ltp_get_lpc_fx( - Word32 *x, - const Word16 L, - Word32 *A, - const Word16 order ); + Word32 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word32 *A, /* Qx */ + const Word16 order /* Q0 */ +); void predict_signal( - const Word16 excI[], /* i : i excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max, /* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ -); - -Word16 tcx_ltp_decode_params( Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - const Word16 pitmin, - const Word16 pitfr1, - const Word16 pitfr2, - const Word16 pitmax, - const Word16 pitres ); + const Word16 excI[], /* i : input excitation buffer Qx*/ + Word16 excO[], /* o : output excitation buffer Qx*/ + const Word16 T0, /* i : integer pitch lag Q0*/ + Word16 frac, /* i : fraction of lag Q0*/ + const Word16 frac_max, /* i : max fraction Q0*/ + const Word16 L_subfr /* i : subframe size Q0*/ +); + +Word16 tcx_ltp_decode_params( + Word16 *ltp_param, /* Q0 */ + Word16 *pitch_int, /* Q0 */ + Word16 *pitch_fr, /* Q0 */ + Word16 *gain, /* Q13 */ + const Word16 pitmin, /* Q0 */ + const Word16 pitfr1, /* Q0 */ + const Word16 pitfr2, /* Q0 */ + const Word16 pitmax, /* Q0 */ + const Word16 pitres /* Q0 */ +); void tcx_ltp_post( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf ); + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word16 *sig, /* Qx */ + Word16 *tcx_buf /* Qx */ +); void tcx_ltp_post32( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word32 *sig, - Word32 *tcx_buf, + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word32 *sig, /* sig_q */ + Word32 *tcx_buf, /* sig_q */ Word16 sig_q ); // gs_inact_switching_fx.c diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index 89965f8de95f941a92a86c818c31f20b95cd4558..a42272f0b7a5806dbaaf6febb9e62d4544b2891a 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -17,10 +17,11 @@ #define MAX_TRANSITION_LEN 240 /* L_FRAME_48K / 4 */ void tcx_ltp_get_lpc( - Word16 *x, - const Word16 L, - Word16 *A, - const Word16 order ) + Word16 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word16 *A, /* Qx */ + const Word16 order /* Q0 */ +) { Word16 i, j, s, s2, tmp; Word32 r, L_tmp; @@ -37,25 +38,25 @@ void tcx_ltp_get_lpc( r = L_deposit_l( 0 ); FOR( j = 0; j < L; j++ ) { - L_tmp = L_sub( r, 0x40000000 ); + L_tmp = L_sub( r, 0x40000000 /* 1 in Q30 */ ); /* Q30 */ if ( L_tmp > 0 ) s = sub( s, 1 ); if ( L_tmp > 0 ) r = L_shr( r, 2 ); - tmp = shl( x[j], s ); + tmp = shl( x[j], s ); /* Qx + s */ #ifdef BASOP_NOGLOB - r = L_mac0_sat( r, tmp, tmp ); + r = L_mac0_sat( r, tmp, tmp ); /* Q30 */ #else r = L_mac0( r, tmp, tmp ); #endif } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -70,18 +71,18 @@ void tcx_ltp_get_lpc( move64(); FOR( j = 0; j < L; j++ ) { - tmpbuf[j] = mult_r( x[j], tmp ); + tmpbuf[j] = mult_r( x[j], tmp ); /* Qx */ move16(); - r64 = W_mac0_16_16( r64, tmpbuf[j], tmpbuf[j] ); + r64 = W_mac0_16_16( r64, tmpbuf[j], tmpbuf[j] ); /* Q30 */ } - r = W_sat_l( r64 ); + r = W_sat_l( r64 ); /* Q30 */ } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -99,12 +100,12 @@ void tcx_ltp_get_lpc( move64(); FOR( j = 0; j < tmp; j++ ) { - r64 = W_mac0_16_16( r64, p[j], p[j + i] ); + r64 = W_mac0_16_16( r64, p[j], p[j + i] ); /* Q30 */ } r = W_sat_l( r64 ); } r = L_shl( r, s2 ); - r_l[i] = L_Extract_lc( r, &r_h[i] ); + r_l[i] = L_Extract_lc( r, &r_h[i] ); /* Q14 */ move16(); move16(); } @@ -113,10 +114,11 @@ void tcx_ltp_get_lpc( } void tcx_ltp_get_lpc_fx( - Word32 *x, - const Word16 L, - Word32 *A, - const Word16 order ) + Word32 *x, /* Qx */ + const Word16 L, /* Q0 */ + Word32 *A, /* Qx */ + const Word16 order /* Q0 */ +) { Word16 i, j, s, s2; Word32 r, tmp, L_tmp; @@ -133,21 +135,21 @@ void tcx_ltp_get_lpc_fx( r = L_deposit_l( 0 ); FOR( j = 0; j < L; j++ ) { - L_tmp = L_sub( r, 0x40000000 ); + L_tmp = L_sub( r, 0x40000000 /* 1 in Q30 */ ); /* Q30 */ if ( L_tmp > 0 ) s = sub( s, 1 ); if ( L_tmp > 0 ) r = L_shr( r, 2 ); - tmp = L_shl( x[j], s ); + tmp = L_shl( x[j], s ); /* Qx + s */ r = Madd_32_32( r, tmp, tmp ); } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -168,12 +170,12 @@ void tcx_ltp_get_lpc_fx( } r = W_sat_l( r64 ); } - r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); - r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); + r = L_max( r, L_shl( 100, shl( s, 1 ) ) ); /* Q30 */ + r = Mpy_32_16_1( r, 16386 /*1.0001f Q14*/ ); /* Q29 */ s2 = norm_l( r ); r = L_shl( r, s2 ); s2 = sub( s2, 1 ); - r_l[0] = L_Extract_lc( r, &r_h[0] ); + r_l[0] = L_Extract_lc( r, &r_h[0] ); /* Q14 */ move16(); move16(); @@ -191,12 +193,12 @@ void tcx_ltp_get_lpc_fx( move64(); FOR( j = 0; j < tmp; j++ ) { - r64 = W_add( r64, Mpy_32_32( p[j], p[j + i] ) ); + r64 = W_add( r64, Mpy_32_32( p[j], p[j + i] ) ); /* Q30 */ } r = W_sat_l( r64 ); } r = L_shl( r, s2 ); - r_l[i] = L_Extract_lc( r, &r_h[i] ); + r_l[i] = L_Extract_lc( r, &r_h[i] ); /* Q14 */ move16(); move16(); } @@ -205,17 +207,18 @@ void tcx_ltp_get_lpc_fx( } static void tcx_ltp_get_zir( - Word16 *zir, - const Word16 length, - Word16 *synth_ltp, - Word16 *synth, - Word16 *A, - const Word16 lpcorder, - const Word16 gain, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 pitres, - const Word16 filtIdx ) + Word16 *zir, /* Qx */ + const Word16 length, /* Q0 */ + Word16 *synth_ltp, /* Qx */ + Word16 *synth, /* Qx */ + Word16 *A, /* Qx */ + const Word16 lpcorder, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 pitres, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word16 buf[TCXLTP_LTP_ORDER], alpha, step; Word16 *x0, *x1; @@ -224,18 +227,18 @@ static void tcx_ltp_get_zir( const Word16 *w0, *w1, *v0, *v1; Word16 i, j, k, L; - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitres, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitres]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitres - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitres]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); FOR( j = 0; j < lpcorder; j++ ) @@ -247,20 +250,20 @@ static void tcx_ltp_get_zir( FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ #else s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add( k, pitres ); + k = k + pitres; } /* s2 *= ALPHA; buf[j] = ( synth[j] - gain * s2 ) - ( synth_ltp[j] - gain * s ); */ #ifdef BASOP_NOGLOB i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); - buf[j] = add_sat( sub_sat( synth[j], synth_ltp[j] ), mult_r_sat( gain, i ) ); + buf[j] = add_sat( sub_sat( synth[j], synth_ltp[j] ), mult_r_sat( gain, i ) ); /* Qx */ #else i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); buf[j] = add( sub( synth[j], synth_ltp[j] ), mult_r( gain, i ) ); @@ -277,13 +280,13 @@ static void tcx_ltp_get_zir( E_UTIL_synthesis( 0, A, zir, zir, length, buf, 0, lpcorder ); - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); /* step = 1.f/(float)(length/2); */ step = shl( 4, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -291,26 +294,27 @@ static void tcx_ltp_get_zir( move16(); } - FOR( j = shr( length, 1 ); j < length; j++ ) + FOR( j = length / 2; j < length; j++ ) { - zir[j] = mult_r( zir[j], alpha ); + zir[j] = mult_r( zir[j], alpha ); /* Qx */ move16(); alpha = sub( alpha, step ); } } static void tcx_ltp_get_zir_fx( - Word32 *zir, - const Word16 length, - Word32 *synth_ltp, - Word32 *synth, - Word32 *A, - const Word16 lpcorder, - const Word16 gain, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 pitres, - const Word16 filtIdx ) + Word32 *zir, /* Qx */ + const Word16 length, /* Q0 */ + Word32 *synth_ltp, /* Qx */ + Word32 *synth, /* Qx */ + Word32 *A, /* Qx */ + const Word16 lpcorder, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 pitres, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word32 buf[TCXLTP_LTP_ORDER]; Word16 alpha, step; @@ -321,18 +325,18 @@ static void tcx_ltp_get_zir_fx( Word32 i; Word16 j, k, L; - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitres, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitres]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitres - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitres]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); FOR( j = 0; j < lpcorder; j++ ) @@ -343,15 +347,15 @@ static void tcx_ltp_get_zir_fx( move16(); FOR( i = 0; i < L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, pitres ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k = k + pitres; } /* s2 *= ALPHA; buf[j] = ( synth[j] - gain * s2 ) - ( synth_ltp[j] - gain * s ); */ - i = L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ); - buf[j] = L_add_sat( L_sub_sat( synth[j], synth_ltp[j] ), Mpy_32_16_1( i, gain ) ); + i = L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ); /* Qx */ + buf[j] = L_add_sat( L_sub_sat( synth[j], synth_ltp[j] ), Mpy_32_16_1( i, gain ) ); /* Qx */ move16(); @@ -365,13 +369,13 @@ static void tcx_ltp_get_zir_fx( E_UTIL_synthesis_fx( 0, A, zir, zir, length, buf, 0, lpcorder ); - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); /* step = 1.f/(float)(length/2); */ step = shl( 4, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -381,19 +385,19 @@ static void tcx_ltp_get_zir_fx( FOR( j = shr( length, 1 ); j < length; j++ ) { - zir[j] = Mpy_32_16_r( zir[j], alpha ); + zir[j] = Mpy_32_16_r( zir[j], alpha ); /* Qx */ move32(); alpha = sub( alpha, step ); } } void predict_signal( - const Word16 excI[], /* i : input excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max, /* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ + const Word16 excI[], /* i : input excitation buffer Qx*/ + Word16 excO[], /* o : output excitation buffer Qx*/ + const Word16 T0, /* i : integer pitch lag Q0*/ + Word16 frac, /* i : fraction of lag Q0*/ + const Word16 frac_max, /* i : max fraction Q0*/ + const Word16 L_subfr /* i : subframe size Q0*/ ) { Word16 j; @@ -412,17 +416,17 @@ void predict_signal( x0--; } - win = &inter4_2tcx2[frac][0]; + win = &inter4_2tcx2[frac][0]; /* Q15 */ if ( EQ_16( frac_max, 6 ) ) - win = &inter6_2tcx2[frac][0]; + win = &inter6_2tcx2[frac][0]; /* Q15 */ FOR( j = 0; j < L_subfr; j++ ) { #ifdef BASOP_NOGLOB - s = L_mult_o( win[0], x0[0], &Overflow ); - s = L_mac_o( s, win[1], x0[1], &Overflow ); - s = L_mac_o( s, win[2], x0[2], &Overflow ); - excO[j] = mac_ro( s, win[3], x0[3], &Overflow ); + s = L_mult_o( win[0], x0[0], &Overflow ); /* Qx + 16 */ + s = L_mac_o( s, win[1], x0[1], &Overflow ); /* Qx + 16 */ + s = L_mac_o( s, win[2], x0[2], &Overflow ); /* Qx + 16 */ + excO[j] = mac_ro( s, win[3], x0[3], &Overflow ); /* Qx + 16 */ #else s = L_mult( win[0], x0[0] ); s = L_mac( s, win[1], x0[1] ); @@ -436,16 +440,17 @@ void predict_signal( } static void tcx_ltp_synth_filter( - Word16 *synth_ltp, - Word16 *synth, - Word16 length, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 pitch_res, - Word16 *zir, /* can be NULL */ - Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out */ - Word16 filtIdx ) + Word16 *synth_ltp, /* Qx */ + Word16 *synth, /* Qx */ + Word16 length, /* Q0 */ + Word16 pitch_int, /* Q0 */ + Word16 pitch_fr, /* Q0 */ + Word16 gain, /* Q15 */ + Word16 pitch_res, /* Q0 */ + Word16 *zir, /* can be NULL */ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ + Word16 filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -458,19 +463,19 @@ static void tcx_ltp_synth_filter( IF( gain > 0 ) { - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); alpha = 0; @@ -479,7 +484,7 @@ static void tcx_ltp_synth_filter( { if ( fade < 0 ) { - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); } @@ -487,7 +492,7 @@ static void tcx_ltp_synth_filter( step = shl( 2, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -508,13 +513,13 @@ static void tcx_ltp_synth_filter( FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ #else s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add( k, pitch_res ); + k = k + pitch_res; } /* s2 *= ALPHA; @@ -522,18 +527,18 @@ static void tcx_ltp_synth_filter( zir: synth_ltp[j] = synth[j] - gain * s2 + gain * s - zir[j]; fade-in/out: synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; */ #ifdef BASOP_NOGLOB - i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); + i = sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ); /* Qx */ #else i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); #endif - k = mult_r( gain, i ); + k = mult_r( gain, i ); /* Qx */ if ( fade != 0 ) - k = mult_r( k, alpha ); + k = mult_r( k, alpha ); /* Qx */ #ifdef BASOP_NOGLOB - k = add_sat( synth[j], k ); + k = add_sat( synth[j], k ); /* Qx */ if ( zir != NULL ) { - k = sub_sat( k, zir[j] ); + k = sub_sat( k, zir[j] ); /* Qx */ } #else k = add( synth[j], k ); @@ -541,7 +546,7 @@ static void tcx_ltp_synth_filter( k = sub( k, zir[j] ); #endif - synth_ltp[j] = k; + synth_ltp[j] = k; /* Qx */ move16(); BASOP_SATURATE_WARNING_OFF_EVS; @@ -564,21 +569,22 @@ static void tcx_ltp_synth_filter( } ELSE { - Copy( synth, synth_ltp, length ); + Copy( synth, synth_ltp, length ); /* Qx */ } } static void tcx_ltp_synth_filter32( - Word32 *synth_ltp, - Word32 *synth, - Word16 length, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 pitch_res, - Word32 *zir, /* can be NULL */ - Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out */ - Word16 filtIdx ) + Word32 *synth_ltp, /* Qx */ + Word32 *synth, /* Qx */ + Word16 length, /* Q0 */ + Word16 pitch_int, /* Q0 */ + Word16 pitch_fr, /* Q0 */ + Word16 gain, /* Q15 */ + Word16 pitch_res, /* Q0 */ + Word32 *zir, /* can be NULL Qx*/ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ + Word16 filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -591,19 +597,19 @@ static void tcx_ltp_synth_filter32( IF( gain > 0 ) { - x0 = &synth_ltp[-pitch_int]; + x0 = &synth_ltp[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = synth; + y0 = synth; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); alpha = 0; @@ -612,7 +618,7 @@ static void tcx_ltp_synth_filter32( { if ( fade < 0 ) { - alpha = 0x7FFF; + alpha = 0x7FFF; /* 1 in Q15 */ move16(); } @@ -620,7 +626,7 @@ static void tcx_ltp_synth_filter32( step = shl( 2, norm_s( length ) ); if ( s_and( length, sub( length, 1 ) ) != 0 ) { - step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); + step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); /* Q15 */ } if ( EQ_16( length, 240 ) ) { @@ -641,13 +647,13 @@ static void tcx_ltp_synth_filter32( FOR( i = 0; i < L; i++ ) { #ifdef BASOP_NOGLOB - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ #else s = L_mac( L_mac( s, w0[k], x0[i] ), w1[k], x1[-i] ); s2 = L_mac( L_mac( s2, v0[k], y0[i] ), v1[k], y1[-i] ); #endif - k = add( k, pitch_res ); + k = k + pitch_res; } /* s2 *= ALPHA; @@ -655,18 +661,18 @@ static void tcx_ltp_synth_filter32( zir: synth_ltp[j] = synth[j] - gain * s2 + gain * s - zir[j]; fade-in/out: synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; */ #ifdef BASOP_NOGLOB - L_tmp = L_sub_sat( s, Mpy_32_16_r( s2, ALPHA ) ); + L_tmp = L_sub_sat( s, Mpy_32_16_r( s2, ALPHA ) ); /* Qx */ #else i = sub( round_fx( s ), mult_r( round_fx( s2 ), ALPHA ) ); #endif - L_tmp2 = Mpy_32_16_r( L_tmp, gain ); + L_tmp2 = Mpy_32_16_r( L_tmp, gain ); /* Qx */ IF( fade != 0 ) - L_tmp2 = Mpy_32_16_r( L_tmp2, alpha ); + L_tmp2 = Mpy_32_16_r( L_tmp2, alpha ); /* Qx */ #ifdef BASOP_NOGLOB - L_tmp2 = L_add_sat( synth[j], L_tmp2 ); + L_tmp2 = L_add_sat( synth[j], L_tmp2 ); /* Qx */ if ( zir != NULL ) { - L_tmp2 = L_sub_sat( L_tmp2, zir[j] ); + L_tmp2 = L_sub_sat( L_tmp2, zir[j] ); /* Qx */ } #else L_tmp2 = add( synth[j], L_tmp2 ); @@ -674,7 +680,7 @@ static void tcx_ltp_synth_filter32( L_tmp2 = sub( L_tmp2, zir[j] ); #endif - synth_ltp[j] = L_tmp2; + synth_ltp[j] = L_tmp2; /* Qx */ move16(); BASOP_SATURATE_WARNING_OFF_EVS; @@ -697,19 +703,20 @@ static void tcx_ltp_synth_filter32( } ELSE { - Copy32( synth, synth_ltp, length ); + Copy32( synth, synth_ltp, length ); /* Qx */ } } static void tcx_ltp_synth_filter_10( - Word16 *out, - Word16 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word16 *out, /* Qx */ + Word16 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -719,22 +726,23 @@ static void tcx_ltp_synth_filter_10( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[-pitch_int]; + x0 = &out[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( GE_16( filtIdx, 0 ) ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = gain; move16(); - gain_step = negate( gain ) / length; + + gain_step = div_s( negate( gain ), length ); /* Q15 */ FOR( j = 0; j < length; j++ ) { @@ -746,12 +754,12 @@ static void tcx_ltp_synth_filter_10( move16(); FOR( i = 0; i < L; i++ ) { - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ k = add( k, pitch_res ); } - out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); + out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); /* Qx */ x0++; x1++; @@ -765,14 +773,15 @@ static void tcx_ltp_synth_filter_10( } static void tcx_ltp_synth_filter_10_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word32 *out, /* Qx */ + Word32 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -782,18 +791,18 @@ static void tcx_ltp_synth_filter_10_fx( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[-pitch_int]; + x0 = &out[-pitch_int]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = gain; move16(); @@ -809,12 +818,12 @@ static void tcx_ltp_synth_filter_10_fx( move16(); FOR( i = 0; i < L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, pitch_res ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k = k + pitch_res; } - out[j] = L_add_sat( in[j], Mpy_32_16_1( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); + out[j] = L_add_sat( in[j], Mpy_32_16_1( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); /* Qx */ move32(); x0++; x1++; @@ -828,14 +837,15 @@ static void tcx_ltp_synth_filter_10_fx( } static void tcx_ltp_synth_filter_01( - Word16 *out, - Word16 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word16 *out, /* Qx */ + Word16 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -845,18 +855,18 @@ static void tcx_ltp_synth_filter_01( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[negate( pitch_int )]; + x0 = &out[-( pitch_int )]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = 0; move16(); @@ -869,13 +879,13 @@ static void tcx_ltp_synth_filter_01( s2 = 0; move16(); - for ( i = 0, k = 0; i < L; i++, k = add( k, pitch_res ) ) + for ( i = 0, k = 0; i < L; i++, k = k + pitch_res ) { - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ } - out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); + out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); /* Qx */ move32(); x0++; @@ -890,14 +900,15 @@ static void tcx_ltp_synth_filter_01( } static void tcx_ltp_synth_filter_01_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 pitch_int, - const Word16 pitch_fr, - const Word16 gain, - const Word16 pitch_res, - const Word16 filtIdx ) + Word32 *out, /* Qx */ + Word32 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 pitch_int, /* Q0 */ + const Word16 pitch_fr, /* Q0 */ + const Word16 gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -907,18 +918,18 @@ static void tcx_ltp_synth_filter_01_fx( Word16 i, j, k, L; Word16 curr_gain, gain_step; - x0 = &out[negate( pitch_int )]; + x0 = &out[-( pitch_int )]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( filtIdx >= 0 ); - w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; - v0 = &tcxLtpFilters[filtIdx].filt[0]; - v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; - L = tcxLtpFilters[filtIdx].length; + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ + L = tcxLtpFilters[filtIdx].length; /* Q0 */ curr_gain = 0; move16(); @@ -934,12 +945,12 @@ static void tcx_ltp_synth_filter_01_fx( move16(); FOR( i = 0; i < L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, pitch_res ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k = k + pitch_res; } - out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); + out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); /* Qx */ move32(); x0++; @@ -965,19 +976,20 @@ static void tcx_ltp_synth_filter_01_fx( ---------------------------------------------------------------------*/ static void tcx_ltp_synth_filter_11_unequal_pitch( - Word16 *out, - Word16 *in, - const Word16 length, - const Word16 cur_pitch_int, - const Word16 cur_pitch_fr, - const Word16 cur_gain, - const Word16 pitch_res, - const Word16 filtIdx, - const Word16 prev_pitch_int, - const Word16 prev_pitch_fr, - const Word16 prev_gain, - const Word16 prev_pitch_res, - const Word16 prev_filtIdx ) + Word16 *out, /* Qx */ + Word16 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 cur_pitch_int, /* Q0 */ + const Word16 cur_pitch_fr, /* Q0 */ + const Word16 cur_gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx, /* Q0 */ + const Word16 prev_pitch_int, /* Q0 */ + const Word16 prev_pitch_fr, /* Q0 */ + const Word16 prev_gain, /* Q15 */ + const Word16 prev_pitch_res, /* Q0 */ + const Word16 prev_filtIdx /* Q0 */ +) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -994,27 +1006,27 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( Word16 *temp_ptr; Word16 gain, gain_step; - x0 = &out[negate( prev_pitch_int )]; + x0 = &out[-( prev_pitch_int )]; x1 = x0 - 1; y0 = in; y1 = y0 - 1; assert( ( filtIdx >= 0 ) && ( prev_filtIdx >= 0 ) ); - w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; - w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; - v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; - v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; + w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; /* Q15 */ - prev_L = tcxLtpFilters[prev_filtIdx].length; + prev_L = tcxLtpFilters[prev_filtIdx].length; /* Q0 */ move16(); - p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; - p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; - q0 = &tcxLtpFilters[filtIdx].filt[0]; - q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; /* Q15 */ + p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; /* Q15 */ + q0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); /* 1. decreasing gain filter. The first filter unit with the parameters associated to the previous interval and scaling towards 0 */ @@ -1032,12 +1044,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( move16(); FOR( i = 0; i < prev_L; i++ ) { - s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); - s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); - k = add( k, prev_pitch_res ); + s = L_mac_sat( L_mac_sat( s, w0[k], x0[i] ), w1[k], x1[-i] ); /* Qx */ + s2 = L_mac_sat( L_mac_sat( s2, v0[k], y0[i] ), v1[k], y1[-i] ); /* Qx */ + k = k + prev_pitch_res; } - out[j] = add_sat( in[j], mult_r_sat( gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); + out[j] = add_sat( in[j], mult_r_sat( gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); /* Qx */ x0++; x1++; @@ -1047,13 +1059,13 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( gain = add( gain, gain_step ); } - Copy( out - L, temp_buf, length + L ); - Copy( in + length, temp_buf + length + L, L ); + Copy( out - L, temp_buf, length + L ); /* Qx */ + Copy( in + length, temp_buf + length + L, L ); /* Qx */ temp_ptr = &temp_buf[0] + L; - m0 = temp_ptr; - m1 = temp_ptr - 1; - l0 = &out[negate( cur_pitch_int )]; + m0 = temp_ptr; /* Qx */ + m1 = temp_ptr - 1; /* Qx */ + l0 = &out[-( cur_pitch_int )]; /* Qx */ l1 = l0 - 1; /* 2. increasing gain filter. The second filter unit with the parameters associated to the current interval and scaling from 0 towards current gain */ @@ -1071,12 +1083,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( move16(); FOR( i = 0; i < L; i++ ) { - s3 = L_mac_sat( L_mac_sat( s3, p0[k], l0[i] ), p1[k], l1[-i] ); - s4 = L_mac_sat( L_mac_sat( s4, q0[k], m0[i] ), q1[k], m1[-i] ); - k = add( k, pitch_res ); + s3 = L_mac_sat( L_mac_sat( s3, p0[k], l0[i] ), p1[k], l1[-i] ); /* Qx */ + s4 = L_mac_sat( L_mac_sat( s4, q0[k], m0[i] ), q1[k], m1[-i] ); /* Qx */ + k = k + pitch_res; } - out[j] = add_sat( *( temp_ptr + j ), mult_r_sat( gain, sub_sat( round_fx_sat( s3 ), mult_r_sat( round_fx_sat( s4 ), ALPHA ) ) ) ); + out[j] = add_sat( *( temp_ptr + j ), mult_r_sat( gain, sub_sat( round_fx_sat( s3 ), mult_r_sat( round_fx_sat( s4 ), ALPHA ) ) ) ); /* Qx */ move32(); l0++; @@ -1091,19 +1103,20 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( } static void tcx_ltp_synth_filter_11_unequal_pitch_fx( - Word32 *out, - Word32 *in, - const Word16 length, - const Word16 cur_pitch_int, - const Word16 cur_pitch_fr, - const Word16 cur_gain, - const Word16 pitch_res, - const Word16 filtIdx, - const Word16 prev_pitch_int, - const Word16 prev_pitch_fr, - const Word16 prev_gain, - const Word16 prev_pitch_res, - const Word16 prev_filtIdx ) + Word32 *out, /* Qx */ + Word32 *in, /* Qx */ + const Word16 length, /* Q0 */ + const Word16 cur_pitch_int, /* Q0 */ + const Word16 cur_pitch_fr, /* Q0 */ + const Word16 cur_gain, /* Q15 */ + const Word16 pitch_res, /* Q0 */ + const Word16 filtIdx, /* Q0 */ + const Word16 prev_pitch_int, /* Q0 */ + const Word16 prev_pitch_fr, /* Q0 */ + const Word16 prev_gain, /* Q15 */ + const Word16 prev_pitch_res, /* Q0 */ + const Word16 prev_filtIdx /* Q0 */ +) { Word32 *x0, *x1; Word32 *y0, *y1; @@ -1120,27 +1133,27 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( Word32 *temp_ptr; Word16 gain, gain_step; - x0 = &out[negate( prev_pitch_int )]; + x0 = &out[-( prev_pitch_int )]; /* Qx */ x1 = x0 - 1; - y0 = in; + y0 = in; /* Qx */ y1 = y0 - 1; assert( GE_16( filtIdx, 0 ) && GE_16( prev_filtIdx, 0 ) ); - w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; - w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; - v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; - v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; + w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; /* Q15 */ + w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; /* Q15 */ + v0 = &tcxLtpFilters[prev_filtIdx].filt[0]; /* Q15 */ + v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; /* Q15 */ - prev_L = tcxLtpFilters[prev_filtIdx].length; + prev_L = tcxLtpFilters[prev_filtIdx].length; /* Q0 */ move16(); - p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; - p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; - q0 = &tcxLtpFilters[filtIdx].filt[0]; - q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; /* Q15 */ + p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; /* Q15 */ + q0 = &tcxLtpFilters[filtIdx].filt[0]; /* Q15 */ + q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; /* Q15 */ - L = tcxLtpFilters[filtIdx].length; + L = tcxLtpFilters[filtIdx].length; /* Q0 */ move16(); /* 1. decreasing gain filter. The first filter unit with the parameters associated to the previous interval and scaling towards 0 */ @@ -1158,12 +1171,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( move16(); FOR( i = 0; i < prev_L; i++ ) { - s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); - s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); - k = add( k, prev_pitch_res ); + s = Madd_32_16_r( Madd_32_16_r( s, x0[i], w0[k] ), x1[-i], w1[k] ); /* Qx */ + s2 = Madd_32_16_r( Madd_32_16_r( s2, y0[i], v0[k] ), y1[-i], v1[k] ); /* Qx */ + k += prev_pitch_res; } - out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), gain ) ); + out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), gain ) ); /* Qx */ move32(); x0++; x1++; @@ -1173,13 +1186,13 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( gain = add( gain, gain_step ); } - Copy32( out - L, temp_buf, length + L ); - Copy32( in + length, temp_buf + length + L, L ); - temp_ptr = &temp_buf[0] + L; + Copy32( out - L, temp_buf, length + L ); /* Qx */ + Copy32( in + length, temp_buf + length + L, L ); /* Qx */ + temp_ptr = &temp_buf[0] + L; /* Qx */ - m0 = temp_ptr; + m0 = temp_ptr; /* Qx */ m1 = temp_ptr - 1; - l0 = &out[negate( cur_pitch_int )]; + l0 = &out[-( cur_pitch_int )]; /* Qx */ l1 = l0 - 1; /* 2. increasing gain filter. The second filter unit with the parameters associated to the current interval and scaling from 0 towards current gain */ @@ -1196,12 +1209,12 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( k = 0; FOR( i = 0; i < L; i++ ) { - s3 = Madd_32_16_r( Madd_32_16_r( s3, l0[i], p0[k] ), l1[-i], p1[k] ); - s4 = Madd_32_16_r( Madd_32_16_r( s4, m0[i], q0[k] ), m1[-i], q1[k] ); + s3 = Madd_32_16_r( Madd_32_16_r( s3, l0[i], p0[k] ), l1[-i], p1[k] ); /* Qx */ + s4 = Madd_32_16_r( Madd_32_16_r( s4, m0[i], q0[k] ), m1[-i], q1[k] ); /* Qx */ k = add( k, pitch_res ); } - out[j] = L_add_sat( *( temp_ptr + j ), Mpy_32_16_r( L_sub_sat( s3, Mpy_32_16_1( s4, ALPHA ) ), gain ) ); + out[j] = L_add_sat( *( temp_ptr + j ), Mpy_32_16_r( L_sub_sat( s3, Mpy_32_16_1( s4, ALPHA ) ), gain ) ); /* Qx */ move32(); l0++; @@ -1216,15 +1229,16 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( } Word16 tcx_ltp_decode_params( - Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - const Word16 pitmin, - const Word16 pitfr1, - const Word16 pitfr2, - const Word16 pitmax, - const Word16 pitres ) + Word16 *ltp_param, /* Q0 */ + Word16 *pitch_int, /* Q0 */ + Word16 *pitch_fr, /* Q0 */ + Word16 *gain, /* Q13 */ + const Word16 pitmin, /* Q0 */ + const Word16 pitfr1, /* Q0 */ + const Word16 pitfr2, /* Q0 */ + const Word16 pitmax, /* Q0 */ + const Word16 pitres /* Q0 */ +) { Word16 tmp, tmp2; @@ -1233,47 +1247,47 @@ Word16 tcx_ltp_decode_params( test(); IF( ltp_param != 0 && ltp_param[0] != 0 ) { - tmp = imult1616( sub( pitfr2, pitmin ), pitres ); + tmp = imult1616( sub( pitfr2, pitmin ), pitres ); /* Q0 */ IF( LT_16( ltp_param[1], tmp ) ) { tmp2 = idiv1616U( ltp_param[1], pitres ); - *pitch_int = add( pitmin, tmp2 ); + *pitch_int = add( pitmin, tmp2 ); /* Q0 */ move16(); - tmp2 = sub( *pitch_int, pitmin ); - *pitch_fr = sub( ltp_param[1], imult1616( tmp2, pitres ) ); + tmp2 = sub( *pitch_int, pitmin ); /* Q0 */ + *pitch_fr = sub( ltp_param[1], imult1616( tmp2, pitres ) ); /* Q0 */ move16(); } ELSE { - tmp2 = imult1616( sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ); + tmp2 = imult1616( sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ); /* Q0 */ IF( LT_16( ltp_param[1], add( tmp, tmp2 ) ) ) { - tmp2 = idiv1616U( sub( ltp_param[1], tmp ), shr( pitres, 1 ) ); + tmp2 = idiv1616U( sub( ltp_param[1], tmp ), shr( pitres, 1 ) ); /* Q0 */ - *pitch_int = add( pitfr2, tmp2 ); + *pitch_int = add( pitfr2, tmp2 ); /* Q0 */ move16(); - *pitch_fr = shl( sub( sub( ltp_param[1], tmp ), imult1616( tmp2, shr( pitres, 1 ) ) ), 1 ); + *pitch_fr = shl( sub( sub( ltp_param[1], tmp ), imult1616( tmp2, shr( pitres, 1 ) ) ), 1 ); /* Q0 */ move16(); } ELSE { - *pitch_int = sub( add( ltp_param[1], pitfr1 ), add( tmp, tmp2 ) ); + *pitch_int = sub( add( ltp_param[1], pitfr1 ), add( tmp, tmp2 ) ); /* Q0 */ move16(); *pitch_fr = 0; move16(); } } - *gain = imult1616( add( ltp_param[2], 1 ), 0x1400 ); + *gain = imult1616( add( ltp_param[2], 1 ), 0x1400 /* 0.625 in Q13 */ ); /* Q13 */ move16(); IF( LT_16( *pitch_int, PIT_MIN_SHORTER ) ) { /*pitch out of range due to bit error */ - *pitch_int = PIT_MIN_SHORTER; + *pitch_int = PIT_MIN_SHORTER; /* Q0 */ move16(); return 1; } @@ -1281,14 +1295,14 @@ Word16 tcx_ltp_decode_params( IF( GT_16( *pitch_int, PIT_MAX_MAX ) ) { /*pitch out of range due to bit error */ - *pitch_int = PIT_MAX_MAX; + *pitch_int = PIT_MAX_MAX; /* Q0 */ move16(); return 1; } } ELSE { - *pitch_int = pitmax; + *pitch_int = pitmax; /* Q0 */ move16(); *pitch_fr = 0; move16(); @@ -1302,11 +1316,12 @@ Word16 tcx_ltp_decode_params( void tcx_ltp_post( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf ) + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word16 *sig, /* Qx */ + Word16 *tcx_buf /* Qx */ +) { Word16 tmp, L_transition, lpcorder, filtIdx; Word16 gain, gain2; @@ -1318,17 +1333,17 @@ void tcx_ltp_post( Word16 tcx_buf_len, bfi, L_frame_core, SideInfoOnly; Word32 total_brate; - total_brate = st->total_brate; + total_brate = st->total_brate; /* Q0 */ move32(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); + total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); /* Q0 */ move32(); } filtIdx = 0; /* just to avoid comilation warnings */ move16(); - tcx_buf_len = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); + tcx_buf_len = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */ SideInfoOnly = 0; move16(); if ( GE_32( total_brate, HQ_96k ) ) @@ -1337,12 +1352,12 @@ void tcx_ltp_post( move16(); } - L_frame_core = st->L_frame; + L_frame_core = st->L_frame; /* Q0 */ move16(); if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - L_frame_core = L_FRAME; + L_frame_core = L_FRAME; /* Q0 */ move16(); } @@ -1356,15 +1371,15 @@ void tcx_ltp_post( move16(); gain = 0; move16(); - L_frame_core = st->L_frame_past; + L_frame_core = st->L_frame_past; /* Q0 */ move16(); } ELSE { - bfi = st->bfi; - pitch_int = hTcxLtpDec->tcxltp_pitch_int; - pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; - gain = hTcxLtpDec->tcxltp_gain; + bfi = st->bfi; /* Q0 */ + pitch_int = hTcxLtpDec->tcxltp_pitch_int; /* Q0 */ + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; /* Q0 */ + gain = hTcxLtpDec->tcxltp_gain; /* Q15 */ move16(); move16(); move16(); @@ -1374,23 +1389,23 @@ void tcx_ltp_post( /* Parameters */ - L_transition = shr( output_frame, 2 ); + L_transition = shr( output_frame, 2 ); /* Q0 */ lpcorder = TCXLTP_LTP_ORDER; move16(); /* Input buffer */ sig_in = buf_in + tcx_buf_len; - Copy( hTcxLtpDec->tcxltp_mem_in, buf_in, tcx_buf_len ); - Copy( sig, buf_in + tcx_buf_len, output_frame ); + Copy( hTcxLtpDec->tcxltp_mem_in, buf_in, tcx_buf_len ); /* exp(exp_tcxltp_mem_in) */ + Copy( sig, buf_in + tcx_buf_len, output_frame ); /* Qx */ IF( GT_16( core, ACELP_CORE ) ) { - Copy( tcx_buf, sig_in + output_frame, tcx_buf_len ); + Copy( tcx_buf, sig_in + output_frame, tcx_buf_len ); /* Qx */ } - Copy( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in, tcx_buf_len ); + Copy( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in, tcx_buf_len ); /* Qx */ /* Output buffer */ sig_out = buf_out + output_frame; - Copy( hTcxLtpDec->tcxltp_mem_out, buf_out, output_frame ); + Copy( hTcxLtpDec->tcxltp_mem_out, buf_out, output_frame ); /* exp(exp_tcxltp_mem_out) */ /* TCX-LTP parameters: integer pitch, fractional pitch, gain */ test(); @@ -1417,30 +1432,30 @@ void tcx_ltp_post( tmp32 = L_mult0( add( imult1616( pitch_int, st->pit_res_max ), pitch_fr ), tmp ); /* Q13 */ tmp = round_fx( L_shl( tmp32, 3 ) ); /* Q0 */ pitch_int = idiv1616U( tmp, st->pit_res_max ); - pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); + pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); /* Q0 */ } test(); test(); IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, L_FRAME16k ) ) { - gain = mult_r( gain, 10486 /*0.32f Q15*/ ); + gain = mult_r( gain, 10486 /*0.32f Q15*/ ); /* Q15 */ } ELSE IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, 512 ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE IF( GT_16( st->element_mode, IVAS_SCE ) && GE_32( total_brate, IVAS_96k ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE @@ -1578,7 +1593,7 @@ void tcx_ltp_post( IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* The filtering is deactivated, just copy input to the output */ - Copy( sig_in + delay, sig_out + delay, L_transition ); + Copy( sig_in + delay, sig_out + delay, L_transition ); /* Qx */ } ELSE IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0 ) { @@ -1609,7 +1624,7 @@ void tcx_ltp_post( test(); IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { - Copy( sig_in + delay, sig_out + delay, L_transition ); + Copy( sig_in + delay, sig_out + delay, L_transition ); /* Qx */ } ELSE IF( hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { @@ -1645,7 +1660,7 @@ void tcx_ltp_post( /* copy to output */ - Copy( sig_out, sig, output_frame ); + Copy( sig_out, sig, output_frame ); /* Qx */ /* Update */ hTcxLtpDec->tcxltp_pitch_int_post_prev = pitch_int; @@ -1658,18 +1673,18 @@ void tcx_ltp_post( move16(); st->pit_res_max_past = st->pit_res_max; move16(); - Copy( sig_out, hTcxLtpDec->tcxltp_mem_out, output_frame ); + Copy( sig_out, hTcxLtpDec->tcxltp_mem_out, output_frame ); /* Qx */ } void tcx_ltp_post32( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, - Word16 core, - Word16 output_frame, - Word16 delay, - Word32 *sig, - Word32 *tcx_buf, + Word16 core, /* Q0 */ + Word16 output_frame, /* Q0 */ + Word16 delay, /* Q0 */ + Word32 *sig, /* sig_q */ + Word32 *tcx_buf, /* sig_q */ Word16 sig_q ) { Word16 tmp, L_transition, lpcorder, filtIdx; @@ -1692,7 +1707,7 @@ void tcx_ltp_post32( filtIdx = 0; /* just to avoid comilation warnings */ move16(); - tcx_buf_len = NS2SA_FX2( st->output_Fs, TCXLTP_DELAY_NS ); + tcx_buf_len = NS2SA_FX2( st->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */ move16(); SideInfoOnly = 0; move16(); @@ -1702,7 +1717,7 @@ void tcx_ltp_post32( move16(); } - L_frame_core = st->L_frame; + L_frame_core = st->L_frame; /* Q0 */ move16(); if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -1717,7 +1732,7 @@ void tcx_ltp_post32( pitch_int = 0; pitch_fr = 0; gain = 0; - L_frame_core = st->L_frame_past; + L_frame_core = st->L_frame_past; /* Q0 */ move16(); move16(); move16(); @@ -1725,10 +1740,10 @@ void tcx_ltp_post32( } ELSE { - bfi = st->bfi; - pitch_int = hTcxLtpDec->tcxltp_pitch_int; - pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; - gain = hTcxLtpDec->tcxltp_gain; + bfi = st->bfi; /* Q0 */ + pitch_int = hTcxLtpDec->tcxltp_pitch_int; /* Q0 */ + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; /* Q0 */ + gain = hTcxLtpDec->tcxltp_gain; /* Q15 */ move16(); move16(); move16(); @@ -1738,25 +1753,25 @@ void tcx_ltp_post32( /* Parameters */ - L_transition = shr( output_frame, 2 ); + L_transition = shr( output_frame, 2 ); /* Q0 */ lpcorder = TCXLTP_LTP_ORDER; move16(); /* Input buffer */ sig_in = buf_in + tcx_buf_len; - Copy32( hTcxLtpDec->tcxltp_mem_in_32, buf_in, tcx_buf_len ); + Copy32( hTcxLtpDec->tcxltp_mem_in_32, buf_in, tcx_buf_len ); /* exp(exp_tcxltp_mem_in)*/ scale_sig32( buf_in, tcx_buf_len, sub( hTcxLtpDec->exp_tcxltp_mem_in, sub( 31, sig_q ) ) ); - Copy32( sig, buf_in + tcx_buf_len, output_frame ); + Copy32( sig, buf_in + tcx_buf_len, output_frame ); /* sig_q */ IF( core > ACELP_CORE ) { - Copy32( tcx_buf, sig_in + output_frame, tcx_buf_len ); + Copy32( tcx_buf, sig_in + output_frame, tcx_buf_len ); /* sig_q */ } - Copy32( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in_32, tcx_buf_len ); + Copy32( sig + output_frame - tcx_buf_len, hTcxLtpDec->tcxltp_mem_in_32, tcx_buf_len ); /* sig_q */ hTcxLtpDec->exp_tcxltp_mem_in = sub( 31, sig_q ); move16(); /* Output buffer */ sig_out = buf_out + output_frame; - Copy32( hTcxLtpDec->tcxltp_mem_out_32, buf_out, output_frame ); + Copy32( hTcxLtpDec->tcxltp_mem_out_32, buf_out, output_frame ); /* exp(exp_tcxltp_mem_out) */ scale_sig32( buf_out, output_frame, sub( hTcxLtpDec->exp_tcxltp_mem_out, sub( 31, sig_q ) ) ); /* TCX-LTP parameters: integer pitch, fractional pitch, gain */ @@ -1781,7 +1796,7 @@ void tcx_ltp_post32( tmp32 = L_mult0( add( imult1616( pitch_int, st->pit_res_max ), pitch_fr ), tmp ); /* Q13 */ tmp = round_fx( L_shl( tmp32, 3 ) ); /* Q0 */ pitch_int = idiv1616U( tmp, st->pit_res_max ); - pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); + pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); /* Q0 */ } IF( st->element_mode == EVS_MONO ) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ { @@ -1789,24 +1804,24 @@ void tcx_ltp_post32( test(); IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, L_FRAME16k ) ) { - gain = mult_r( gain, 10486 /*0.32f Q15*/ ); + gain = mult_r( gain, 10486 /*0.32f Q15*/ ); /* Q15 */ } ELSE IF( EQ_32( total_brate, 48000 ) && EQ_16( L_frame_core, 512 ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE IF( GT_16( st->element_mode, IVAS_SCE ) && GE_32( total_brate, IVAS_96k ) ) { - gain = mult_r( gain, 13107 /*0.40f Q15*/ ); + gain = mult_r( gain, 13107 /*0.40f Q15*/ ); /* Q15 */ } ELSE { - gain = mult_r( gain, 20972 /*0.64f Q15*/ ); + gain = mult_r( gain, 20972 /*0.64f Q15*/ ); /* Q15 */ } } ELSE @@ -1815,11 +1830,11 @@ void tcx_ltp_post32( * PLC: LTP and bad frame (concealment) */ IF( st->pit_res_max == st->pit_res_max_past ) /* ensure consistent core SR to previous frame; otherwise, set gain to 0 */ { - pitch_int = hTcxLtpDec->tcxltp_pitch_int_post_prev; + pitch_int = hTcxLtpDec->tcxltp_pitch_int_post_prev; /* Q0 */ move16(); - pitch_fr = hTcxLtpDec->tcxltp_pitch_fr_post_prev; + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr_post_prev; /* Q0 */ move16(); - gain = shl( mult_r( hTcxLtpDec->tcxltp_gain_post_prev, st->hTcxDec->damping ), 1 ); + gain = shl( mult_r( hTcxLtpDec->tcxltp_gain_post_prev, st->hTcxDec->damping ), 1 ); /* Q15 */ } ELSE { @@ -1940,7 +1955,7 @@ void tcx_ltp_post32( IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* The filtering is deactivated, just copy input to the output */ - Copy32( sig_in + delay, sig_out + delay, L_transition ); + Copy32( sig_in + delay, sig_out + delay, L_transition ); /* sig_q */ } ELSE IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0 ) { @@ -1970,7 +1985,7 @@ void tcx_ltp_post32( test(); IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { - Copy32( sig_in + delay, sig_out + delay, L_transition ); + Copy32( sig_in + delay, sig_out + delay, L_transition ); /* sig_q */ } ELSE IF( hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { @@ -2006,7 +2021,7 @@ void tcx_ltp_post32( /* copy to output */ - Copy32( sig_out, sig, output_frame ); + Copy32( sig_out, sig, output_frame ); /* sig_q */ /* Update */ hTcxLtpDec->tcxltp_pitch_int_post_prev = pitch_int; @@ -2018,7 +2033,7 @@ void tcx_ltp_post32( hTcxLtpDec->tcxltp_filt_idx_prev = filtIdx; move16(); st->pit_res_max_past = st->pit_res_max; - Copy32( sig_out, hTcxLtpDec->tcxltp_mem_out_32, output_frame ); + Copy32( sig_out, hTcxLtpDec->tcxltp_mem_out_32, output_frame ); /* sig_q */ hTcxLtpDec->exp_tcxltp_mem_out = sub( 31, sig_q ); move16(); } diff --git a/lib_com/tcx_mdct_window.c b/lib_com/tcx_mdct_window.c index adda4b8d2c10d5b0aebd36a7aa83476e2d3cd259..c466a8271ba3aba1a70b70ba1cf9137c509e87a4 100644 --- a/lib_com/tcx_mdct_window.c +++ b/lib_com/tcx_mdct_window.c @@ -109,21 +109,22 @@ void mdct_window_sine_flt( void mdct_window_sine_IVAS_updated( - PWord16 *window, - const Word32 Fs, - const Word16 n, - const Word16 window_type, - const Word16 element_mode ) + PWord16 *window, /* Qx */ + const Word32 Fs, /* Q0 */ + const Word16 n, /* Q0 */ + const Word16 window_type, /* Q0 */ + const Word16 element_mode /* Q0 */ +) { - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { const PWord16 *table; table = getSineWindowTable( n ); - FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) + FOR( Word32 i = 0; i < n / 2; i++ ) { - window[i].v.re = table[i].v.re; + window[i].v.re = table[i].v.re; /* Qx */ move16(); - window[i].v.im = table[i].v.im; + window[i].v.im = table[i].v.im; /* Qx */ move16(); } // PMT("getSineWindowTable needs to be updated for IVAS") @@ -138,17 +139,17 @@ void mdct_window_sine_IVAS_updated( SWITCH( window_type ) { case FULL_OVERLAP: - window_table = tcx_mdct_window_48_fx; + window_table = tcx_mdct_window_48_fx; /* Q15 */ buf_in_size = 420; move16(); BREAK; case HALF_OVERLAP: - window_table = tcx_mdct_window_half_48_fx; + window_table = tcx_mdct_window_half_48_fx; /* Q15 */ buf_in_size = 180; BREAK; case TRANSITION_OVERLAP: case MIN_OVERLAP: - window_table = tcx_mdct_window_trans_48_fx; + window_table = tcx_mdct_window_trans_48_fx; /* Q15 */ buf_in_size = 60; move16(); BREAK; @@ -160,25 +161,28 @@ void mdct_window_sine_IVAS_updated( IF( EQ_32( Fs, 48000 ) ) { - Copy( window_table, temp, n ); + Copy( window_table, temp, n ); /* Q15 */ } ELSE { lerp( window_table, temp, n, buf_in_size ); } - FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) + FOR( Word32 i = 0; i < n / 2; i++ ) { - window[i].v.re = temp[n - 1 - i]; + window[i].v.re = temp[n - 1 - i]; /* Qx */ move16(); - window[i].v.im = temp[i]; + window[i].v.im = temp[i]; /* Qx */ move16(); } } } ////Use mdct_window_sine_IVAS_updated for IVAS (EVS path covered as well) -void mdct_window_sine( PWord16 *window, Word16 n ) +void mdct_window_sine( + PWord16 *window, /* Qx */ + Word16 n /* Q0 */ +) { #ifdef IVAS_CODE if ( element_mode == EVS_MONO ) @@ -186,11 +190,11 @@ void mdct_window_sine( PWord16 *window, Word16 n ) { const PWord16 *table; table = getSineWindowTable( n ); - FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) + FOR( Word32 i = 0; i < n / 2; i++ ) { - window[i].v.re = table[i].v.re; + window[i].v.re = table[i].v.re; /* Qx */ move16(); - window[i].v.im = table[i].v.im; + window[i].v.im = table[i].v.im; /* Qx */ move16(); } // PMT("getSineWindowTable needs to be updated for IVAS") @@ -388,10 +392,11 @@ void mdct_window_aldo_flt( void mdct_window_aldo( - Word16 *window1, - PWord16 *window1_trunc, - PWord16 *window2, - Word16 n ) + Word16 *window1, /* Q15 */ + PWord16 *window1_trunc, /* Q15 */ + PWord16 *window2, /* Q15 */ + Word16 n /* Q0 */ +) { Word16 i, n0, n1, n2, d, tmp; const Word16 *p1, *p2; @@ -400,36 +405,36 @@ void mdct_window_aldo( SWITCH( n ) { case 320 / 2: - p1 = window_48kHz_fx + 2; - p2 = window_48kHz_fx + 1110 - 3; + p1 = window_48kHz_fx + 2; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 3; /* Q15 */ d = 6; move16(); BREAK; case 512 / 2: - p1 = window_256kHz; - p2 = window_256kHz + 592 - 1; + p1 = window_256kHz; /* Q15 */ + p2 = window_256kHz + 592 - 1; /* Q15 */ d = 2; BREAK; case 640 / 2: - p1 = window_48kHz_fx + 1; - p2 = window_48kHz_fx + 1110 - 2; + p1 = window_48kHz_fx + 1; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 2; /* Q15 */ d = 3; move16(); BREAK; case 1024 / 2: - p1 = window_256kHz; - p2 = window_256kHz + 592 - 1; + p1 = window_256kHz; /* Q15 */ + p2 = window_256kHz + 592 - 1; /* Q15 */ d = 1; move16(); BREAK; case 1280 / 2: - p1 = window_48kHz_fx + 1; - p2 = window_48kHz_fx + 1110 - 2; + p1 = window_48kHz_fx + 1; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 2; /* Q15 */ d = 3; BREAK; case 1920 / 2: - p1 = window_48kHz_fx; - p2 = window_48kHz_fx + 1110 - 1; + p1 = window_48kHz_fx; /* Q15 */ + p2 = window_48kHz_fx + 1110 - 1; /* Q15 */ d = 1; move16(); BREAK; @@ -448,7 +453,7 @@ void mdct_window_aldo( { FOR( i = 0; i < n0; i++ ) { - *window1 = *p1; + *window1 = *p1; /* Q15 */ move16(); window1++; p1 += d; @@ -457,7 +462,7 @@ void mdct_window_aldo( tmp = shr( n, 1 ); FOR( ; i < tmp; i++ ) { - window1_trunc->v.im = *p1; + window1_trunc->v.im = *p1; /* Q15 */ move16(); window1_trunc++; p1 += d; @@ -470,7 +475,7 @@ void mdct_window_aldo( FOR( ; i < n1; i++ ) { window1_trunc--; - window1_trunc->v.re = *p1; + window1_trunc->v.re = *p1; /* Q15 */ move16(); p1 += d; } @@ -481,12 +486,12 @@ void mdct_window_aldo( FOR( i = 0; i < n0; i += 2 ) { - *window1 = *p1; + *window1 = *p1; /* Q15 */ move16(); window1++; p1 += d; - *window1 = *pi; + *window1 = *pi; /* Q15 */ move16(); window1++; pi++; @@ -495,12 +500,12 @@ void mdct_window_aldo( tmp = shr( n, 1 ); FOR( ; i < tmp; i += 2 ) { - window1_trunc->v.im = *p1; + window1_trunc->v.im = *p1; /* Q15 */ move16(); window1_trunc++; p1 += d; - window1_trunc->v.im = *pi; + window1_trunc->v.im = *pi; /* Q15 */ move16(); window1_trunc++; pi++; @@ -509,12 +514,12 @@ void mdct_window_aldo( FOR( ; i < n1; i += 2 ) { window1_trunc--; - window1_trunc->v.re = *pi; + window1_trunc->v.re = *pi; /* Q15 */ move16(); pi++; window1_trunc--; - window1_trunc->v.re = *p1; + window1_trunc->v.re = *p1; /* Q15 */ move16(); p1 += d; } @@ -526,7 +531,7 @@ void mdct_window_aldo( tmp = shr( n2, 1 ); FOR( i = 0; i < tmp; i++ ) { - window2->v.im = *p2; + window2->v.im = *p2; /* Q15 */ move16(); window2++; p2 -= d; @@ -539,7 +544,7 @@ void mdct_window_aldo( FOR( ; i < n2; i++ ) { window2--; - window2->v.re = *p2; + window2->v.re = *p2; /* Q15 */ move16(); p2 -= d; } @@ -551,12 +556,12 @@ void mdct_window_aldo( tmp = shr( n2, 1 ); FOR( i = 0; i < tmp; i += 2 ) { - window2->v.im = *p2; + window2->v.im = *p2; /* Q15 */ move16(); window2++; p2 -= d; - window2->v.im = *pi; + window2->v.im = *pi; /* Q15 */ move16(); window2++; pi--; @@ -565,12 +570,12 @@ void mdct_window_aldo( FOR( ; i < n2; i += 2 ) { window2--; - window2->v.re = *pi; + window2->v.re = *pi; /* Q15 */ move16(); pi--; window2--; - window2->v.re = *p2; + window2->v.re = *p2; /* Q15 */ move16(); p2 -= d; } diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index eb44da8c98e245a8b2925dfd1ef72c446865bfac..d0a5d1d1248935e5611bbf096141d0cab86168cb 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -18,7 +18,7 @@ ivas_error evs_dec_fx( Decoder_State *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal */ + Word16 output_sp[], /* o : output synthesis signal Q0*/ frameMode_fx frameMode /* i : Decoder frame mode */ ) { @@ -99,7 +99,7 @@ ivas_error evs_dec_fx( st_fx->idchan = 0; move16(); - st_fx->element_brate = st_fx->total_brate; + st_fx->element_brate = st_fx->total_brate; /*Q0*/ move32(); st_fx->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st_fx->total_brate, 0, 0, -1, -1 ); @@ -118,7 +118,7 @@ ivas_error evs_dec_fx( move16(); } - output_frame = st_fx->output_frame_fx; + output_frame = st_fx->output_frame_fx; /*Q0*/ move16(); core_switching_flag = 0; @@ -138,9 +138,9 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - hq_core_type = hHQ_core->last_hq_core_type; + hq_core_type = hHQ_core->last_hq_core_type; /*Q0*/ move16(); - st_fx->coder_type = st_fx->last_coder_type; + st_fx->coder_type = st_fx->last_coder_type; /*Q0*/ move16(); } ELSE @@ -165,7 +165,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { #ifdef BASOP_NOGLOB - hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); + hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ #else hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif @@ -174,7 +174,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < st_fx->L_frame; i++ ) { #ifdef BASOP_NOGLOB - hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); + hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ #else hHQ_core->old_out_LB_fx[i] = shl( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif @@ -190,11 +190,11 @@ ivas_error evs_dec_fx( f = L_deposit_l( hTcxDec->conceal_eof_gain ); /*Q14*/ s = norm_l( f ); s = sub( 16, s ); - tmp1 = extract_l( L_shr_r( f, s ) ); + tmp1 = extract_l( L_shr_r( f, s ) ); /*Q14 - s*/ FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); + hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); /*hTcxDec->Q_syn_Overl*/ #else hTcxDec->syn_OverlFB[i] = shl( mult( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); #endif @@ -202,11 +202,11 @@ ivas_error evs_dec_fx( } s = norm_l( f ); s = sub( 16, s ); - tmp1 = extract_l( L_shr_r( f, s ) ); + tmp1 = extract_l( L_shr_r( f, s ) ); /*Q14 - s*/ FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); + hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); /*hTcxDec->Q_syn_Overl*/ #else hTcxDec->syn_Overl[i] = shl( mult( tmp1, hTcxDec->syn_Overl[i] ), s ); #endif @@ -241,7 +241,7 @@ ivas_error evs_dec_fx( IF( NE_16( frameMode, FRAMEMODE_MISSING ) ) /* frame mode normal or future frame */ { getPartialCopyInfo( st_fx, &st_fx->coder_type, &sharpFlag ); - frameMode = st_fx->bfi; + frameMode = st_fx->bfi; /*Q0*/ move16(); } @@ -251,7 +251,7 @@ ivas_error evs_dec_fx( /* the partial copy is a RF FRAME_NO_DATA frame and should follow the concealment path*/ st_fx->bfi = 1; move16(); - st_fx->codec_mode = st_fx->last_codec_mode; + st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/ move16(); frameMode = FRAMEMODE_MISSING; move16(); @@ -268,7 +268,7 @@ ivas_error evs_dec_fx( { st_fx->bfi = 1; move16(); - st_fx->codec_mode = st_fx->last_codec_mode; + st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/ move16(); frameMode = FRAMEMODE_MISSING; move16(); @@ -287,7 +287,7 @@ ivas_error evs_dec_fx( { st_fx->bfi = 1; move16(); - st_fx->codec_mode = st_fx->last_codec_mode; + st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/ move16(); frameMode = FRAMEMODE_MISSING; move16(); @@ -311,14 +311,14 @@ ivas_error evs_dec_fx( decision_matrix_dec_fx( st_fx, &sharpFlag, &hq_core_type, &core_switching_flag ); IF( NE_16( st_fx->bfi, 1 ) ) { - st_fx->sr_core = i_mult( st_fx->L_frame, FRAMES_PER_SEC ); - st_fx->fscale_old = st_fx->fscale; + st_fx->sr_core = i_mult( st_fx->L_frame, FRAMES_PER_SEC ); /*Q0*/ + st_fx->fscale_old = st_fx->fscale; /*Q0*/ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /*Q0*/ } ELSE { - frameMode = FRAMEMODE_MISSING; + frameMode = FRAMEMODE_MISSING; /*Q0*/ move16(); } } @@ -423,7 +423,7 @@ ivas_error evs_dec_fx( #ifdef ADD_IVAS_BWE 0, #endif - output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); + output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); /*Q0*/ } /*---------------------------------------------------------------------* @@ -474,11 +474,11 @@ ivas_error evs_dec_fx( #ifdef ADD_IVAS_BWE 0, #endif - output_frame, &Qpostd ); + output_frame, &Qpostd ); /*Q0*/ } ELSE IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { - hb_synth_fx_exp = swb_bwe_dec_hr_fx( st_fx, old_syn_12k8_16k_fx, Qpostd, hb_synth_fx, output_frame, unbits, pitch_buf_fx ); + hb_synth_fx_exp = swb_bwe_dec_hr_fx( st_fx, old_syn_12k8_16k_fx, Qpostd, hb_synth_fx, output_frame, unbits, pitch_buf_fx ); /*Q0*/ } /*---------------------------------------------------------------------* @@ -497,13 +497,13 @@ ivas_error evs_dec_fx( move16(); } /*output_frame/FRAC_BWE_SMOOTH*/ - j = shr( output_frame, 1 ); + j = shr( output_frame, 1 ); /*Q0*/ tmp16_2 = 0; move16(); FOR( i = 0; i < j; i++ ) { /*hb_synth[i] *= (i*tmp);*/ - hb_synth_fx[i] = mult_r( hb_synth_fx[i], tmp16_2 ); + hb_synth_fx[i] = mult_r( hb_synth_fx[i], tmp16_2 ); /*hb_synth_fx_exp*/ move16(); #ifdef BASOP_NOGLOB tmp16_2 = add_o( tmp16_2, tmp16, &Overflow ); @@ -535,24 +535,24 @@ ivas_error evs_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/ exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx ); - Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); + Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/ Qpostd = exp; move16(); - Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( exp, st_fx->Qprev_synth_buffer_fx ) ); + Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( exp, st_fx->Qprev_synth_buffer_fx ) ); /*exp*/ st_fx->Qprev_synth_buffer_fx = exp; move16(); - Copy( synth_fx, tmp_buffer_fx, output_frame ); - Copy( st_fx->prev_synth_buffer_fx, synth_fx, tmps ); - Copy( tmp_buffer_fx, synth_fx + tmps, output_frame - tmps ); - Copy( tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps ); + Copy( synth_fx, tmp_buffer_fx, output_frame ); /*exp*/ + Copy( st_fx->prev_synth_buffer_fx, synth_fx, tmps ); /*st_fx->Qprev_synth_buffer_fx*/ + Copy( tmp_buffer_fx, synth_fx + tmps, output_frame - tmps ); /*exp*/ + Copy( tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps ); /*exp*/ } ELSE { exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx ); - Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); + Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/ Qpostd = exp; move16(); st_fx->Qprev_synth_buffer_fx = exp; @@ -573,7 +573,7 @@ ivas_error evs_dec_fx( move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, @@ -605,7 +605,7 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* TBE on top of ACELP@12.8kHz */ - tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); /*Q0*/ } ELSE { @@ -613,12 +613,12 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { /* HR SWB BWE on top of ACELP@16kHz */ - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ } ELSE { /* TBE on top of ACELP@16kHz */ - tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); /*Q0*/ } } @@ -630,12 +630,12 @@ ivas_error evs_dec_fx( IF( ( NE_16( st_fx->extl, st_fx->last_extl ) || ( EQ_16( st_fx->extl, st_fx->last_extl ) && EQ_16( ( st_fx->core ^ st_fx->last_core ), HQ_CORE ) ) ) && !( EQ_16( st_fx->extl, SWB_CNG ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) ) { /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/ tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { - hb_synth_fx[i] = mult_r( hb_synth_fx[i], sin_table256_fx[tmp16] ); + hb_synth_fx[i] = mult_r( hb_synth_fx[i], sin_table256_fx[tmp16] /*Q15*/ ); /*Q15 - hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } @@ -645,28 +645,28 @@ ivas_error evs_dec_fx( { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/ tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { - tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[sub( 255, tmp16 )] ), - st_fx->hb_prev_synth_buffer_fx[sub( sub( st_fx->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ) ); + tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[( 255 - tmp16 )] ), + st_fx->hb_prev_synth_buffer_fx[( ( st_fx->old_bwe_delay - 1 ) - i )], sin_table256_fx[tmp16] /*Q15*/ ) ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } - Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); + Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ } ELSE IF( GT_16( tmps, st_fx->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ /*incr = (short)( L_FRAME / (st->old_bwe_delay + 0.5f) );*/ - incr = idiv1616( L_FRAME * 2, add( shl( st_fx->old_bwe_delay, 1 ), 1 ) ); + incr = idiv1616( L_FRAME * 2, add( shl( st_fx->old_bwe_delay, 1 ), 1 ) ); /*Q0*/ tmp16 = 0; move16(); FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { - tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[sub( 255, tmp16 )] ); + tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[( 255 - tmp16 )] ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } @@ -679,23 +679,23 @@ ivas_error evs_dec_fx( FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/ - tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st_fx->hb_prev_synth_buffer_fx[sub( sub( st_fx->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); + tmp_buffer_fx[( ( tmps - 1 ) - i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[( ( tmps - 1 ) - i )], 32767 ), st_fx->hb_prev_synth_buffer_fx[( ( st_fx->old_bwe_delay - 1 ) - i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ move16(); tmp16 = add( tmp16, incr ); } - Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); + Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ } /* Delay hb_synth */ tmp16 = sub( hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp ); IF( tmp16 != 0 ) { - Scale_sig( st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); + Scale_sig( st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); /*Q15 - hb_synth_fx_exp*/ } - Copy( hb_synth_fx, tmp_buffer_fx, output_frame ); - Copy( st_fx->hb_prev_synth_buffer_fx, hb_synth_fx, tmps ); - Copy( tmp_buffer_fx, hb_synth_fx + tmps, sub( output_frame, tmps ) ); - Copy( tmp_buffer_fx + sub( output_frame, tmps ), st_fx->hb_prev_synth_buffer_fx, tmps ); + Copy( hb_synth_fx, tmp_buffer_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ + Copy( st_fx->hb_prev_synth_buffer_fx, hb_synth_fx, tmps ); /*Q15 - hb_synth_fx_exp*/ + Copy( tmp_buffer_fx, hb_synth_fx + tmps, sub( output_frame, tmps ) ); /*Q15 - hb_synth_fx_exp*/ + Copy( tmp_buffer_fx + sub( output_frame, tmps ), st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hb_synth_fx_exp*/ st_fx->old_bwe_delay = tmps; move16(); @@ -707,7 +707,7 @@ ivas_error evs_dec_fx( test(); IF( ( st_fx->ppp_mode_dec || ( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) && EQ_16( st_fx->L_frame, st_fx->last_L_frame ) && ( GT_16( st_fx->bws_cnt, 1 ) || NE_16( st_fx->last_extl, -1 ) ) ) { - Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); + Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ IF( LT_16( hBWE_TD->prev_hb_synth_fx_exp, 14 ) ) { hb_synth_fx_exp = add( hBWE_TD->prev_hb_synth_fx_exp, 1 ); @@ -720,7 +720,7 @@ ivas_error evs_dec_fx( } ELSE { - Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); + Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ } add_vec_fx( synth_fx, Qpostd, hb_synth_fx, hb_synth_fx_exp, synth_fx, Qpostd, output_frame ); @@ -749,10 +749,10 @@ ivas_error evs_dec_fx( BREAK; /*Q15*/ } - L_tmp = L_deposit_l( 1 ); /*Q2*hb_synth_fx_exp*/ + L_tmp = L_deposit_l( 1 ); FOR( i = 0; i < output_frame; i++ ) { - L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( hb_synth_fx[i], hb_synth_fx[i] ), tmp16 ) ); /*Q2*hb_synth_fx_exp*/ + L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( hb_synth_fx[i], hb_synth_fx[i] ), tmp16 ) ); /*Q30 - 2*hb_synth_fx_exp*/ } exp = norm_l( L_tmp ); fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); @@ -769,14 +769,14 @@ ivas_error evs_dec_fx( move16(); /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */ - delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); - Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); - Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); + delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/ + Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ + Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL ); /* final output of synthesis signal */ - Copy( synth_fx, output_sp, output_frame ); + Copy( synth_fx, output_sp, output_frame ); /*Qpostd*/ } ELSE /* MODE2 PART */ { @@ -828,7 +828,7 @@ ivas_error evs_dec_fx( dec_acelp_tcx_frame_fx( st_fx, &concealWholeFrame, output_sp, st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx ); - concealWholeFrameTmp = concealWholeFrame; + concealWholeFrameTmp = concealWholeFrame; /*Q0*/ move16(); if ( st_fx->bfi ) { @@ -900,7 +900,7 @@ ivas_error evs_dec_fx( move16(); } - st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); + st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); /*Q0*/ st_fx->bws_cnt = 0; move16(); @@ -931,7 +931,7 @@ ivas_error evs_dec_fx( fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); } } - Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); + Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ } ELSE { @@ -992,9 +992,9 @@ ivas_error evs_dec_fx( /* -------------------------------------------------------------- */ { - nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); - st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); - st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; + nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/ + st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/ + st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; /*Q0*/ move16(); st_fx->cldfbAna->lsb = st_fx->cldfbAna->no_channels; move16(); @@ -1015,12 +1015,12 @@ ivas_error evs_dec_fx( HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec; noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ), output_sp, 0 ); - hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); /*Q15*/ if ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { - hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); + hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); /*Q15*/ } - st_fx->lp_noise = hFdCngDec->lp_noise; + st_fx->lp_noise = hFdCngDec->lp_noise; /*Q9.23*/ move32(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT ApplyFdCng_fx( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 ); @@ -1046,7 +1046,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); + output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); /*Q0*/ #else output_sp[i] = add( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); #endif @@ -1061,7 +1061,7 @@ ivas_error evs_dec_fx( { timeIn_e = s_max( 0, s_min( sub( getScaleFactor16( pcmbufFB, hTcxDec->L_frameTCX ), 3 ), timeIn_e ) ); } - Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); + Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ timeIn_e = negate( timeIn_e ); cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); st_fx->scaleFactor.hb_scale = st_fx->scaleFactor.lb_scale; @@ -1072,8 +1072,8 @@ ivas_error evs_dec_fx( Word16 timeDomainBuffer[L_FRAME16k]; Word16 A[M + 1]; - Copy( st_fx->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame ); - Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); + Copy( st_fx->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame ); /*Q0*/ + Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); /*Q12*/ update_decoder_LPD_cng( st_fx, st_fx->coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); /* Generate additional comfort noise to mask potential coding artefacts */ @@ -1090,7 +1090,7 @@ ivas_error evs_dec_fx( { FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { - timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( st_fx->L_frame, 2 ) ) )] ); + timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[( i + ( 5 * ( st_fx->L_frame / 4 ) ) )] ); /*Q0*/ move16(); } } @@ -1117,10 +1117,10 @@ ivas_error evs_dec_fx( timeIn_e = 2; move16(); - Scale_sig( timeDomainBuffer, st_fx->L_frame, timeIn_e ); + Scale_sig( timeDomainBuffer, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ IF( st_fx->p_bpf_noise_buf ) { - Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); + Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ } timeIn_e = negate( timeIn_e ); @@ -1147,7 +1147,7 @@ ivas_error evs_dec_fx( IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { - Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); + Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ } } @@ -1179,28 +1179,28 @@ ivas_error evs_dec_fx( /* MODE1 MDCT to ACELP 2 transition */ delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); - Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /*Q0*/ hHQ_core->Q_old_postdec = 0; move16(); - delay_tdbwe = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + delay_tdbwe = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/ IF( GE_16( output_frame, L_FRAME16k ) ) { - Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); + Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); /*Qpostd*/ } test(); IF( EQ_16( st_fx->last_codec_mode, MODE1 ) && GT_16( st_fx->last_core_bfi, ACELP_CORE ) ) { - Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate( timeIn_e ) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ + Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate( timeIn_e ) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ /*-timeIn_e*/ IF( EQ_16( st_fx->core, ACELP_CORE ) ) { Word16 step, alpha, nz; i = 15; move16(); - tmps = NS2SA_FX2( st_fx->output_Fs, 3000000L ); - nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); - step = Inv16( tmps, &i ); + tmps = NS2SA_FX2( st_fx->output_Fs, 3000000L ); /*Q0*/ + nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); /*Q0*/ + step = Inv16( tmps, &i ); /*Q15 - i*/ step = shl( step, i ); alpha = 0; move16(); @@ -1208,11 +1208,11 @@ ivas_error evs_dec_fx( test(); IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { - Copy( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps ); + Copy( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps ); /*hHQ_core->Q_fer_samples*/ } ELSE { - Scale_sig( hHQ_core->old_out_fx, nz + tmps, negate( hHQ_core->Q_old_wtda ) ); + Scale_sig( hHQ_core->old_out_fx, nz + tmps, negate( hHQ_core->Q_old_wtda ) ); /*Q0*/ } hHQ_core->Q_old_wtda = 0; move16(); @@ -1220,7 +1220,7 @@ ivas_error evs_dec_fx( FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); + output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); /*timeIn_e*/ #else output_sp[i + delay_comp] = msu_r( L_mult( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); #endif @@ -1232,12 +1232,12 @@ ivas_error evs_dec_fx( { IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp ); + Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp ); /*Q0*/ } ELSE { - Copy( st_fx->prev_synth_buffer_fx, hTcxDec->FBTCXdelayBuf, delay_tdbwe ); - Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp ); + Copy( st_fx->prev_synth_buffer_fx, hTcxDec->FBTCXdelayBuf, delay_tdbwe ); /*st_fx->q_prev_synth_buffer_fx*/ + Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp ); /*Q0*/ } } } @@ -1247,30 +1247,30 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->core, ACELP_CORE ) && !( st_fx->con_tcx ) ) { set16_fx( st_fx->delay_buf_out_fx, 0, delay_comp ); - Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); + Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); /*timeIn_e*/ } ELSE { - Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->old_synth_lenFB, delay_comp ), st_fx->delay_buf_out_fx, delay_comp ); + Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->old_synth_lenFB, delay_comp ), st_fx->delay_buf_out_fx, delay_comp ); /*Q0*/ IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/ } ELSE { - Copy( hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); + Copy( hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/ } - Copy( pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub( output_frame, delay_comp ) ); + Copy( pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub( output_frame, delay_comp ) ); /*Q0*/ } } /* Delay compensation for TD-BWE*/ IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy( output_sp, tmp_buffer_fx, output_frame ); - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate( timeIn_e ) ); - Copy( tmp_buffer_fx, output_sp + delay_tdbwe, sub( output_frame, delay_tdbwe ) ); - Copy_Scale_sig( tmp_buffer_fx + sub( output_frame, delay_tdbwe ), st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e ); + Copy( output_sp, tmp_buffer_fx, output_frame ); /*timeIn_e*/ + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate( timeIn_e ) ); /*st_fx->q_prev_synth_buffer_fx*/ + Copy( tmp_buffer_fx, output_sp + delay_tdbwe, sub( output_frame, delay_tdbwe ) ); /*timeIn_e*/ + Copy_Scale_sig( tmp_buffer_fx + sub( output_frame, delay_tdbwe ), st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e ); /*timeIn_e*/ } test(); @@ -1311,13 +1311,13 @@ ivas_error evs_dec_fx( IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /*Q0*/ } ELSE { - tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ } - delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); + delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/ test(); test(); @@ -1330,8 +1330,8 @@ ivas_error evs_dec_fx( test(); IF( GT_16( st_fx->last_core_bfi, ACELP_CORE ) || ( st_fx->bfi && st_fx->last_core > ACELP_CORE ) || ( st_fx->prev_bfi && st_fx->last_con_tcx ) ) { - Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); - Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); + Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); /*Q0*/ + Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); /*Q0*/ } ELSE { @@ -1347,14 +1347,14 @@ ivas_error evs_dec_fx( FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); + output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); /*Q0*/ #else output_sp[i + tmps] = msu_r( L_mult( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); #endif move16(); alpha = add( alpha, step ); } - Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); + Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); /*Q0*/ } Copy( pcmbufFB + sub( hTcxDec->L_frameTCX, tmps ), hTcxDec->FBTCXdelayBuf, tmps ); @@ -1364,12 +1364,12 @@ ivas_error evs_dec_fx( { IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*st_fx->q_prev_synth_buffer_fx*/ } ELSE { - Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - Copy( hTcxDec->FBTCXdelayBuf + NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); + Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /*st_fx->Qprev_synth_buffer_fx*/ + Copy( hTcxDec->FBTCXdelayBuf + NS2SA( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*Q0*/ } } } @@ -1377,7 +1377,7 @@ ivas_error evs_dec_fx( { Word16 step, alpha; - Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, delta, negate( timeIn_e ) ); + Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, delta, negate( timeIn_e ) ); /*Q0*/ i = 15; move16(); @@ -1389,7 +1389,7 @@ ivas_error evs_dec_fx( FOR( i = delta; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); + output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); /*Q0*/ #else output_sp[i] = msu_r( L_mult( output_sp[i], alpha ), shr( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); #endif @@ -1402,14 +1402,14 @@ ivas_error evs_dec_fx( } } - Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); - Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); + Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ + Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ - Scale_sig( output_sp, output_frame, timeIn_e ); + Scale_sig( output_sp, output_frame, timeIn_e ); /*timeIn_e*/ tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ) + tmps, output_sp, hTcxDec->FBTCXdelayBuf ); - Copy( output_sp, synth_fx, output_frame ); + Copy( output_sp, synth_fx, output_frame ); /*timeIn_e*/ } /* end of MODE2 */ @@ -1422,28 +1422,28 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ) ) ); - Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx + sub( output_frame, post_hq_delay ), output_frame, negate( Qpostd ) ); /* output_sp not initialized yet */ + Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ) ) ); /*hTcxDec->q_synth_history_fx*/ + Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx + sub( output_frame, post_hq_delay ), output_frame, negate( Qpostd ) ); /* output_sp not initialized yet */ /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill this buffer are not available for all cases, the impact on the output is limited */ set16_fx( hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), 0, post_hq_delay ); IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); /*Q0*/ } IF( NE_16( st_fx->core, ACELP_CORE ) ) { IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); /*Q0*/ + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); /*Q0*/ } ELSE { - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); /*Q0*/ + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); /*Q0*/ } } } @@ -1453,7 +1453,7 @@ ivas_error evs_dec_fx( st_fx->Qprev_synth_buffer_fx = Qpostd; move16(); - Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); + Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ hp20( synth_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); /*----------------------------------------------------------------* @@ -1467,7 +1467,7 @@ ivas_error evs_dec_fx( } ELSE { - Copy( synth_fx, output_sp, output_frame ); + Copy( synth_fx, output_sp, output_frame ); /*Q0*/ } /*--------------------------------------------------------* diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 0c3f8afd6273966e2acfbb3ebd002927eb158724..81a5ae15175ca2cfaa5c6a07ab0a06dd2ca6d434 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -362,16 +362,16 @@ void configureFdCngDec( #ifdef IVAS_FLOAT_FIXED void configureFdCngDec_ivas_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */ - const Word16 bwidth, - const Word32 total_brate, - const Word16 L_frame, - const Word16 last_L_frame, - const Word16 element_mode ) + const Word16 bwidth, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 last_L_frame, /*Q0*/ + const Word16 element_mode /*Q0*/ ) { Word16 j, stopBandFR; HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; - hsCom->CngBandwidth = bwidth; + hsCom->CngBandwidth = bwidth; /*Q0*/ move16(); if ( EQ_16( hsCom->CngBandwidth, FB ) ) { @@ -381,7 +381,7 @@ void configureFdCngDec_ivas_fx( test(); IF( NE_32( total_brate, FRAME_NO_DATA ) && NE_32( total_brate, SID_2k40 ) ) { - hsCom->CngBitrate = total_brate; + hsCom->CngBitrate = total_brate; /*Q0*/ move32(); } ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) ) @@ -504,7 +504,7 @@ void configureFdCngDec_ivas_fx( hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( hsCom->FdCngSetup.numPartitions, 1 )], 1 ); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[( hsCom->FdCngSetup.numPartitions - 1 )], 1 ); /*Q0*/ initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); IF( EQ_16( hsCom->stopFFTbin, 160 ) ) @@ -522,13 +522,13 @@ void configureFdCngDec_ivas_fx( hsCom->nFFTpart = 21; move16(); } - hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); + hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); /*Q0*/ move16(); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[( j + hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); /*Q0*/ move16(); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[( j + hsCom->nFFTpart )]; move16(); } @@ -536,13 +536,13 @@ void configureFdCngDec_ivas_fx( move16(); if ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) { - stopBandFR = hsCom->stopFFTbin; + stopBandFR = hsCom->stopFFTbin; /*Q0*/ move16(); } initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); - hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; + hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; /*Q0*/ move16(); BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) ); @@ -551,18 +551,18 @@ void configureFdCngDec_ivas_fx( SWITCH( hsCom->fftlen ) { case 512: - hsCom->olapWinAna_fx = olapWinAna512_fx; + hsCom->olapWinAna_fx = olapWinAna512_fx; /*Q30*/ hsCom->fftSineTab_fx = NULL; - hsCom->olapWinSyn_fx = olapWinSyn256_fx; + hsCom->olapWinSyn_fx = olapWinSyn256_fx; /*Q15*/ hsCom->fftlenShift = 8; move16(); hsCom->fftlenFac = 32767 /*1.0 Q15*/; move16(); BREAK; case 640: - hsCom->olapWinAna_fx = olapWinAna640_fx; - hsCom->fftSineTab_fx = fftSineTab640_fx; - hsCom->olapWinSyn_fx = olapWinSyn320_fx; + hsCom->olapWinAna_fx = olapWinAna640_fx; /*Q30*/ + hsCom->fftSineTab_fx = fftSineTab640_fx; /*Q15*/ + hsCom->olapWinSyn_fx = olapWinSyn320_fx; /*Q15*/ hsCom->fftlenShift = 9; move16(); hsCom->fftlenFac = 20480 /*0.625 Q15*/; @@ -1305,13 +1305,13 @@ void FdCng_decodeSID_ivas_fx( const Word16 gain_q_offset = tmp16; /* Q0 */ move16(); - invTrfMatrix_fx = (Word32 *) tmpRAM_fx; + invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /*Q31*/ hFdCngCom = ( st->hFdCngDec )->hFdCngCom; - sidNoiseEst = hFdCngCom->sidNoiseEst; + sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q16*/ - N = hFdCngCom->npart; + N = hFdCngCom->npart; /*Q0*/ move16(); gain = 0; move32(); @@ -1321,7 +1321,7 @@ void FdCng_decodeSID_ivas_fx( /* Read bitstream */ FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { - indices[i] = get_next_indice_fx( st, bits_37bits[i] ); + indices[i] = get_next_indice_fx( st, bits_37bits[i] ); /*Q0*/ move16(); } @@ -1350,7 +1350,7 @@ void FdCng_decodeSID_ivas_fx( move16(); FOR( i = 0; i < N; i++ ) { - sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); + sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); /*Q31 - res_exp[i]*/ move32(); if ( LT_16( max_res_exp, res_exp[i] ) ) { @@ -1361,7 +1361,7 @@ void FdCng_decodeSID_ivas_fx( FOR( i = 0; i < N; i++ ) { - sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); + sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); /*Q31 - max_res_exp*/ move32(); } @@ -1372,14 +1372,14 @@ void FdCng_decodeSID_ivas_fx( IF( hFdCngCom->CngBandwidth == NB ) { - sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( sidNoiseEst[sub( N, 1 )], NB_LAST_BAND_SCALE ); + sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/ move32(); } test(); IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( sidNoiseEst[sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE ); + sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/ move32(); } @@ -1916,16 +1916,16 @@ void generate_masking_noise( *-------------------------------------------------------------------*/ void generate_masking_noise_ivas_fx( - Word32 *timeDomainBuffer, /* i/o: time-domain signal */ + Word32 *timeDomainBuffer, /* i/o: time-domain signal Q31 - *exp_out*/ Word16 *exp_out, /* o : time-domain signal exp */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 length, /* i : frame size */ - const Word16 core, /* i : core */ - const Word16 return_noise, /* i : noise is returned instead of added */ - const Word16 secondary, /* i : flag to indicate secondary noise generation */ - const Word16 element_mode, /* i : element mode */ + const Word16 length, /* i : frame size Q0*/ + const Word16 core, /* i : core Q0*/ + const Word16 return_noise, /* i : noise is returned instead of added Q0*/ + const Word16 secondary, /* i : flag to indicate secondary noise generation Q0*/ + const Word16 element_mode, /* i : element mode Q0*/ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word32 *cngNoiseLevel_fx = hFdCngCom->cngNoiseLevel; @@ -1941,14 +1941,14 @@ void generate_masking_noise_ivas_fx( Word16 shift; scale_fx = 0x40000000; // 1.0 in Q30 move32(); - startBand = hFdCngCom->startBand; + startBand = hFdCngCom->startBand; /*Q0*/ move16(); shift = getScaleFactor32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); if ( LT_16( sub( hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { - shift = sub( hFdCngCom->cngNoiseLevelExp, 4 ); + shift = sub( hFdCngCom->cngNoiseLevelExp, 4 ); /*Q0*/ } - scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); /*hFdCngCom->cngNoiseLevelExp*/ hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, shift ); move16(); @@ -2004,11 +2004,11 @@ void generate_masking_noise_ivas_fx( IF( startBand == 0 ) { rand_gauss_fx( &fftBuffer_fx[0], seed, *exp_out ); // Q15 - ptr_r_fx = fftBuffer_fx + 2; + ptr_r_fx = fftBuffer_fx + 2; /*Q31 - hFdCngCom->fftBuffer_exp*/ Word16 exp1; exp1 = add( hFdCngCom->cngNoiseLevelExp, 1 ); Word32 mpy1; - mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); // Q = noise_exp-1 + mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); /*Q31 - exp1*/ mpy1 = L_shl( mpy1, exp1 ); // Q31 fftBuffer_fx[0] = Mpy_32_32( fftBuffer_fx[0], mpy1 ); /* DC component in FFT */ // Q = Q15 ptr_level_fx++; @@ -2018,7 +2018,7 @@ void generate_masking_noise_ivas_fx( fftBuffer_fx[0] = 0; move32(); set32_fx( fftBuffer_fx + 2, 0, shl( sub( startBand, 1 ), 1 ) ); - ptr_r_fx = fftBuffer_fx + shl( startBand, 1 ); + ptr_r_fx = fftBuffer_fx + shl( startBand, 1 ); /*Q31 - hFdCngCom->fftBuffer_exp*/ } ptr_i_fx = ptr_r_fx + 1; FOR( ; ptr_level_fx < cngNoiseLevel_fx + hFdCngCom->stopFFTbin - startBand; ptr_level_fx++ ) @@ -2028,7 +2028,7 @@ void generate_masking_noise_ivas_fx( Word16 exp2; exp2 = add( hFdCngCom->cngNoiseLevelExp, 1 ); Word32 mpy2; - mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); // Q = noise_exp-1 + mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); /*Q31 - exp2*/ ( *ptr_r_fx ) = L_shl( Mpy_32_32( *ptr_r_fx, mpy2 ), exp2 ); // Q = Q15 move32(); ptr_r_fx += 2; @@ -2068,11 +2068,11 @@ void generate_masking_noise_ivas_fx( /* Add some comfort noise on top of decoded signal */ IF( return_noise ) { - Copy32( maskingNoise_fx, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); + Copy32( maskingNoise_fx, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/ } ELSE { - v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); + v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/ } return; @@ -2339,14 +2339,14 @@ void generate_stereo_masking_noise( *-------------------------------------------------------------------*/ void generate_stereo_masking_noise_fx( - Word16 *syn, /* i/o: time-domain signal */ + Word16 *syn, /* i/o: time-domain signal Q_syn*/ Word16 Q_syn, Decoder_State *st, /* i/o: decoder state structure */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 fadeOut, /* i : only fade out of previous state */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/ + const Word16 fadeOut, /* i : only fade out of previous state Q0*/ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const Word16 nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { HANDLE_FD_CNG_COM hFdCngCom; @@ -2361,22 +2361,22 @@ void generate_stereo_masking_noise_fx( IF( st->idchan == 0 ) { hFdCngCom = st->hFdCngDec->hFdCngCom; - Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); - Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); /*Q6*/ + Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); /*st->Q_syn*/ - set32_fx( &Np_fx[shr( hFdCngCom->frameSize, 1 )], 0, shr( hFdCngCom->frameSize, 1 ) ); - set32_fx( &Ns_fx[shr( hFdCngCom->frameSize, 1 )], 0, shr( hFdCngCom->frameSize, 1 ) ); + set32_fx( &Np_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) ); + set32_fx( &Ns_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) ); IF( !fadeOut ) { - Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); /*Q15*/ 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 ) { 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_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); + gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); /*Q30*/ scale_fx = ONE_IN_Q30; move32(); IF( LT_32( gamma_fx, 966367642 /* 0.9 in Q30 */ ) ) @@ -2394,7 +2394,7 @@ void generate_stereo_masking_noise_fx( move16(); move16(); move16(); - gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); + gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); /*Q31 - exp_gamma1*/ Word32 temp; temp = Sqrt32( gamma_fx, &exp_gamma2 ); // Q31-exp_gamma1 gamma_fx = L_sub( gamma_fx, L_shl( temp, sub( exp_gamma2, exp_gamma1 ) ) ); // Q31-exp_gamma1 @@ -2418,9 +2418,9 @@ void generate_stereo_masking_noise_fx( 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_fx < 0 ) { - add2 = L_negate( add2 ); + add2 = L_negate( add2 ); /*Q6*/ } - Ns_fx[i] = L_add( Ns_fx[i], add2 ); + Ns_fx[i] = L_add( Ns_fx[i], add2 ); /*Q6*/ move32(); } FOR( ; i < hFdCngCom->frameSize; i++ ) @@ -2440,13 +2440,13 @@ void generate_stereo_masking_noise_fx( FOR( i = 0; i < shr( hFdCngCom->frameSize, 1 ); i++ ) { hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, - L_add( L_shr( hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )], Q15 ), - Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ) ) ), + L_add( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ), Q14 ); // Q_olap move16(); hStereoCng->olapBufferSynth22_fx[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, - L_sub( L_shr( hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )], Q15 ), - Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ) ) ), + L_sub( L_shr( hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ) ) ), Q14 ); // Q_olap move16(); } @@ -2458,16 +2458,16 @@ void generate_stereo_masking_noise_fx( Np_fx[i] = L_add( Np_fx[i], N1_fx[i] ); // Q6 move32(); } - Copy32( &N1_fx[shr( hFdCngCom->frameSize, 1 )], &Np_fx[shr( hFdCngCom->frameSize, 1 )], shr( hFdCngCom->frameSize, 1 ) ); - scale_fx = L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ); // Q21 + Copy32( &N1_fx[( hFdCngCom->frameSize / 2 )], &Np_fx[( hFdCngCom->frameSize / 2 )], shr( hFdCngCom->frameSize, 1 ) ); /*Q6*/ + scale_fx = L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ); // Q21 FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { - hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ), Q6 ); // Q_olap + hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[( i + ( 5 * ( hFdCngCom->frameSize / 4 ) ) )] ), Q6 ); // Q_olap move16(); } } - Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, sub( st->Q_syn, 15 ) ); + Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, sub( st->Q_syn, 15 ) ); /*st->Q_syn*/ } ELSE { @@ -2495,9 +2495,9 @@ void generate_stereo_masking_noise_fx( ELSE IF( hStereoCng->enableSecCNA ) { Word16 SP_ratio_fx; - SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis */ + SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis Q15*/ Word16 prevSP_ratio_fx; - prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis */ + prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis Q15*/ move16(); /* scale and add masking noise */ FOR( i = 0; i < shr( *hStereoCng->frameSize, 2 ); i++ ) @@ -2506,20 +2506,20 @@ void generate_stereo_masking_noise_fx( Word16 scale_fx_tmp; scale_fx_tmp = BASOP_Util_Divide3216_Scale( L_add( L_mult0( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), L_mult0( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ), &s ); // Q15 scale_fx_tmp = shl( scale_fx_tmp, s ); - syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/ move16(); } FOR( ; i < *hStereoCng->frameSize / 2; i++ ) { - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/ move16(); } FOR( ; i < *hStereoCng->frameSize; i++ ) { - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); /*Q_syn*/ move16(); } - hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); + hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /*Q15*/ move16(); } @@ -2651,14 +2651,14 @@ void generate_masking_noise_lb_dirac( #ifdef IVAS_FLOAT_FIXED void generate_masking_noise_lb_dirac_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ - const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ - const Word16 cna_flag /* i : CNA flag for LB and HB */ + Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA Q11*/ + const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered Q0*/ + const Word16 cna_flag /* i : CNA flag for LB and HB Q0*/ ) { Word16 i; - Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; - Word32 *fftBuffer = hFdCngCom->fftBuffer; + Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/ + Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/ Word32 *ptr_r; Word32 *ptr_i; Word32 *ptr_level; @@ -2710,19 +2710,19 @@ void generate_masking_noise_lb_dirac_fx( IF( scale != 0 ) { /*Generate LF comfort noise only at first slot, for the whole frame*/ - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*hFdCngCom->cngNoiseLevelExp*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ IF( EQ_16( hFdCngCom->startBand, 0 ) ) { rand_gauss_fx( &fftBuffer[0], seed, exp_out ); - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*hFdCngCom->fftBuffer_exp*/ Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); - Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT */ - sqr = L_shl( sqr, exp2 ); - fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT */ + Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT Q31 - exp2*/ + sqr = L_shl( sqr, exp2 ); /*Q31*/ + fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT Q31 - hFdCngCom->fftBuffer_exp*/ move32(); ptr_level++; } @@ -2731,22 +2731,22 @@ void generate_masking_noise_lb_dirac_fx( fftBuffer[0] = 0; move32(); set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); - ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); + ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); /*hFdCngCom->fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*hFdCngCom->fftBuffer_exp*/ FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { rand_gauss_fx( ptr_r, seed, exp_out ); Word16 exp2 = hFdCngCom->cngNoiseLevelExp; - Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); - ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); // hFdCngCom->fftBuffer_exp + exp2 - 31 + Word32 mpy2 = Sqrt32( Mpy_32_32( scale, *ptr_level ), &exp2 ); /*Q31 - exp2*/ + ( *ptr_r ) = L_shl( Mpy_32_32( *ptr_r, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, seed, exp_out ); - ( *ptr_i ) = L_shl( Mpy_32_32( *ptr_i, mpy2 ), exp2 ); + ( *ptr_i ) = L_shl( Mpy_32_32( *ptr_i, mpy2 ), exp2 ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); ptr_i += 2; } @@ -2887,12 +2887,12 @@ void generate_masking_noise_dirac( void generate_masking_noise_dirac_ivas_fx( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ - Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ - Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ - Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ - const Word16 slot_index, /* i : CLDFB slot index */ - const Word16 cna_flag, /* i : CNA flag for LB and HB */ - const Word16 fd_cng_flag, /* i : FD-CNG flag for HB */ + Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA q_input*/ + Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer q_cldfb*/ + Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer q_cldfb*/ + const Word16 slot_index, /* i : CLDFB slot index Q0*/ + const Word16 cna_flag, /* i : CNA flag for LB and HB Q0*/ + const Word16 fd_cng_flag, /* i : FD-CNG flag for HB Q0*/ Word16 q_input, Word16 *q_cldfb ) { @@ -2948,12 +2948,12 @@ void generate_masking_noise_dirac_ivas_fx( IF( scale_fx != 0 ) { /* LF CLDFB*/ - cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[L_mult0( hFdCngCom->numCoreBands, slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); } ELSE { /* LB ana CLDFB*/ - cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[L_mult0( hFdCngCom->numCoreBands, slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[( hFdCngCom->numCoreBands * slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); } } @@ -2967,11 +2967,11 @@ void generate_masking_noise_dirac_ivas_fx( q_scale = 27; move16(); q_shift = norm_l( scale_fx ); - scale_fx = L_shl( scale_fx, q_shift ); + scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/ q_scale = add( q_scale, q_shift ); scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2 * Q8 - 34 q_scale = sub( add( q_scale, 2 * Q8 ), 31 ); - ptr_level_fx = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + ptr_level_fx = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ q_ptr_level = sub( 31, hFdCngCom->cngNoiseLevelExp ); FOR( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ ) @@ -2979,12 +2979,12 @@ void generate_masking_noise_dirac_ivas_fx( Word32 num; Word16 exp, q_num; q_shift = norm_l( scale_fx ); - scale_fx = L_shl( scale_fx, q_shift ); + scale_fx = L_shl( scale_fx, q_shift ); /*q_scale+q_shift*/ q_scale = add( q_scale, q_shift ); - num = Mpy_32_32( scale_fx, *ptr_level_fx ); + num = Mpy_32_32( scale_fx, *ptr_level_fx ); /*q_num*/ q_num = sub( add( q_scale, q_ptr_level ), 31 ); exp = sub( 31, q_num ); - num = Sqrt32( num, &exp ); + num = Sqrt32( num, &exp ); /*Q31 - exp*/ /* Real part in CLDFB band */ rand_gauss_fx( &Cldfb_RealBuffer_fx[i], seed, *q_cldfb ); Cldfb_RealBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_RealBuffer_fx[i], num ), exp ); @@ -3049,8 +3049,8 @@ void FdCngDecodeMDCTStereoSID_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; - ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; - lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; + ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/ + lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q18*/ } /* decode noise shapes and gains */ @@ -3060,7 +3060,7 @@ void FdCngDecodeMDCTStereoSID_fx( hFdCngCom = ( sts[ch]->hFdCngDec )->hFdCngCom; N = hFdCngCom->npart; move16(); - hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); + hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); /*Q0*/ move16(); IF( ch ) @@ -3077,7 +3077,7 @@ void FdCngDecodeMDCTStereoSID_fx( /* read bitstream */ FOR( i = 0; i < stages; i++ ) { - indices[i] = get_next_indice_fx( sts[ch], bits_37bits[i] ); + indices[i] = get_next_indice_fx( sts[ch], bits_37bits[i] ); /*Q0*/ move16(); } { @@ -3111,12 +3111,12 @@ void FdCngDecodeMDCTStereoSID_fx( hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom; FOR( p = 0; p < N; p++ ) { - tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 - tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); + tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 + tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/ move32(); if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) ) { - max_exp_idx = p; + max_exp_idx = p; /*Q0*/ move16(); } } @@ -3124,7 +3124,7 @@ void FdCngDecodeMDCTStereoSID_fx( // Bringing in same exponent FOR( p = 0; p < N; p++ ) { - lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); + lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q31 - exp_arr[max_exp_idx]*/ move32(); } @@ -3149,12 +3149,12 @@ void FdCngDecodeMDCTStereoSID_fx( { IF( GT_16( exp_diff, 0 ) ) { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/ move32(); } ELSE { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/ move32(); } } @@ -3302,26 +3302,26 @@ void FdCngDecodeDiracMDCTStereoSID_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; - ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; - lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; - ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++; + ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; /*Q20*/ + lr_ptr_fx[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; /*Q20*/ + ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++; /*Q18*/ } /* decode noise shapes and gains */ hFdCngCom = ( sts[0]->hFdCngDec )->hFdCngCom; - N = hFdCngCom->npart; + N = hFdCngCom->npart; /*Q0*/ move16(); /* read bitstream */ FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { - indices[i] = get_next_indice_fx( sts[0], bits_37bits[i] ); + indices[i] = get_next_indice_fx( sts[0], bits_37bits[i] ); /*Q0*/ move16(); } gain_fx[0] = Mpy_32_32( L_shl( L_sub( get_next_indice_fx( sts[0], 7 ), GAIN_Q_OFFSET_IVAS_FX ), Q20 ), TWO_BY_THREE_Q31 /* 2/3 in Q31 */ ); // Q20 move32(); - gain_fx[1] = gain_fx[0]; + gain_fx[1] = gain_fx[0]; /*Q20*/ move32(); /* MSVQ decoder */ @@ -3330,7 +3330,7 @@ void FdCngDecodeDiracMDCTStereoSID_fx( Scale_sig32( ms_ptr_fx[0], N, shift ); // Q20 - Copy32( ms_ptr_fx[0], ms_ptr_fx[1], N ); + Copy32( ms_ptr_fx[0], ms_ptr_fx[1], N ); /*Q20*/ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -3340,12 +3340,12 @@ void FdCngDecodeDiracMDCTStereoSID_fx( FOR( p = 0; p < N; p++ ) { - tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 - tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); + tmp32 = L_add( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q20 + tmp32_arr[p] = BASOP_util_Pow2( Mpy_32_32( tmp32, LOG_10_BASE_2_BY_10_Q31 ), Q11, &exp_arr[p] ); /*Q31 - exp_arr[p]*/ move32(); if ( LT_16( exp_arr[max_exp_idx], exp_arr[p] ) ) { - max_exp_idx = p; + max_exp_idx = p; /*Q0*/ move16(); } } @@ -3353,23 +3353,23 @@ void FdCngDecodeDiracMDCTStereoSID_fx( // Bringing in same exponent FOR( p = 0; p < N; p++ ) { - lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); + lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); /*Q20*/ move32(); } - hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx]; + hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx]; /*Q0*/ move16(); /* NB last band energy compensation */ test(); IF( hFdCngCom->CngBandwidth == NB ) { - lr_ptr_fx[ch][sub( N, 1 )] = Mpy_32_32( lr_ptr_fx[ch][sub( N, 1 )], NB_LAST_BAND_SCALE_Q31 ); + lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], NB_LAST_BAND_SCALE_Q31 ); /*Q20*/ move32(); } ELSE IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - lr_ptr_fx[ch][sub( N, 1 )] = Mpy_32_32( lr_ptr_fx[ch][sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE_Q31 ); + lr_ptr_fx[ch][( N - 1 )] = Mpy_32_32( lr_ptr_fx[ch][( N - 1 )], SWB_13k2_LAST_BAND_SCALE_Q31 ); /*Q20*/ move32(); } @@ -3393,12 +3393,12 @@ void FdCngDecodeDiracMDCTStereoSID_fx( { IF( exp_diff > 0 ) { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); /*Q18*/ move32(); } ELSE { - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], sub( 1, exp_diff ) ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); /*Q18*/ move32(); } } diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index ae5f0c2b139c4b8c852e5ff71d68af3a524452f5..984c1495e4bf8f2c195bfe23a37f4636fce4716f 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -73,7 +73,7 @@ ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) #ifdef IVAS_FLOAT_FIXED void initFdCngDec_ivas_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ) + Word16 scale /*Q15*/ ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; @@ -176,14 +176,14 @@ void initFdCngDec_ivas_fx( move16(); hFdCngDec->cna_rescale_fact_fx = 0; move16(); - hFdCngDec->cna_seed = 5687; + hFdCngDec->cna_seed = 5687; /*Q0*/ move16(); set16_fx( hFdCngDec->cna_cm_fx, 0, STEREO_DFT_BAND_MAX ); set16_fx( hFdCngDec->cna_g_state_fx, 0, STEREO_DFT_BAND_MAX ); st->CNG_mode = -1; move16(); - Copy( st->lsp_old_fx, st->lspCNG_fx, M ); + Copy( st->lsp_old_fx, st->lspCNG_fx, M ); /*Q15*/ #ifdef MSAN_FIX hFdCngDec->hFdCngCom->sid_frame_counter = 0; #endif @@ -192,7 +192,7 @@ void initFdCngDec_ivas_fx( void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ) + Word16 scale /*Q15*/ ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; @@ -322,17 +322,17 @@ void initFdCngDec_fx( */ void configureFdCngDec_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bwidth, - Word32 total_brate, - Word16 L_frame, - const Word16 Last_L_frame, - const Word16 element_mode ) + Word16 bwidth, /*Q0*/ + Word32 total_brate, /*Q0*/ + Word16 L_frame, /*Q0*/ + const Word16 Last_L_frame, /*Q0*/ + const Word16 element_mode /*Q0*/ ) { Word16 j, stopBandFR; HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; - hsCom->CngBandwidth = bwidth; + hsCom->CngBandwidth = bwidth; /*Q0*/ move16(); if ( EQ_16( hsCom->CngBandwidth, FB ) ) { @@ -342,7 +342,7 @@ void configureFdCngDec_fx( test(); IF( total_brate != FRAME_NO_DATA && NE_32( total_brate, SID_2k40 ) ) { - hsCom->CngBitrate = total_brate; + hsCom->CngBitrate = total_brate; /*Q0*/ move32(); } ELSE IF( EQ_32( hsCom->CngBitrate, -1 ) ) @@ -454,16 +454,16 @@ void configureFdCngDec_fx( } } } - hsCom->fftlen = hsCom->FdCngSetup.fftlen; + hsCom->fftlen = hsCom->FdCngSetup.fftlen; /*Q0*/ move16(); - hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; + hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; /*Q0*/ move16(); /* Configure the SID quantizer and the Confort Noise Generator */ hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( hsCom->FdCngSetup.numPartitions, 1 )], 1 ); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[( hsCom->FdCngSetup.numPartitions - 1 )], 1 ); /*Q0*/ move16(); initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); @@ -485,9 +485,9 @@ void configureFdCngDec_fx( move16(); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[( j + hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); /*Q0*/ move16(); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[( j + hsCom->nFFTpart )]; /*Q15*/ move16(); } @@ -495,14 +495,14 @@ void configureFdCngDec_fx( move16(); if ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) { - stopBandFR = hsCom->stopFFTbin; + stopBandFR = hsCom->stopFFTbin; /*Q0*/ move16(); } initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); - hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; + hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; /*Q0*/ move16(); SWITCH( hsCom->fftlen ) @@ -579,17 +579,17 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error */ Word16 ApplyFdCng_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT Word16 *powerSpectrum, #endif - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music ) + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ + Word16 is_music /*Q0*/ ) { Word16 j, k, nBins; Word16 s, s1, s2, num, denom; @@ -636,7 +636,7 @@ Word16 ApplyFdCng_fx( test(); move16(); } - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ move32(); cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; move16(); @@ -743,21 +743,21 @@ Word16 ApplyFdCng_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -777,7 +777,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -790,7 +790,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -807,7 +807,7 @@ Word16 ApplyFdCng_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } @@ -832,7 +832,7 @@ Word16 ApplyFdCng_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -841,28 +841,28 @@ Word16 ApplyFdCng_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -901,7 +901,7 @@ Word16 ApplyFdCng_fx( #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); #else @@ -982,7 +982,7 @@ Word16 ApplyFdCng_fx( hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -998,17 +998,17 @@ Word16 ApplyFdCng_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ Overflow = 0; move16(); IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); @@ -1024,17 +1024,17 @@ Word16 ApplyFdCng_fx( } #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); + st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); @@ -1116,21 +1116,21 @@ Word16 ApplyFdCng_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1150,7 +1150,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1160,7 +1160,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1204,16 +1204,16 @@ Word16 ApplyFdCng_fx( #ifdef IVAS_FLOAT_FIXED Word16 ApplyFdCng_ivas_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input */ + Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, - Word32 *powerSpectrum, + Word32 *powerSpectrum, /*Q_power_spectrum*/ Word16 Q_power_spectrum, - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ + Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music ) + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ + Word16 is_music /*Q0*/ ) { Word16 j, k, nBins; Word16 s, s1, s2, num, denom; @@ -1239,7 +1239,7 @@ Word16 ApplyFdCng_ivas_fx( hFdCngDec = st->hFdCngDec; hFdCngCom = hFdCngDec->hFdCngCom; - Word32 *sidNoiseEst = hFdCngCom->sidNoiseEst; + Word32 *sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q31 - hFdCngCom->sidNoiseEstExp*/ /* limit L_frame and core fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ L_frame = s_min( st->L_frame, L_FRAME16k ); @@ -1336,7 +1336,7 @@ Word16 ApplyFdCng_ivas_fx( j = 0; move16(); // s2 = -( WORD32_BITS - 1 ); - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( WORD32_BITS - 1 ); move16(); FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { @@ -1349,21 +1349,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1371,7 +1371,7 @@ Word16 ApplyFdCng_ivas_fx( /* Set unique exponent, if mantissa is equal to zero */ IF( EQ_16( facTab[k], 0 ) ) { - facTabExp[k] = negate( sub( WORD32_BITS, 1 ) ); + facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } s2 = s_max( s2, facTabExp[k] ); @@ -1380,10 +1380,10 @@ Word16 ApplyFdCng_ivas_fx( FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); + s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1399,7 +1399,7 @@ Word16 ApplyFdCng_ivas_fx( Word16 q_norm = L_norm_arr( &cngNoiseLevel[j], sub( FFTCLDFBLEN, j ) ); IF( GT_16( s, q_norm ) ) { - scale_sig32( cngNoiseLevel, j, sub( q_norm, s ) ); + scale_sig32( cngNoiseLevel, j, sub( q_norm, s ) ); /*q_norm*/ e_shift = sub( s, q_norm ); } } @@ -1407,7 +1407,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], sub( s, e_shift ) ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], sub( s, e_shift ) ); /*Q: s*/ move32(); } } @@ -1424,7 +1424,7 @@ Word16 ApplyFdCng_ivas_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } @@ -1442,7 +1442,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1451,28 +1451,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, 1 ); + L_tmp = Mpy_32_16_1( L_tmp, 1 ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1493,7 +1493,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1502,28 +1502,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); #else st->hTcxDec->conCngLevelBackgroundTrace = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); @@ -1542,7 +1542,7 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); #ifdef BASOP_NOGLOB - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif @@ -1551,28 +1551,28 @@ Word16 ApplyFdCng_ivas_fx( IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs( L_c, 0, 0 ); + L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); #endif } } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ #ifdef BASOP_NOGLOB - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1604,7 +1604,7 @@ Word16 ApplyFdCng_ivas_fx( move32(); FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) { - L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); + L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); /*Q31*/ } L_tmp_exp = 0; move16(); @@ -1624,9 +1624,9 @@ Word16 ApplyFdCng_ivas_fx( { lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ - lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); + lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); /*x2.56*/ } st->plcBackgroundNoiseUpdated = 1; @@ -1659,7 +1659,7 @@ Word16 ApplyFdCng_ivas_fx( hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ /*Q31 - hFdCngDec->bandNoiseShape_exp*/ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); @@ -1672,18 +1672,18 @@ Word16 ApplyFdCng_ivas_fx( Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31 - L_tmp_exp*/ Overflow = 0; move16(); IF( *( cngNoiseLevel + j ) < 0 ) { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } IF( *( cngNoiseLevel + j ) >= 0 ) { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ } #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); @@ -1699,17 +1699,17 @@ Word16 ApplyFdCng_ivas_fx( } #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); + L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16*/ + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ #else st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); #endif @@ -1740,7 +1740,7 @@ Word16 ApplyFdCng_ivas_fx( &hFdCngDec->partNoiseShape_exp ); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - Copy32( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); + Copy32( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); /*Q31 - hFdCngDec->sidNoiseEstExp*/ } } @@ -1758,7 +1758,7 @@ Word16 ApplyFdCng_ivas_fx( { if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - sidNoiseEst = hFdCngCom->sidNoiseEstLp; + sidNoiseEst = hFdCngCom->sidNoiseEstLp; /*Q31 - hFdCngDec->sidNoiseEstExp*/ } /* Interpolate the CLDFB band levels from the SID (partition) levels */ IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) @@ -1770,7 +1770,7 @@ Word16 ApplyFdCng_ivas_fx( move16(); } - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( ( WORD32_BITS - 1 ) ); move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; @@ -1785,21 +1785,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( sidNoiseEst[k] ); - L_tmp = L_shl( sidNoiseEst[k], s1 ); + L_tmp = L_shl( sidNoiseEst[k], s1 ); /*Q31 - ( hFdCngCom->sidNoiseEstExp - s1 )*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - ( hFdCngDec->partNoiseShape_ex - s1 )*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1807,7 +1807,7 @@ Word16 ApplyFdCng_ivas_fx( /* Set unique exponent, IF mantissa is equal to zero */ IF( EQ_16( facTab[k], 0 ) ) { - facTabExp[k] = negate( sub( WORD32_BITS, 1 ) ); + facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } s2 = s_max( s2, facTabExp[k] ); @@ -1820,10 +1820,10 @@ Word16 ApplyFdCng_ivas_fx( FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) { s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); + s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1833,7 +1833,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1845,7 +1845,7 @@ Word16 ApplyFdCng_ivas_fx( { IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { - s2 = negate( sub( WORD32_BITS, 1 ) ); + s2 = -( ( WORD32_BITS - 1 ) ); /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -1859,21 +1859,21 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngDec->partNoiseShape[k] != 0 ) { s1 = norm_l( hFdCngCom->sidNoiseEstLp[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEstLp[k], s1 ); + L_tmp = L_shl( hFdCngCom->sidNoiseEstLp[k], s1 ); /*Q31 - ( hFdCngCom->sidNoiseEstExp - s1 )*/ L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEstLp[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); L_tmp = L_shr( L_tmp, 1 ); s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); + num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); + L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - ( hFdCngDec->partNoiseShape_exp - s1 )*/ L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); + denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - facTab[k] = div_s( num, denom ); + facTab[k] = div_s( num, denom ); /*Q15 - s*/ move16(); facTabExp[k] = s; move16(); @@ -1897,7 +1897,7 @@ Word16 ApplyFdCng_ivas_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); + cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1907,7 +1907,7 @@ Word16 ApplyFdCng_ivas_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ move32(); } } @@ -1948,7 +1948,7 @@ Word16 ApplyFdCng_ivas_fx( void */ void perform_noise_estimation_dec_fx( - const Word16 *timeDomainInput, /* i: pointer to time domain input */ + const Word16 *timeDomainInput, /* i: pointer to time domain input Q*/ const Word16 Q, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT float *power_spectrum, @@ -1977,22 +1977,22 @@ void perform_noise_estimation_dec_fx( /* pointer initialization */ - periodog = hFdCngDec->hFdCngCom->periodog; - fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; + periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ - part = hFdCngDec->part_shaping; - psize_inv = hFdCngDec->psize_inv_shaping; - psize_norm = hFdCngDec->psize_shaping_norm; + part = hFdCngDec->part_shaping; /*Q0*/ + psize_inv = hFdCngDec->psize_inv_shaping; /*Q15*/ + psize_norm = hFdCngDec->psize_shaping_norm; /*Q15 - hFdCngDec->psize_shaping_norm_exp*/ /* variable initialization */ - startBand = hFdCngDec->hFdCngCom->startBand; + startBand = hFdCngDec->hFdCngCom->startBand; /*Q0*/ move16(); - stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; + stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; /*Q0*/ move16(); - npart = hFdCngDec->npart_shaping; + npart = hFdCngDec->npart_shaping; /*Q0*/ move16(); - nFFTpart = hFdCngDec->nFFTpart_shaping; + nFFTpart = hFdCngDec->nFFTpart_shaping; /*Q0*/ move16(); /* Perform STFT analysis */ @@ -2278,36 +2278,36 @@ void perform_noise_estimation_dec_fx( len = sub( stopFFTbin, startBand ); - s = getScaleFactor32( &fftBuffer[shl( startBand, 1 )], shl( len, 1 ) ); + s = getScaleFactor32( &fftBuffer[( startBand * 2 )], shl( len, 1 ) ); s = sub( s, 1 ); ptr_per = periodog; IF( startBand == 0 ) { /* DC component */ - tmp_r = extract_h( L_shl( fftBuffer[0], s ) ); + tmp_r = extract_h( L_shl( fftBuffer[0], s ) ); /*Q15 - fftBuffer_exp + s*/ - tmp = L_mult( tmp_r, tmp_r ); - *ptr_per = tmp; + tmp = L_mult( tmp_r, tmp_r ); /*Q31 - 2*(fftBuffer_exp - s)*/ + *ptr_per = tmp; /*Q31 - 2*(fftBuffer_exp - s)*/ move32(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ len = sub( len, 1 ); } ELSE { - ptr_r = fftBuffer + shl( startBand, 1 ); + ptr_r = fftBuffer + shl( startBand, 1 ); /*fftBuffer_exp*/ } ptr_i = ptr_r + 1; FOR( i = 0; i < len; i++ ) { - tmp_r = extract_h( L_shl( *ptr_r, s ) ); - tmp_i = extract_h( L_shl( *ptr_i, s ) ); + tmp_r = extract_h( L_shl( *ptr_r, s ) ); /*Q15 - fftBuffer_exp + s*/ + tmp_i = extract_h( L_shl( *ptr_i, s ) ); /*Q15 - fftBuffer_exp + s*/ - tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); - *ptr_per = tmp; + tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); /*Q31 - 2*(fftBuffer_exp - s)*/ + *ptr_per = tmp; /*Q31 - 2*(fftBuffer_exp - s)*/ move32(); ptr_r += 2; @@ -2348,7 +2348,7 @@ void perform_noise_estimation_dec_fx( len = sub( stopFFTbin, startBand ); FOR( i = 0; i < len; i++ ) { - hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); + hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } hFdCngDec->hFdCngCom->periodog_exp = add( hFdCngDec->hFdCngCom->periodog_exp, sub( 2, s ) ); @@ -2404,17 +2404,17 @@ void perform_noise_estimation_dec_fx( #ifdef IVAS_FLOAT_FIXED void perform_noise_estimation_dec_ivas_fx( - const Word16 *timeDomainInput, /* i: pointer to time domain input */ + const Word16 *timeDomainInput, /* i: pointer to time domain input Q*/ const Word16 Q, - Word32 *power_spectrum, + Word32 *power_spectrum, /*Q_power_spectrum*/ Word16 Q_power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - const Word16 VAD /* i : VAD flag in the decoder */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 L_frame, /* i : frame length at internal Fs Q0*/ + const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs Q0*/ + const Word32 last_core_brate, /* i : previous frame core bitrate Q0*/ + const Word16 VAD /* i : VAD flag in the decoder Q0*/ ) { Word16 i, p, fftBuffer_exp = 0; @@ -2442,15 +2442,15 @@ void perform_noise_estimation_dec_ivas_fx( /* pointer initialization */ - periodog = hFdCngDec->hFdCngCom->periodog; - fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; - ptr_per = periodog; - msPeriodog = hFdCngDec->msPeriodog; - msNoiseEst = hFdCngDec->msNoiseEst; + periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ + ptr_per = periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + msPeriodog = hFdCngDec->msPeriodog; /*Q31 - hFdCngDec->msPeriodog_exp*/ + msNoiseEst = hFdCngDec->msNoiseEst; /*Q31 - hFdCngDec->msNoiseEst_exp*/ - part = hFdCngDec->part_shaping; - psize_inv = hFdCngDec->psize_inv_shaping; - psize_norm = hFdCngDec->psize_shaping_norm; + part = hFdCngDec->part_shaping; /*Q0*/ + psize_inv = hFdCngDec->psize_inv_shaping; /*Q15*/ + psize_norm = hFdCngDec->psize_shaping_norm; /*Q15 - hFdCngDec->psize_shaping_norm_exp*/ /* variable initialization */ startBand = hFdCngDec->hFdCngCom->startBand; @@ -2494,39 +2494,39 @@ void perform_noise_estimation_dec_ivas_fx( /* Calculate periodogram (squared magnitude in each FFT bin) */ IF( startBand == 0 ) { - W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); + W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /*Q31 - 2*fftBuffer_exp*/ tmp_s = W_norm( W_tmp ); - ( *ptr_per ) = W_extract_h( W_shl( W_tmp, tmp_s ) ); + ( *ptr_per ) = W_extract_h( W_shl( W_tmp, tmp_s ) ); /*tmp_q*/ tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); min_q = tmp_q; move16(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ } ELSE { - ptr_r = fftBuffer + i_mult( 2, startBand ); + ptr_r = fftBuffer + i_mult( 2, startBand ); /*Q31 - fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ FOR( ; ptr_per < periodog + sub( stopFFTbin, startBand ); ptr_per++ ) { - W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); + W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); /*Q31 - 2*(fftBuffer_exp)*/ tmp_s = W_norm( W_tmp ); tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); - *ptr_per = W_extract_h( W_shl( W_tmp, tmp_s ) ); + *ptr_per = W_extract_h( W_shl( W_tmp, tmp_s ) ); /*tmp_q*/ IF( LT_16( tmp_q, min_q ) ) { - reIter = ptr_per; + reIter = ptr_per; /*tmp_q*/ Word16 diff; diff = sub( min_q, tmp_q ); WHILE( reIter > periodog ) { reIter--; - *reIter = L_shr( *reIter, diff ); + *reIter = L_shr( *reIter, diff ); /*tmp_q*/ move32(); } min_q = tmp_q; @@ -2536,7 +2536,7 @@ void perform_noise_estimation_dec_ivas_fx( { Word16 diff; diff = sub( tmp_q, min_q ); - ( *ptr_per ) = L_shr( ( *ptr_per ), diff ); + ( *ptr_per ) = L_shr( ( *ptr_per ), diff ); /*min_q*/ } /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ @@ -2560,7 +2560,7 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( p = 0; p < stopFFTbin - startBand; p++ ) { - periodog[p] = L_shl( periodog[p], tmp_s ); + periodog[p] = L_shl( periodog[p], tmp_s ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } } @@ -2576,9 +2576,9 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( ; i <= part[p]; i++ ) { - temp = L_add( temp, periodog[i] ); + temp = L_add( temp, periodog[i] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ } - msPeriodog[p] = Mpy_32_16_1( temp, psize_inv[p] ); // Qtemp = Qperiodog + msPeriodog[p] = Mpy_32_16_1( temp, psize_inv[p] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } @@ -2596,7 +2596,7 @@ void perform_noise_estimation_dec_ivas_fx( { FOR( p = 0; p < NPART_SHAPING; p++ ) { - msPeriodog[p] = L_shr( msPeriodog[p], sub( -16, hFdCngDec->msPeriodog_exp ) ); + msPeriodog[p] = L_shr( msPeriodog[p], sub( -16, hFdCngDec->msPeriodog_exp ) ); /*Q31 - (-16)*/ move32(); } hFdCngDec->msPeriodog_exp = -16; @@ -2612,8 +2612,8 @@ void perform_noise_estimation_dec_ivas_fx( move64(); FOR( ; i <= part[p]; i++ ) { - delta = L_sub( periodog[i], msPeriodog[p] ); - W_tmp = W_add( W_tmp, W_mult0_32_32( delta, delta ) ); + delta = L_sub( periodog[i], msPeriodog[p] ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + W_tmp = W_add( W_tmp, W_mult0_32_32( delta, delta ) ); /*Q31 - 2*(hFdCngDec->hFdCngCom->periodog_exp)*/ } tmp_s = W_norm( W_tmp ); temp = W_extract_h( W_shl( W_tmp, tmp_s ) ); // Q = 63 - 2*(31-exp) - tmp_s @@ -2622,25 +2622,25 @@ void perform_noise_estimation_dec_ivas_fx( /* compensate for the loss of variance */ e_temp = sub( 63, add( i_mult( sub( 31, hFdCngDec->hFdCngCom->periodog_exp ), 2 ), tmp_s ) ); - temp = Sqrt32( temp, &e_temp ); + temp = Sqrt32( temp, &e_temp ); /*Q31 - e_temp*/ IF( LT_16( e_temp, 0 ) ) { - temp = L_shr( temp, abs_s( e_temp ) ); + temp = L_shr( temp, abs_s( e_temp ) ); /*Q31*/ e_temp = 0; move16(); } - ftemp = rand_gauss( &hFdCngDec->cna_seed ); + ftemp = rand_gauss( &hFdCngDec->cna_seed ); /*Q29*/ - L_tmp = Mpy_32_32( temp, ftemp ); - L_tmp = L_shr( L_tmp, sub( sub( hFdCngDec->hFdCngCom->periodog_exp, e_temp ), 2 ) ); + L_tmp = Mpy_32_32( temp, ftemp ); /*Q29*/ + L_tmp = L_shr( L_tmp, sub( sub( hFdCngDec->hFdCngCom->periodog_exp, e_temp ), 2 ) ); /*Q31 - hFdCngDec->msPeriodog_exp*/ - msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); + msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); - IF( LT_32( msPeriodog[p], L_shr( 21474, hFdCngDec->msPeriodog_exp ) ) ) + IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) { - msPeriodog[p] = L_shr( 21474, hFdCngDec->msPeriodog_exp ); + msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); } } @@ -2652,7 +2652,7 @@ void perform_noise_estimation_dec_ivas_fx( { FOR( p = 0; p < npart; p++ ) { - msPeriodog[p] = L_shr( msPeriodog[p], sub( 5, tmp_s ) ); + msPeriodog[p] = L_shr( msPeriodog[p], sub( 5, tmp_s ) ); /*Q31 - hFdCngDec->msPeriodog_exp - 5 + tmp_s*/ move32(); } hFdCngDec->msPeriodog_exp = add( hFdCngDec->msPeriodog_exp, sub( 5, tmp_s ) ); @@ -2664,13 +2664,13 @@ void perform_noise_estimation_dec_ivas_fx( move32(); IF( GE_16( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ) { - enr_tot = L_add_sat( L_shr( sum32_fx( msPeriodog, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ), 1 ); + enr_tot = L_add_sat( L_shr( sum32_fx( msPeriodog, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ), 1 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ enr_tot0 = L_add_sat( sum32_fx( msNoiseEst, npart ), 1 ); } ELSE IF( LT_16( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ) { enr_tot = L_add_sat( sum32_fx( msPeriodog, npart ), 1 ); - enr_tot0 = L_add_sat( L_shr( sum32_fx( msNoiseEst, npart ), sub( hFdCngDec->msPeriodog_exp, hFdCngDec->msNoiseEst_exp ) ), 1 ); + enr_tot0 = L_add_sat( L_shr( sum32_fx( msNoiseEst, npart ), sub( hFdCngDec->msPeriodog_exp, hFdCngDec->msNoiseEst_exp ) ), 1 ); /*Q31 - hFdCngDec->msPeriodog_exp*/ } /* update short-term periodogram on larger partitions */ @@ -2680,7 +2680,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( max_l && GT_16( q_shift, norm_shift ) ) { - scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, sub( norm_shift, q_shift ) ); + scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - hFdCngDec->msPeriodog_ST_exp + ( norm_shift - q_shift )*/ hFdCngDec->msPeriodog_ST_exp = sub( hFdCngDec->msPeriodog_ST_exp, sub( norm_shift, q_shift ) ); move16(); q_shift = norm_shift; @@ -2693,14 +2693,14 @@ void perform_noise_estimation_dec_ivas_fx( IF( NE_16( L_frame, last_L_frame ) || LE_32( last_core_brate, SID_2k40 ) ) { /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */ - hFdCngDec->msPeriodog_ST_fx[p] = L_shl( msPeriodog[p], q_shift ); + hFdCngDec->msPeriodog_ST_fx[p] = L_shl( msPeriodog[p], q_shift ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ move32(); } ELSE { #ifdef IVAS_ENH32_CADENCE_CHANGES - temp = L_shl( msPeriodog[p], q_shift ); - hFdCngDec->msPeriodog_ST_fx[p] = Madd_32_16( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), temp, MAX_16 - ST_PERIODOG_FACT_Q15 ); + temp = L_shl( msPeriodog[p], q_shift ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ + hFdCngDec->msPeriodog_ST_fx[p] = Madd_32_16( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), temp, MAX_16 - ST_PERIODOG_FACT_Q15 ); /*Q31 - hFdCngDec->msPeriodog_ST_exp*/ #else hFdCngDec->msPeriodog_ST_fx[p] = L_add( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), Mpy_32_16_1( temp, sub( MAX_16, ST_PERIODOG_FACT_Q15 ) ) ); #endif @@ -2711,7 +2711,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, q_shift ); + scale_sig32( hFdCngDec->msPeriodog_ST_fx, NPART_SHAPING, q_shift ); /*Q31 - hFdCngDec->msPeriodog_ST_exp + q_shift*/ hFdCngDec->msPeriodog_ST_exp = sub( hFdCngDec->msPeriodog_ST_exp, q_shift ); move16(); } @@ -2731,32 +2731,32 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( EQ_16( last_L_frame, L_FRAME16k ) && EQ_16( L_frame, L_FRAME ) ) { - msNoiseEst[61] = msNoiseEst[58]; + msNoiseEst[61] = msNoiseEst[58]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[60] = L_min( msNoiseEst[58], msNoiseEst[57] ); + msNoiseEst[60] = L_min( msNoiseEst[58], msNoiseEst[57] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[59] = msNoiseEst[57]; + msNoiseEst[59] = msNoiseEst[57]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[58] = msNoiseEst[56]; + msNoiseEst[58] = msNoiseEst[56]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[57] = msNoiseEst[56]; + msNoiseEst[57] = msNoiseEst[56]; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[55] ); + msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[55] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); } ELSE IF( EQ_16( last_L_frame, L_FRAME ) && EQ_16( L_frame, L_FRAME16k ) ) { - msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[57] ); + msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[57] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[57] = L_min( msNoiseEst[58], msNoiseEst[59] ); + msNoiseEst[57] = L_min( msNoiseEst[58], msNoiseEst[59] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[58] = L_min( msNoiseEst[60], msNoiseEst[61] ); + msNoiseEst[58] = L_min( msNoiseEst[60], msNoiseEst[61] ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[59] = 0; + msNoiseEst[59] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[60] = 0; + msNoiseEst[60] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); - msNoiseEst[61] = 0; + msNoiseEst[61] = 0; /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; @@ -2773,15 +2773,15 @@ void perform_noise_estimation_dec_ivas_fx( /* background noise update with moving average */ IF( hFdCngDec->first_cna_noise_update_cnt != 0 ) { - alpha = Inv16( add( hFdCngDec->first_cna_noise_update_cnt, 1 ), &e ); - alpha = shl_sat( alpha, e ); // Q15 + alpha = Inv16( add( hFdCngDec->first_cna_noise_update_cnt, 1 ), &e ); /*Q15*/ + alpha = shl_sat( alpha, e ); // Q15 maximum_32_fx( msPeriodog, npart, &max_l ); q_shift = sub( hFdCngDec->hFdCngCom->periodog_exp, hFdCngDec->msNoiseEst_exp ); norm_shift = norm_l( max_l ); test(); IF( max_l && GT_16( q_shift, norm_shift ) ) { - scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); + scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - hFdCngDec->msNoiseEst_exp + ( norm_shift - q_shift )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, sub( norm_shift, q_shift ) ); move16(); q_shift = norm_shift; @@ -2791,7 +2791,7 @@ void perform_noise_estimation_dec_ivas_fx( { temp = L_shl( msPeriodog[p], q_shift ); #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), Mpy_32_16_1( temp, alpha ) ); #endif @@ -2801,8 +2801,8 @@ void perform_noise_estimation_dec_ivas_fx( ELSE { Word16 tmp = s_max( sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); - Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); - scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); + Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); /*Q31 - tmp*/ + scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); /*Q31 - tmp*/ hFdCngDec->msNoiseEst_exp = tmp; move16(); } @@ -2810,7 +2810,7 @@ void perform_noise_estimation_dec_ivas_fx( /* check, if we reached the required number of first CNA noise update frames */ IF( LT_16( hFdCngDec->first_cna_noise_update_cnt, FIRST_CNA_NOISE_UPD_FRAMES - 1 ) ) { - hFdCngDec->first_cna_noise_update_cnt = add( hFdCngDec->first_cna_noise_update_cnt, 1 ); + hFdCngDec->first_cna_noise_update_cnt = add( hFdCngDec->first_cna_noise_update_cnt, 1 ); /*Q0*/ move16(); } ELSE @@ -2838,10 +2838,10 @@ void perform_noise_estimation_dec_ivas_fx( { Word16 scale; /* no updates during active frames except for significant energy drops */ - enr_ratio = BASOP_Util_Divide3232_Scale( enr_tot, enr_tot0, &scale ); + enr_ratio = BASOP_Util_Divide3232_Scale( enr_tot, enr_tot0, &scale ); /*Q15 - scale*/ IF( scale <= 0 ) { - enr_ratio = shl( enr_ratio, scale ); + enr_ratio = shl( enr_ratio, scale ); /*Q15*/ scale = 15; move16(); } @@ -2852,7 +2852,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_16( enr_ratio, shl( 1, sub( scale, 1 ) ) ) ) { /* total energy significantly decreases during active frames -> downward update */ - wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); + wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); /*scale*/ Word16 temp_q_msNoiseEst[NPART_SHAPING]; Word16 min_q_msNoiseEst = MAX_16; move16(); @@ -2867,7 +2867,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_32( L_tmp, msNoiseEst[p] ) ) { #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); /*temp_q_msNoiseEst[p]*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], wght ), Mpy_32_16_1( L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ) ); #endif @@ -2879,7 +2879,7 @@ void perform_noise_estimation_dec_ivas_fx( } FOR( p = 0; p < NPART_SHAPING; p++ ) { - msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); + msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); /*min_q_msNoiseEst*/ move32(); } hFdCngDec->msNoiseEst_exp = min_q_msNoiseEst; @@ -2890,11 +2890,11 @@ void perform_noise_estimation_dec_ivas_fx( /* energy significantly decreases in one of the larger partitions during active frames -> downward update */ FOR( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ ) { - L_tmp = L_shr_sat( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); + L_tmp = L_shr_sat( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); /*Q31 - hFdCngDec->msPeriodog_ST_exp*/ IF( LT_32( L_tmp, msNoiseEst[p] ) ) { #ifdef IVAS_ENH32_CADENCE_CHANGES - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ #else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), Mpy_32_16_1( L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ) ); #endif @@ -2915,12 +2915,12 @@ void perform_noise_estimation_dec_ivas_fx( hFdCngDec->ms_last_inactive_bwidth = bwidth; move16(); /* update background noise during inactive frames */ - ptr_per = msNoiseEst; + ptr_per = msNoiseEst; /*Q31 - hFdCngDec->msNoiseEst_exp*/ FOR( p = 0; p < npart; p++ ) { Word16 i_e = 15; move16(); - enr = msPeriodog[p]; + enr = msPeriodog[p]; /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); enr_e = hFdCngDec->msPeriodog_exp; move16(); @@ -2930,7 +2930,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( GT_16( hFdCngDec->ms_cnt_bw_up, 0 ) && GT_16( p, 55 ) ) { - alpha = Inv16( add( hFdCngDec->ms_cnt_bw_up, 1 ), &i_e ); + alpha = Inv16( add( hFdCngDec->ms_cnt_bw_up, 1 ), &i_e ); /*Q15 - i_e*/ IF( i_e < 0 ) { alpha = shr( alpha, negate( i_e ) ); // Q15 @@ -2948,14 +2948,14 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( ( norm_l( *ptr_per ) == 0 ) && *ptr_per ) { - enr = *ptr_per; + enr = *ptr_per; /*Q31 - hFdCngDec->msNoiseEst_exp*/ scale_sig32( msNoiseEst, NPART_SHAPING, -1 ); hFdCngDec->msNoiseEst_exp = add( hFdCngDec->msNoiseEst_exp, 1 ); move16(); } ELSE { - enr = L_shl( *ptr_per, 1 ); + enr = L_shl( *ptr_per, 1 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ } enr_e = hFdCngDec->msNoiseEst_exp; move16(); @@ -2965,7 +2965,7 @@ void perform_noise_estimation_dec_ivas_fx( test(); IF( *ptr_per != 0 && alpha != 0 ) { - *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); + *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); if ( *ptr_per == 0 ) { @@ -2985,19 +2985,19 @@ void perform_noise_estimation_dec_ivas_fx( norm_shift = norm_l( enr ); IF( LE_16( q_shift, norm_shift ) ) { - enr = L_shl( enr, q_shift ); + enr = L_shl( enr, q_shift ); /*Q31 - hFdCngDec->msNoiseEst_exp + q_shift*/ move32(); } ELSE { enr_e = sub( enr_e, norm_shift ); - enr = L_shl( enr, norm_shift ); - scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); + enr = L_shl( enr, norm_shift ); /*Q31 - hFdCngDec->msNoiseEst_exp + norm_shift*/ + scale_sig32( msNoiseEst, NPART_SHAPING, sub( norm_shift, q_shift ) ); /*Q31 - ( hFdCngDec->msNoiseEst_exp - ( norm_shift - q_shift ) )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, sub( norm_shift, q_shift ) ); move16(); } } - *ptr_per = Madd_32_16( ( *ptr_per ), enr, sub( MAX_16, alpha ) ); + *ptr_per = Madd_32_16( ( *ptr_per ), enr, sub( MAX_16, alpha ) ); /*Q31 - enr_e*/ move32(); #else *ptr_per = L_add( ( *ptr_per ), Mpy_32_16_1( enr, sub( MAX_16, alpha ) ) ); @@ -3016,12 +3016,12 @@ void perform_noise_estimation_dec_ivas_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( msNoiseEst, NPART_SHAPING, q_shift ); + scale_sig32( msNoiseEst, NPART_SHAPING, q_shift ); /*Q31 - ( hFdCngDec->msNoiseEst_exp - q_shift )*/ hFdCngDec->msNoiseEst_exp = sub( hFdCngDec->msNoiseEst_exp, q_shift ); move16(); } - Copy32( msNoiseEst, hFdCngDec->msPsd_fx, npart ); + Copy32( msNoiseEst, hFdCngDec->msPsd_fx, npart ); /*Q31 - ( hFdCngDec->msNoiseEst_exp )*/ hFdCngDec->msPsd_exp_fft = hFdCngDec->msNoiseEst_exp; move16(); @@ -3029,7 +3029,7 @@ void perform_noise_estimation_dec_ivas_fx( scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); - Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); + Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ hFdCngDec->smoothed_psd_exp = hFdCngDec->bandNoiseShape_exp; move16(); set32_fx( &hFdCngDec->smoothed_psd_fx[stopFFTbin], 0, sub( L_FRAME16k, stopFFTbin ) ); @@ -3040,7 +3040,7 @@ void perform_noise_estimation_dec_ivas_fx( IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && power_spectrum != NULL ) { /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ - periodog = power_spectrum; + periodog = power_spectrum; /*Q_power_spectrum*/ periodog_exp = sub( 31, Q_power_spectrum ); } ELSE @@ -3048,20 +3048,20 @@ void perform_noise_estimation_dec_ivas_fx( /* Compute the squared magnitude in each FFT bin */ IF( startBand == 0 ) { - W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /* DC component */ + W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /* DC component */ /*Q31 - 2*fftBuffer_exp*/ min_q = 2; move16(); ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( i_mult( sub( 31, fftBuffer_exp ), 2 ), min_q ) ) ); move32(); ptr_per++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - fftBuffer_exp*/ } ELSE { - ptr_r = fftBuffer + i_mult( 2, startBand ); + ptr_r = fftBuffer + i_mult( 2, startBand ); /*Q31 - fftBuffer_exp*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ SWITCH( hFdCngDec->hFdCngCom->fftlen ) { @@ -3083,17 +3083,17 @@ void perform_noise_estimation_dec_ivas_fx( FOR( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ ) { - W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); + W_tmp = W_add( W_mult0_32_32( ( *ptr_r ), ( *ptr_r ) ), W_mult0_32_32( ( *ptr_i ), ( *ptr_i ) ) ); /*Q31 - 2*(fftBuffer_exp)*/ - tmp_s = W_norm( W_tmp ); + tmp_s = W_norm( W_tmp ); /*tmp_q*/ tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); IF( tmp_q < 0 ) { - W_tmp = W_shr( W_tmp, negate( tmp_q ) ); + W_tmp = W_shr( W_tmp, negate( tmp_q ) ); /*Q31 - 2*(fftBuffer_exp) + tmp_q*/ } IF( LT_16( tmp_q, min_q ) ) { - reIter = ptr_per; + reIter = ptr_per; /*tmp_q*/ Word16 diff; IF( ( tmp_q <= 0 ) ) { @@ -3107,7 +3107,7 @@ void perform_noise_estimation_dec_ivas_fx( WHILE( reIter > periodog ) { reIter--; - *reIter = L_shr( *reIter, diff ); + *reIter = L_shr( *reIter, diff ); /*tmp_q*/ move32(); } IF( tmp_q >= 0 ) @@ -3150,7 +3150,7 @@ void perform_noise_estimation_dec_ivas_fx( move16(); FOR( p = 0; p < stopFFTbin - startBand; p++ ) { - periodog[p] = L_shl( periodog[p], tmp_s ); + periodog[p] = L_shl( periodog[p], tmp_s ); /*Q31 - hFdCngDec->hFdCngCom->periodog_exp + tmp_s*/ move32(); } } @@ -3245,24 +3245,24 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) invTrfMatrix_fx = (Word32 *) tmpRAM_fx; - sidNoiseEst = st->sidNoiseEst; + sidNoiseEst = st->sidNoiseEst; /*Q31 - st->sidNoiseEstExp*/ move16(); - preemph_fac = corest->preemph_fac; + preemph_fac = corest->preemph_fac; /*Q15*/ move16(); - N = st->npart; + N = st->npart; /*Q0*/ move16(); - st->sid_frame_counter = add( st->sid_frame_counter, 1 ); + st->sid_frame_counter = add( st->sid_frame_counter, 1 ); /*Q15*/ move16(); /* Read bitstream */ FOR( i = 0; i < stages_37bits; i++ ) { - indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); + indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); /*Q0*/ move16(); } - index = get_next_indice_fx( corest, 7 ); + index = get_next_indice_fx( corest, 7 ); /*Q0*/ /* MSVQ decoder */ IF( corest->element_mode != EVS_MONO ) @@ -3282,7 +3282,7 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) FOR( i = 0; i < N; i++ ) { - v[i] = L_deposit_h( v16[i] ); + v[i] = L_deposit_h( v16[i] ); /*Q23*/ move32(); } } @@ -3290,8 +3290,8 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* decode gain, format gain: Q9.23 */ gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); - gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); - gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); + gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); /*Q23*/ + gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); /*Q23*/ /* Apply gain and undo log */ @@ -3300,11 +3300,11 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) maxVal = L_add( 0x80000000 /*-1.0 Q31*/, 0 ); FOR( i = 0; i < N; i++ ) { - maxVal = L_max( maxVal, v[i] ); + maxVal = L_max( maxVal, v[i] ); /*Q23*/ } - maxVal = L_add( maxVal, gain ); - maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); + maxVal = L_add( maxVal, gain ); /*Q23*/ + maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/ sidNoiseEst_Exp = 0; move16(); @@ -3319,25 +3319,25 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* format v: Q9.23, format sidNoiseEst: Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ FOR( i = 0; i < N; i++ ) { - tmp = L_add( v[i], gain ); - tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); + tmp = L_add( v[i], gain ); /*Q23*/ + tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/ tmp = L_sub( tmp, E_ExpLd64 ); assert( tmp < 0 ); - st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); + st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); /*Q31 - st->sidNoiseEstExp*/ move32(); } /* NB last band energy compensation */ IF( st->CngBandwidth == NB ) { - st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], NB_LAST_BAND_SCALE ); + st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/ move32(); } test(); IF( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) ) { - st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE ); + st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/ move32(); } @@ -3374,8 +3374,8 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) #ifdef IVAS_FLOAT_FIXED void noisy_speech_detection_fx( HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ - const Word16 vad, - const Word16 *syn, /* i : input time-domain frame */ + const Word16 vad, /*Q0*/ + const Word16 *syn, /* i : input time-domain frame Q*/ const Word16 Q ) { Word16 i; @@ -3392,7 +3392,7 @@ void noisy_speech_detection_fx( IF( vad == 0 ) { - totalNoise = dotWord32_16_Mant32Exp( hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp ); + totalNoise = dotWord32_16_Mant32Exp( hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp ); /*Q31 - totalNoise_exp*/ /* - logTotalNoise is scaled by LD_DATA_SCALE+2 @@ -3402,16 +3402,16 @@ void noisy_speech_detection_fx( */ IF( totalNoise == 0 ) { - logTotalNoise = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); + logTotalNoise = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); /*Q31*/ } ELSE { - logTotalNoise = BASOP_Util_Log2( totalNoise ); + logTotalNoise = BASOP_Util_Log2( totalNoise ); /*Q25*/ logTotalNoiseExp = L_shl( L_deposit_l( totalNoise_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); - logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); + logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); /*Q31 - logTotalNoiseExp*/ } - hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); + hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_noise*/ move32(); } ELSE @@ -3422,11 +3422,11 @@ void noisy_speech_detection_fx( move16(); FOR( i = 0; i < hFdCngDec->hFdCngCom->frameSize; i++ ) { - tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); + tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); /*2*(Q) - (Etot_exp - 31)*/ IF( LT_32( L_sub( maxWord32, tmp ), Etot ) ) { Etot_exp = add( Etot_exp, 1 ); - Etot = L_shr_r( Etot, 1 ); + Etot = L_shr_r( Etot, 1 ); /*Q31 - Etot_exp*/ tmp = L_shr_r( tmp, 1 ); } Etot = L_add( Etot, tmp ); @@ -3441,32 +3441,32 @@ void noisy_speech_detection_fx( */ IF( Etot == 0 ) { - logEtot = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); + logEtot = L_add( -1677721600l /*-0.78125 Q31*/, 0 ); /*Q31*/ } ELSE { - logEtot = BASOP_Util_Log2( Etot ); + logEtot = BASOP_Util_Log2( Etot ); /*Q25*/ logEtotExp = L_shl( L_deposit_l( Etot_exp ), WORD32_BITS - 1 - LD_DATA_SCALE ); - logEtot = Mpy_32_16_1( L_add( logEtot, logEtotExp ), 24660 /*0.75257498916 Q15*/ ); + logEtot = Mpy_32_16_1( L_add( logEtot, logEtotExp ), 24660 /*0.75257498916 Q15*/ ); /*Q31 - logEtotExp*/ IF( EQ_16( hFdCngDec->hFdCngCom->frameSize, L_FRAME16k ) ) { - logEtot = L_add( logEtot, -184894985l /*-0.086098436822497 Q31*/ ); + logEtot = L_add( logEtot, -184894985l /*-0.086098436822497 Q31*/ ); /*Q31 - logEtotExp*/ } ELSE { - logEtot = L_add( logEtot, -176765584l /*-0.082312889439370 Q31*/ ); + logEtot = L_add( logEtot, -176765584l /*-0.082312889439370 Q31*/ ); /*Q31 - logEtotExp*/ } } - hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); + hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_speech*/ move32(); } - tmp = L_sub( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); + tmp = L_sub( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); /*Q23*/ if ( LT_32( hFdCngDec->lp_noise, tmp ) ) { - hFdCngDec->lp_noise = tmp; + hFdCngDec->lp_noise = tmp; /*Q23*/ move32(); } @@ -3485,13 +3485,13 @@ void noisy_speech_detection_fx( #ifdef IVAS_FLOAT_FIXED void generate_comfort_noise_dec_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st, Word16 *Q_new, - Word16 gen_exc, - const Word16 nchan_out /* i : number of output channels */ + Word16 gen_exc, /*Q0*/ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word16 i, j, s, sc, sn, cnt; @@ -3525,15 +3525,15 @@ void generate_comfort_noise_dec_fx( /* pointer initialization */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); - fftBuffer = hFdCngCom->fftBuffer; + fftBuffer = hFdCngCom->fftBuffer; /*Q31 - hFdCngCom->fftBuffer_exp*/ timeDomainOutput = hFdCngCom->timeDomainBuffer; /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -3557,32 +3557,32 @@ void generate_comfort_noise_dec_fx( /* DC component in FFT */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /*Q31 - s*/ - fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); /* Nyquist frequency is discarded */ fftBuffer[1] = L_deposit_l( 0 ); ptr_level = ptr_level + 1; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - hFdCngCom->fftBuffer_exp*/ cnt = sub( cnt, 1 ); } ELSE { - startBand2 = shl( hFdCngCom->startBand, 1 ); + startBand2 = shl( hFdCngCom->startBand, 1 ); /*Q0*/ set32_fx( fftBuffer, 0, startBand2 ); - ptr_r = fftBuffer + startBand2; + ptr_r = fftBuffer + startBand2; /*Q31 - hFdCngCom->fftBuffer_exp*/ } sn = add( sn, 1 ); - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - hFdCngCom->fftBuffer_exp*/ FOR( i = 0; i < cnt; i++ ) { s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( *ptr_level, sn ), &s ); /*Q31 - s*/ /* Real part in FFT bins */ *ptr_r = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); @@ -3627,16 +3627,16 @@ void generate_comfort_noise_dec_fx( /* calculate the residual signal energy */ /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ - Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); - exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); /*Q31 - exp*/ + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2( Lener ); + Lener = BASOP_Util_Log2( Lener ); /*Q25*/ Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ if ( EQ_16( st->L_frame, L_FRAME16k ) ) { - Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f*/ + Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f Q25*/ } /* decrease the energy in case of WB input */ IF( st->bwidth != NB ) @@ -3646,24 +3646,24 @@ void generate_comfort_noise_dec_fx( IF( st->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); /*Q23*/ } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); /*Q23*/ } } ELSE { - att = 384 << 17; - move16(); /*1.5 Q8<<17=Q25*/ + att = 384 << 17; /*1.5 Q8<<17=Q25*/ + move16(); } - Lener = L_sub( Lener, att ); + Lener = L_sub( Lener, att ); /*Q23*/ } /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2( Lener, 6, &exp ); - Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + Lener = BASOP_util_Pow2( Lener, 6, &exp ); /*Q31 - exp*/ + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); /*Q31 - exp*/ exp = sub( 25, exp ); Lener = L_shr( Lener, exp ); /*Q6*/ st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ @@ -3688,17 +3688,17 @@ void generate_comfort_noise_dec_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } @@ -3726,14 +3726,14 @@ void generate_comfort_noise_dec_fx( seed_loc = hFdCngCom->seed; move16(); - N = hFdCngCom->frameSize; + N = hFdCngCom->frameSize; /*Q0*/ move16(); N2 = shr( hFdCngCom->frameSize, 1 ); IF( st->last_core_bfi > ACELP_CORE ) { Word16 left_overlap_mode; - left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; + left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; /*Q0*/ move16(); if ( EQ_16( left_overlap_mode, ALDO_WINDOW ) ) { @@ -3747,7 +3747,7 @@ void generate_comfort_noise_dec_fx( { FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -3758,7 +3758,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -3780,12 +3780,12 @@ void generate_comfort_noise_dec_fx( lpcorder = M; move16(); - old_Aq = st->old_Aq_12_8_fx; - old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); - old_syn_pe = st->mem_syn2_fx; - old_syn = st->syn[lpcorder]; + old_Aq = st->old_Aq_12_8_fx; /*Q12*/ + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); /*Q_exc*/ + old_syn_pe = st->mem_syn2_fx; /*Q_syn*/ + old_syn = st->syn[lpcorder]; /*Q_syn*/ move16(); - preemph_fac = st->preemph_fac; + preemph_fac = st->preemph_fac; /*Q15*/ move16(); Q_exc = st->Q_exc; move16(); @@ -3802,16 +3802,16 @@ void generate_comfort_noise_dec_fx( normShiftEM1 = sub( normShiftE, 1 ); normShiftP2 = add( normShiftE, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); + old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); /*2*(Q_exc)+1+normShiftP2*/ FOR( i = 1; i < N2; i++ ) { - old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); + old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); /*2*(Q_exc)+1+normShiftP2*/ } - old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); + old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); /*Q31*/ old_exc_ener_exp = 0; move16(); - old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); + old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); /*Q31 - old_exc_ener_exp*/ old_exc_ener_exp = add( old_exc_ener_exp, ( sub( 15, Q_exc ) ) ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -3832,14 +3832,14 @@ void generate_comfort_noise_dec_fx( move16(); gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); } - gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); + gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); /*Q31 - gain_exp*/ gain_exp = 2 * CNG_RAND_GAUSS_SHIFT; move16(); - gain = ISqrt32( gain, &gain_exp ); + gain = ISqrt32( gain, &gain_exp ); /*Q31 - gain_exp*/ - gain = Mpy_32_32( old_exc_ener, gain ); - gain16 = extract_h( gain ); + gain = Mpy_32_32( old_exc_ener, gain ); /*Q31 - old_exc_ener_exp - gain_exp*/ + gain16 = extract_h( gain ); /*Q15 - old_exc_ener_exp - gain_exp*/ gain_exp = add( old_exc_ener_exp, gain_exp ); noiseExp = add( CNG_RAND_GAUSS_SHIFT, gain_exp ); @@ -3848,7 +3848,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < N; i++ ) { #ifdef BASOP_NOGLOB - noise[i] = shr_sat( mult( noise[i], gain16 ), s ); + noise[i] = shr_sat( mult( noise[i], gain16 ), s ); /*Q15 - noiseExp*/ #else noise[i] = shr( mult( noise[i], gain16 ), s ); #endif @@ -3861,7 +3861,7 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < lpcorder; i++ ) { #ifdef BASOP_NOGLOB - old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); + old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); /*Q0*/ #else old_syn_pe_tmp[i] = shr( old_syn_pe[i], s ); #endif @@ -3892,11 +3892,11 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < N4; i++ ) { - tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); /*Q15 - noiseExp*/ timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); - timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); + tmp = mult( noise[( i + N4 )], hFdCngCom->olapWinSyn[( ( N4 - 1 ) - i )].v.im ); /*Q15 - noiseExp*/ + timeDomainOutput[( i + N4 )] = add( timeDomainOutput[( i + N4 )], tmp ); move16(); } } @@ -3904,13 +3904,13 @@ void generate_comfort_noise_dec_fx( } void generate_comfort_noise_dec_ivas_fx( - Word32 **bufferReal, /* o : Real part of input bands */ - Word32 **bufferImag, /* o : Imaginary part of input bands */ + Word32 **bufferReal, /* o : Real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : Imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st, /* i/o: decoder state structure */ Word16 *Q_new, - Word16 gen_exc, - const Word16 nchan_out /* i : number of output channels */ + Word16 gen_exc, /*Q0*/ + const Word16 nchan_out /* i : number of output channels Q0*/ ) { Word16 i, j, s; @@ -3927,7 +3927,7 @@ void generate_comfort_noise_dec_ivas_fx( Word16 c1, c2; Word32 tmp1, tmp2; Word16 scaleCldfb; - Word32 *fftBuffer = hFdCngCom->fftBuffer; + Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/ Word16 fftBuffer_exp = hFdCngCom->fftBuffer_exp; Word16 fftBuffer_temp_exp[FFTLEN]; Word16 *timeDomainOutput = hFdCngCom->timeDomainBuffer; @@ -3944,19 +3944,19 @@ void generate_comfort_noise_dec_ivas_fx( hTcxDec = st->hTcxDec; - scaleCldfb = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCldfb = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ temp = 0; move16(); - c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); - c1 = shl( c1, temp ); + c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); /*Q15 - temp*/ + c1 = shl( c1, temp ); /*Q15*/ temp = 0; move16(); - c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); - c2 = shl( c2, temp ); + c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); /*Q15 - temp*/ + c2 = shl( c2, temp ); /*Q15*/ temp = getScaleFactor32( fftBuffer, FFTLEN ); - scale_sig32( fftBuffer, FFTLEN, temp ); + scale_sig32( fftBuffer, FFTLEN, temp ); /*Q31 - hFdCngCom->fftBuffer_exp + temp*/ fftBuffer_exp = sub( fftBuffer_exp, temp ); hFdCngCom->fftBuffer_exp = fftBuffer_exp; move16(); @@ -3982,7 +3982,7 @@ void generate_comfort_noise_dec_ivas_fx( { rand_gauss_fx( &tmp1, seed, Q15 ); rand_gauss_fx( &tmp2, seed2, Q15 ); - fftBuffer[0] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + fftBuffer[0] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q0*/ move32(); fftBuffer_temp_exp[0] = Q16 + Q15; move16(); @@ -3995,13 +3995,13 @@ void generate_comfort_noise_dec_ivas_fx( } sqrtNoiseLevel_exp = cngNoiseLevel_exp; move16(); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqrtNoiseLevel ); /*Q31 - (sqrtNoiseLevel_exp + fftBuffer_temp_exp[0])*/ move32(); fftBuffer_temp_exp[0] = add( sqrtNoiseLevel_exp, fftBuffer_temp_exp[0] ); move16(); ptr_level++; - ptr_r = fftBuffer + 2; + ptr_r = fftBuffer + 2; /*Q31 - (fftBuffer_temp_exp)*/ idx = 2; } ELSE @@ -4009,11 +4009,11 @@ void generate_comfort_noise_dec_ivas_fx( fftBuffer[0] = 0; move16(); set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); - ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); - idx = shl( hFdCngCom->startBand, 1 ); + ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); /*Q31 - fftBuffer_exp*/ + idx = shl( hFdCngCom->startBand, 1 ); /*Q0*/ } - ptr_i = ptr_r + 1; + ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { /* Real part in FFT bins */ @@ -4021,23 +4021,23 @@ void generate_comfort_noise_dec_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); fftBuffer_temp_exp[idx] = Q16; move16(); } ELSE { - rand_gauss_fx( ptr_r, seed, Q15 ); + rand_gauss_fx( ptr_r, seed, Q15 ); /*Q15*/ fftBuffer_temp_exp[idx] = Q16; move16(); } sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ move32(); fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); move16(); @@ -4049,22 +4049,22 @@ void generate_comfort_noise_dec_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); fftBuffer_temp_exp[idx] = Q16; move16(); } ELSE { - rand_gauss_fx( ptr_i, seed, Q15 ); + rand_gauss_fx( ptr_i, seed, Q15 ); /*Q15*/ fftBuffer_temp_exp[idx] = Q16; move16(); } sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); - ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ + ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ move32(); fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); move16(); @@ -4097,7 +4097,7 @@ void generate_comfort_noise_dec_ivas_fx( fftBuffer_exp = sub( 31, fftBuffer_exp ); FOR( i = 0; i < FFTLEN; i++ ) { - fftBuffer[i] = L_shr( fftBuffer[i], sub( fftBuffer_exp, fftBuffer_temp_exp[i] ) ); + fftBuffer[i] = L_shr( fftBuffer[i], sub( fftBuffer_exp, fftBuffer_temp_exp[i] ) ); /*Q31 - fftBuffer_temp_exp[i]*/ move32(); } @@ -4119,7 +4119,7 @@ void generate_comfort_noise_dec_ivas_fx( /* Perform STFT synthesis */ SynthesisSTFT_ivas_fx( fftBuffer, fftBuffer_exp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out ); - scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); + scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); /*Q31 - fftBuffer_exp*/ { Word32 Lener, att; @@ -4128,12 +4128,12 @@ void generate_comfort_noise_dec_ivas_fx( /* calculate the residual signal energy */ /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ - Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); - exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); /*Q31 - exp*/ + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2( Lener ); + Lener = BASOP_Util_Log2( Lener ); /*Q25*/ Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ if ( EQ_16( st->L_frame, L_FRAME16k ) ) { @@ -4147,24 +4147,24 @@ void generate_comfort_noise_dec_ivas_fx( IF( st->CNG_mode >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); /*Q25*/ } ELSE { /* Use least attenuation for higher bitrates */ - att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); /*Q25*/ } } ELSE { - att = 384 << 17; - move16(); /*1.5 Q8<<17=Q25*/ + att = 384 << 17; /*1.5 Q8<<17=Q25*/ + move16(); } Lener = L_sub( Lener, att ); } /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2( Lener, 6, &exp ); - Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + Lener = BASOP_util_Pow2( Lener, 6, &exp ); /*Q31 - exp*/ + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); /*Q31 - exp*/ exp = sub( 25, exp ); Lener = L_shr( Lener, exp ); /*Q6*/ st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ @@ -4184,29 +4184,29 @@ void generate_comfort_noise_dec_ivas_fx( FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { sqrtNoiseLevel_exp = add( CLDFBinvScalingFactor_EXP, sub( cngNoiseLevel_exp, 1 ) ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *ptr_level, scaleCldfb ), &sqrtNoiseLevel_exp ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *ptr_level, scaleCldfb ), &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); bufferReal_exp[j] = Q16; move16(); } ELSE { - rand_gauss_fx( &bufferReal[i][j], seed, Q15 ); + rand_gauss_fx( &bufferReal[i][j], seed, Q15 ); /*Q15*/ move32(); bufferReal_exp[j] = Q16; move16(); } - bufferReal[i][j] = Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ); + bufferReal[i][j] = Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ); /*Q31 - ( bufferReal_exp[j] + sqrtNoiseLevel_exp )*/ move32(); bufferReal_exp[j] = add( bufferReal_exp[j], sqrtNoiseLevel_exp ); move16(); @@ -4214,20 +4214,20 @@ void generate_comfort_noise_dec_ivas_fx( /* Imaginary part in CLDFB band */ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) { - rand_gauss_fx( &tmp1, seed, Q15 ); - rand_gauss_fx( &tmp2, seed2, Q15 ); - bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ + rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ + bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ move32(); bufferImag_exp[j] = Q16; move16(); } ELSE { - rand_gauss_fx( &bufferImag[i][j], seed, Q15 ); + rand_gauss_fx( &bufferImag[i][j], seed, Q15 ); /*Q15*/ bufferImag_exp[j] = Q16; move16(); } - bufferImag[i][j] = Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ); + bufferImag[i][j] = Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ); /*Q31 - ( bufferReal_exp[j] + sqrtNoiseLevel_exp )*/ bufferImag_exp[j] = add( bufferImag_exp[j], sqrtNoiseLevel_exp ); move16(); @@ -4248,9 +4248,9 @@ void generate_comfort_noise_dec_ivas_fx( { FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { - bufferImag[i][j] = L_shr( bufferImag[i][j], sub( *bufferScale, bufferImag_exp[j] ) ); + bufferImag[i][j] = L_shr( bufferImag[i][j], sub( *bufferScale, bufferImag_exp[j] ) ); /*bufferImag_exp*/ move32(); - bufferReal[i][j] = L_shr( bufferReal[i][j], sub( *bufferScale, bufferReal_exp[j] ) ); + bufferReal[i][j] = L_shr( bufferReal[i][j], sub( *bufferScale, bufferReal_exp[j] ) ); /*bufferReal_exp*/ move32(); } } @@ -4271,9 +4271,9 @@ void generate_comfort_noise_dec_ivas_fx( assert( hFdCngCom->frameSize <= 640 ); - seed_loc = hFdCngCom->seed; + seed_loc = hFdCngCom->seed; /*Q0*/ move16(); - N = hFdCngCom->frameSize; + N = hFdCngCom->frameSize; /*Q0*/ move16(); N2 = shr( hFdCngCom->frameSize, 1 ); @@ -4294,7 +4294,7 @@ void generate_comfort_noise_dec_ivas_fx( { FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -4305,7 +4305,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); /*st->q_old_outLB_fx*/ move16(); } } @@ -4327,12 +4327,12 @@ void generate_comfort_noise_dec_ivas_fx( lpcorder = M; move16(); - old_Aq = st->old_Aq_12_8_fx; - old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); - old_syn_pe = st->mem_syn2_fx; - old_syn = st->syn[lpcorder]; + old_Aq = st->old_Aq_12_8_fx; /*Q12*/ + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); /*Q_exc*/ + old_syn_pe = st->mem_syn2_fx; /*Q_syn*/ + old_syn = st->syn[lpcorder]; /*Q_syn*/ move16(); - preemph_fac = st->preemph_fac; + preemph_fac = st->preemph_fac; /*Q15*/ move16(); Q_exc = st->Q_exc; move16(); @@ -4349,16 +4349,16 @@ void generate_comfort_noise_dec_ivas_fx( normShiftEM1 = sub( normShiftE, 1 ); normShiftP2 = add( normShiftE, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); - old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); + old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); /*2*(Q_exc)+1+normShiftP2*/ FOR( i = 1; i < N2; i++ ) { - old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); + old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); /*2*(Q_exc)+1+normShiftP2*/ } - old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); + old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); /*Q31*/ old_exc_ener_exp = 0; move16(); - old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); + old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); /*Q31 - old_exc_ener_exp*/ old_exc_ener_exp = add( old_exc_ener_exp, ( sub( 15, Q_exc ) ) ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -4379,14 +4379,14 @@ void generate_comfort_noise_dec_ivas_fx( move16(); gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); } - gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); + gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); /*Q31 - gain_exp*/ gain_exp = 2 * CNG_RAND_GAUSS_SHIFT; move16(); - gain = ISqrt32( gain, &gain_exp ); + gain = ISqrt32( gain, &gain_exp ); /*Q31 - gain_exp*/ - gain = Mpy_32_32( old_exc_ener, gain ); - gain16 = extract_h( gain ); + gain = Mpy_32_32( old_exc_ener, gain ); /*Q31 - old_exc_ener_exp - gain_exp*/ + gain16 = extract_h( gain ); /*Q15 - old_exc_ener_exp - gain_exp*/ gain_exp = add( old_exc_ener_exp, gain_exp ); noiseExp = add( CNG_RAND_GAUSS_SHIFT, gain_exp ); @@ -4395,7 +4395,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < N; i++ ) { #ifdef BASOP_NOGLOB - noise[i] = shr_sat( mult( noise[i], gain16 ), s ); + noise[i] = shr_sat( mult( noise[i], gain16 ), s ); /*Q15 - noiseExp*/ #else noise[i] = shr( mult( noise[i], gain16 ), s ); #endif @@ -4408,7 +4408,7 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < lpcorder; i++ ) { #ifdef BASOP_NOGLOB - old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); + old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); /*Q0*/ #else old_syn_pe_tmp[i] = shr( old_syn_pe[i], s ); #endif @@ -4439,11 +4439,11 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < N4; i++ ) { - tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); /*Q15 - noiseExp*/ timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); - timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); + tmp = mult( noise[( i + N4 )], hFdCngCom->olapWinSyn[( ( N4 - 1 ) - i )].v.im ); /*Q15 - noiseExp*/ + timeDomainOutput[( i + N4 )] = add( timeDomainOutput[( i + N4 )], tmp ); move16(); move16(); } @@ -4453,8 +4453,8 @@ void generate_comfort_noise_dec_ivas_fx( } void generate_comfort_noise_dec_hf_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ Decoder_State *st ) { @@ -4468,14 +4468,14 @@ void generate_comfort_noise_dec_hf_fx( Word32 *ptr_level; HANDLE_FD_CNG_COM hFdCngCom = st->hFdCngDec->hFdCngCom; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ sn = 0; move16(); @@ -4500,21 +4500,21 @@ void generate_comfort_noise_dec_hf_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ } - ptr_level = ptr_level + 1; + ptr_level = ptr_level + 1; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ } *bufferScale = sub( sc, 15 ); move16(); @@ -4522,11 +4522,11 @@ void generate_comfort_noise_dec_hf_fx( } void generate_comfort_noise_dec_hf_ivas_fx( - Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word32 **bufferReal, /* o : matrix to real part of input bands bufferScale*/ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands bufferScale*/ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 cng_coh_flag /* i : CNG Flag for coherence handling */ + const Word16 cng_coh_flag /* i : CNG Flag for coherence handling Q0*/ ) { Word16 i, j, s, sc, sn; @@ -4541,15 +4541,15 @@ void generate_comfort_noise_dec_hf_ivas_fx( Word32 *cngNoiseLevel; Word32 tmp1, tmp2; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q31 - hFdCngCom->cngNoiseLevelExp*/ cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + scaleCLDFB = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); /*CLDFBinvScalingFactor_EXP + 1*/ seed2 = &( hFdCngCom->seed ); @@ -4567,13 +4567,13 @@ void generate_comfort_noise_dec_hf_ivas_fx( s = 0; move16(); - c1 = Sqrt16( hFdCngCom->coherence_fx, &s ); - c1 = shl( c1, s ); // Q15 + c1 = Sqrt16( hFdCngCom->coherence_fx, &s ); /*Q15 - s*/ + c1 = shl( c1, s ); // Q15 s = 0; move16(); - c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx ), &s ); - c2 = shl( c2, s ); // Q15 + c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx ), &s ); /*Q15 - s*/ + c2 = shl( c2, s ); // Q15 } sn = 0; @@ -4605,38 +4605,38 @@ void generate_comfort_noise_dec_hf_ivas_fx( /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); - sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); + sqrtNoiseLevel = Sqrt32( L_shr( Mpy_32_16_1( *ptr_level, scaleCLDFB ), sn ), &s ); /*Q31 - s*/ IF( cng_coh_flag ) { - rand_gauss_fx( &tmp1, seed, Q28 ); - rand_gauss_fx( &tmp2, seed2, Q28 ); + rand_gauss_fx( &tmp1, seed, Q28 ); /*Q28*/ + rand_gauss_fx( &tmp2, seed2, Q28 ); /*Q28*/ - bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*bufferScale*/ move32(); - bufferReal[i][j] = L_shl( Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); - rand_gauss_fx( &tmp1, seed, Q28 ); - rand_gauss_fx( &tmp2, seed2, Q28 ); + rand_gauss_fx( &tmp1, seed, Q28 ); /*Q28*/ + rand_gauss_fx( &tmp2, seed2, Q28 ); /*Q28*/ - bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*bufferScale*/ move32(); - bufferImag[i][j] = L_shl( Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); } ELSE { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); /*bufferScale*/ move32(); } } - ptr_level = ptr_level + 1; + ptr_level = ptr_level + 1; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ } *bufferScale = sub( sc, 15 ); move16(); @@ -4669,8 +4669,8 @@ void generate_masking_noise_fx( Word16 Q, HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ , - Word16 length, - Word16 core ) + Word16 length, /*Q0*/ + Word16 core /*Q0*/ ) { Word16 i, s, s1, s2, sq, cnt, startBand2, stopFFTbin2; Word16 scaleExp, fftBufferExp, cngNoiseLevelExp; @@ -4684,8 +4684,8 @@ void generate_masking_noise_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; - fftBuffer = hFdCngCom->fftBuffer; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ + fftBuffer = hFdCngCom->fftBuffer; /*Q31 - hFdCngCom->fftBuffer_exp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -4707,7 +4707,7 @@ void generate_masking_noise_fx( IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) { - scale = scaleTable_cn_only[i].scale; + scale = scaleTable_cn_only[i].scale; /*Q14*/ move16(); BREAK; } @@ -4726,7 +4726,7 @@ void generate_masking_noise_fx( { IF( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only_amrwbio[i][0] ) ) { - scale = scaleTable_cn_only_amrwbio[i][1]; + scale = scaleTable_cn_only_amrwbio[i][1]; /*Q14*/ move16(); BREAK; } @@ -4740,7 +4740,7 @@ void generate_masking_noise_fx( /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub( 1, add( s1, s2 ) ); - scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); /*Q15 - scaleExp*/ { /* add exponent of scale and cngNoiseLevel */ @@ -4756,7 +4756,7 @@ void generate_masking_noise_fx( /* consider scaling of random noise */ fftBufferExp = add( fftBufferExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin @@ -4769,8 +4769,8 @@ void generate_masking_noise_fx( /* -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( 0, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); - hFdCngCom->fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ + hFdCngCom->fftBuffer[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*q31 - hFdCngCom->fftBuffer_exp*/ move32(); hFdCngCom->fftBuffer[1] = 0; move32(); @@ -4784,26 +4784,26 @@ void generate_masking_noise_fx( { startBand2 = shl( hFdCngCom->startBand, 1 ); set32_fx( hFdCngCom->fftBuffer, 0, startBand2 ); - fftBuffer = hFdCngCom->fftBuffer + startBand2; + fftBuffer = hFdCngCom->fftBuffer + startBand2; /*Q31 - hFdCngCom->fftBuffer_exp*/ } FOR( i = 0; i < cnt; i++ ) { /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); fftBuffer++; /* imaginary part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *fftBuffer = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q31 - hFdCngCom->fftBuffer_exp*/ move32(); fftBuffer++; @@ -4827,7 +4827,7 @@ void generate_masking_noise_fx( { FOR( i = 0; i < length; i++ ) { - timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); + timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); /*Q0*/ move16(); } } @@ -4836,7 +4836,7 @@ void generate_masking_noise_fx( FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { #ifdef BASOP_NOGLOB - timeDomainBuffer[i] = add_sat( timeDomainBuffer[i], shr_r_sat( maskingNoise[i], -Q ) ); + timeDomainBuffer[i] = add_sat( timeDomainBuffer[i], shr_r_sat( maskingNoise[i], -Q ) ); /*Q0*/ #else timeDomainBuffer[i] = add( timeDomainBuffer[i], shr_r( maskingNoise[i], -Q ) ); #endif @@ -4865,18 +4865,18 @@ void generate_masking_noise_update_seed_fx( /* pointer initializations */ seed = &( hFdCngCom->seed ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ IF( hFdCngCom->startBand == 0 ) { - rand_gauss( seed ); + rand_gauss( seed ); /*Q15*/ cnt = sub( cnt, 1 ); } FOR( i = 0; i < cnt; i++ ) { - rand_gauss( seed ); - rand_gauss( seed ); + rand_gauss( seed ); /*Q15*/ + rand_gauss( seed ); /*Q15*/ } @@ -4889,7 +4889,7 @@ void generate_masking_noise_update_seed_fx( ************************************************************/ #ifdef IVAS_FLOAT_FIXED void generate_masking_noise_mdct_fx( - Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word32 *mdctBuffer, /* i/o: time-domain signal Q31 - mdctBuffer_e*/ Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ , @@ -4907,7 +4907,7 @@ void generate_masking_noise_mdct_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -4927,7 +4927,7 @@ void generate_masking_noise_mdct_fx( test(); IF( ( EQ_16( hFdCngCom->CngBandwidth, scaleTable_cn_only[i].bwmode ) ) && ( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateFrom ) ) && ( LT_32( hFdCngCom->CngBitrate, scaleTable_cn_only[i].bitrateTo ) ) ) { - scale = scaleTable_cn_only[i].scale; + scale = scaleTable_cn_only[i].scale; /*Q14*/ move16(); BREAK; } @@ -4940,7 +4940,7 @@ void generate_masking_noise_mdct_fx( /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub( 1, add( s1, s2 ) ); - scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); + scale = mult_r( shl( scale, s1 ), shl( hFdCngCom->likelihood_noisy_speech, s2 ) ); /*Q15 - scaleExp*/ /* add exponent of scale and cngNoiseLevel */ maskingNoiseExp = add( scaleExp, cngNoiseLevelExp ); @@ -4955,7 +4955,7 @@ void generate_masking_noise_mdct_fx( /* consider scaling of random noise */ maskingNoiseExp = add( maskingNoiseExp, CNG_RAND_GAUSS_SHIFT ); - cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + cnt = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); /*Q0*/ /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -4969,11 +4969,11 @@ void generate_masking_noise_mdct_fx( /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); - maskingNoise[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ + maskingNoise[0] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q15*/ move32(); - pMaskingNoise = &maskingNoise[1]; + pMaskingNoise = &maskingNoise[1]; /*Q15*/ cngNoiseLevel++; cnt = sub( cnt, 1 ); @@ -4981,19 +4981,19 @@ void generate_masking_noise_mdct_fx( ELSE { set32_fx( maskingNoise, 0, hFdCngCom->startBand ); - pMaskingNoise = maskingNoise + hFdCngCom->startBand; + pMaskingNoise = maskingNoise + hFdCngCom->startBand; /*Q15*/ } FOR( i = 0; i < cnt; i++ ) { /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ sq = sub( -1, s ); - sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *cngNoiseLevel, scale ), &sq ); /*Q31 - sq*/ /* real part in FFT bins */ /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *pMaskingNoise = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); + *pMaskingNoise = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), sq ); /*Q15*/ move32(); pMaskingNoise++; @@ -5022,14 +5022,14 @@ void generate_masking_noise_mdct_fx( { /* If shifting negative noise values the lowest result is -1 but never 0. Shift positive noise values to avoid unwanted amplification of these small values later */ - noise = L_shr( Mpy_32_16_1( L_abs( maskingNoise[i] ), 25905 /*0.79056941504 Q15*/ ), s2 ); + noise = L_shr( Mpy_32_16_1( L_abs( maskingNoise[i] ), 25905 /*0.79056941504 Q15*/ ), s2 ); /*Q31 - maskingNoiseExp - s2*/ if ( maskingNoise[i] < 0 ) { noise = L_negate( noise ); } - mdctBuffer[i] = L_add( mdctBuffer[i], noise ); + mdctBuffer[i] = L_add( mdctBuffer[i], noise ); /*Q31 - s*/ move32(); } } @@ -5038,12 +5038,12 @@ void generate_masking_noise_mdct_fx( FOR( i = 0; i < hFdCngCom->stopFFTbin; i++ ) { mdctBuffer[i] = L_add( L_shr( mdctBuffer[i], s1 ), - Mpy_32_16_1( maskingNoise[i], 25905 /*0.79056941504 Q15*/ ) ); + Mpy_32_16_1( maskingNoise[i], 25905 /*0.79056941504 Q15*/ ) ); /*Q31 - s*/ move32(); } FOR( i = hFdCngCom->stopFFTbin; i < L_frame; i++ ) { - mdctBuffer[i] = L_shr( mdctBuffer[i], s1 ); + mdctBuffer[i] = L_shr( mdctBuffer[i], s1 ); /*Q31 - s*/ move32(); } *mdctBuffer_e = s; @@ -5053,7 +5053,7 @@ void generate_masking_noise_mdct_fx( } void generate_masking_noise_mdct_ivas_fx( - Word32 *mdctBuffer, /* i/o: time-domain signal */ + Word32 *mdctBuffer, /* i/o: time-domain signal Q31 - mdctBuffer_e*/ Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ) { @@ -5068,7 +5068,7 @@ void generate_masking_noise_mdct_ivas_fx( // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); /* Compute additional CN level */ @@ -5109,21 +5109,21 @@ void generate_masking_noise_mdct_ivas_fx( sq = cngNoiseLevelExp; move16(); - sqrtNoiseLevel = Sqrt32( temp, &sq ); + sqrtNoiseLevel = Sqrt32( temp, &sq ); /*Q31 - sq*/ rand_gauss_fx( &temp, seed, Q15 ); // Q15 maskingNoise[0] = L_shl( Mpy_32_32( temp, sqrtNoiseLevel ), sq ); // Q15 move32(); - pMaskingNoise = &maskingNoise[1]; + pMaskingNoise = &maskingNoise[1]; /*Q15*/ cngNoiseLevel++; cnt = sub( cnt, 1 ); } ELSE { set32_fx( maskingNoise, 0, hFdCngCom->startBand ); - pMaskingNoise = maskingNoise + hFdCngCom->startBand; + pMaskingNoise = maskingNoise + hFdCngCom->startBand; /*Q15*/ } FOR( i = 0; i < cnt; i++ ) @@ -5134,7 +5134,7 @@ void generate_masking_noise_mdct_ivas_fx( sq = cngNoiseLevelExp; move16(); - sqrtNoiseLevel = Sqrt32( temp, &sq ); + sqrtNoiseLevel = Sqrt32( temp, &sq ); /*Q31 - sq*/ rand_gauss_fx( &temp, seed, Q15 ); // Q15 diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index d39efad140658f5dd275b88467cf8efa54d62811..3dee5f2bc9bba69b80a84795b0500ba53f9e5ee2 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -251,11 +251,6 @@ void core_coder_mode_switch_ivas_fx( { me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); } - IF( st->igf && st->hIGFEnc != NULL ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, N_MAX_TCX - IGF_START_MN ); - } #endif } diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index 33c3201b0aff379e049862561df6aaf387dc51da..2a594cd18d6eb13d4216d10aa737563aa655164a 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -527,58 +527,19 @@ void core_signal_analysis_high_bitrate( q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[frameno], hTcxEnc->L_frameTCX / nSubframes ); if ( st->hIGFEnc ) { - q_spectrum = min( q_spectrum, L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ) ); + q_spectrum = min( q_spectrum, 31 - st->hIGFEnc->spec_be_igf_e ); } floatToFixed_arrL32( hTcxEnc->spectrum[frameno], hTcxEnc->spectrum_fx[frameno], q_spectrum, hTcxEnc->L_frameTCX / nSubframes ); - if ( st->hIGFEnc ) - { - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, st->hIGFEnc->infoStopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } Word32 powerSpec_fx[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ Word16 q_powerSpec; q_powerSpec = L_get_q_buf1( powerSpec, L_subframe ); floatToFixed_arrL32( powerSpec, powerSpec_fx, q_powerSpec, L_subframe ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); - } - - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; #endif ProcessIGF_ivas_fx( st, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_fx[frameno], &q_spectrum, powerSpec_fx, &q_powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum[frameno], q_spectrum, hTcxEnc->L_frameTCX / nSubframes ); fixedToFloat_arrL32( powerSpec_fx, powerSpec, q_powerSpec, L_subframe ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); - } - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } #endif #else ProcessIGF( st, hTcxEnc->spectrum[frameno], hTcxEnc->spectrum[frameno], powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index a78e88139c33d75d42d6cd4994cda921fd784b58..52ca1a022b5d36afb6b7c5a51217f6aed58ef105 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -3672,23 +3672,6 @@ static int16_t IGF_WriteFlatteningTrigger( * updates the start/stop frequency of IGF according to igfGridIdx *-------------------------------------------------------------------*/ -static void IGF_UpdateInfo_ivas( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - const int16_t igfGridIdx /* i : IGF grid index */ -) -{ - H_IGF_GRID hGrid; - - hGrid = &hIGFEnc->igfData.igfInfo.grid[igfGridIdx]; - hIGFEnc->infoStartFrequency = hGrid->startFrequency; - hIGFEnc->infoStopFrequency = hGrid->stopFrequency; - hIGFEnc->infoStartLine = hGrid->startLine; - hIGFEnc->infoStopLine = hGrid->stopLine; - - return; -} - - /*-------------------------------------------------------------------* * IGFEncWriteBitstream() * @@ -3798,11 +3781,6 @@ void IGFEncSetMode( set_s( hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES ); set_s( hPrivateData->igfWhiteningHangoverCnt, 0, IGF_MAX_TILES ); - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - set_f( hPrivateData->igfPastSFM[i], -1.f, IGF_PAST_SFM_LEN ); - } - hPrivateData->igfPastSFM_pos = 0; for ( i = 0; i < IGF_BITBUFSIZE / 8; i++ ) @@ -3811,21 +3789,12 @@ void IGFEncSetMode( } hPrivateData->wasTransient = 0; - set_f( hPrivateData->prevSFM_FIR_flt, 0, IGF_MAX_TILES ); - set_f( hPrivateData->prevSFM_IIR_flt, 0, IGF_MAX_TILES ); set_s( hPrivateData->dampingFactorSmoothing, 2, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_FIR_SFB_SB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_IIR_SFB_SB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_FIR_SFB_TB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevSFM_IIR_SFB_TB, 0, IGF_MAX_SFB ); - set_f( hPrivateData->prevDampingFactor_IIR, -1, IGF_MAX_SFB ); #ifdef IVAS_FLOAT_FIXED set_s( hPrivateData->prevDampingFactor_IIR_fx, MIN16B, IGF_MAX_SFB ); set_s( hPrivateData->prevDampingFactor_IIR_e, 0, IGF_MAX_SFB ); #endif set_s( hPrivateData->logSpec, 0, L_FRAME_PLUS ); - set_f( hPrivateData->SFM_sb, 0.f, IGF_MAX_SFB ); - set_f( hPrivateData->SFM_tb, 0.f, IGF_MAX_SFB ); #ifndef IVAS_FLOAT_FIXED if ( IGFCommonFuncsIGFConfiguration_flt( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) @@ -3856,8 +3825,6 @@ void IGFEncSetMode( hIGFEnc->infoTotalBitsWritten = 0; hIGFEnc->infoTotalBitsPerFrameWritten = 0; hIGFEnc->flatteningTrigger = 0; - hIGFEnc->tns_predictionGain_flt = 0; - set_f( hIGFEnc->spec_be_igf_flt, 0, N_MAX_TCX - IGF_START_MN ); return; } @@ -4488,18 +4455,6 @@ void IGFSaveSpectrumForITF_ivas_fx( return; } #endif -void IGFSaveSpectrumForITF( - IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ - const int16_t igfGridIdx, /* i : IGF grid index */ - const float *pITFSpectrum /* i : MDCT spectrum */ -) -{ - IGF_UpdateInfo_ivas( hIGFEnc, igfGridIdx ); - - mvr2r( pITFSpectrum + IGF_START_MN, hIGFEnc->spec_be_igf_flt, hIGFEnc->infoStopLine - IGF_START_MN ); - - return; -} #ifndef IVAS_FLOAT_FIXED ivas_error IGF_Reconfig( diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index d8bccaa0517bd461d427bb10be7ddc4044960d46..acf99f33d3eddd995db09e5508b7e5a22fe29dc4 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -2301,11 +2301,6 @@ ivas_error init_encoder_ivas_fx( { me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); } - IF( st->igf && st->hIGFEnc != NULL ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, N_MAX_TCX - IGF_START_MN ); - } #endif /*-----------------------------------------------------------------* * FD-CNG encoder diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index c36c6eabd7e89d7dca577740b5e8f8e497a545c0..c7b25cee85e2ddd64ce3111a45450c9f20b59bd1 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -507,7 +507,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( Word16 len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing; Word32 input_buff_fx[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; - FOR( int i = 0; i < MCT_MAX_BLOCKS; i++ ) + FOR( Word32 i = 0; i < MCT_MAX_BLOCKS; i++ ) { set32_fx( input_buff_fx[i], 0, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ); } @@ -525,6 +525,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; + move32(); len_inp_memory = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 580ac60a8b663af4b2ba3b68d7f5f3b02c72ad81..17cc8661bcade684ed7c402bc3559b0b29be6e8c 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -1141,7 +1141,7 @@ ivas_error ivas_enc( ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - IF( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 0671e2f3f6e17c20757b32a325e6930f99b302dd..335ef7b9113742f5eb859c2bc7f2d8ca849b955c 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -544,6 +544,7 @@ void ivas_mc_paramupmix_enc_close( Word16 i, k; Word16 b, j; + test(); IF( hMCParamUpmix == NULL || *hMCParamUpmix == NULL ) { return; diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index fa699e0afa0e4918b625c7f9c9a9d85d6de557fd..92ceb710a64962f5e80c766e72050eb799c08cc8 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -906,13 +906,14 @@ ivas_error ivas_mcmasa_enc_reconfig_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - int32_t ivas_total_brate; + Word32 ivas_total_brate; ivas_error error; error = IVAS_ERR_OK; move32(); ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) { diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 07379e99caf636afa17c1a2ccde15475ac2f4590..51aff96df92d2fbac8dbed8c320f221435f464bd 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -51,7 +51,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static ivas_error ivas_mc_enc_reconfig( Encoder_Struct *st_ivas, const int16_t last_mc_mode ); +static ivas_error ivas_mc_enc_reconfig_fx( Encoder_Struct *st_ivas, const Word16 last_mc_mode ); /*-------------------------------------------------------------------* @@ -621,7 +621,6 @@ ivas_error ivas_mct_enc( Encoder_State *sts_tmp[MCT_MAX_CHANNELS]; Encoder_State *st; Word16 i; - IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS]; nCPE = shr( hMCT->nchan_out_woLFE, 1 ); // nChannels / CPE_CHANNELS /*in case of odd number of channels*/ @@ -676,43 +675,6 @@ ivas_error ivas_mct_enc( } } } - for ( int b = 0; b < hMCT->nchan_out_woLFE; b++ ) - { - st = sts_tmp[b]; - if ( st->hIGFEnc ) - { - ch = 0; - hIGFEnc[ch] = st->hIGFEnc; - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - - hPrivateData = &hIGFEnc[ch]->igfData; - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - for ( int k = 0; k < IGF_MAX_TILES; k++ ) - { - hPrivateData->prevSFM_FIR_flt[k] = fixedToFloat( hPrivateData->prevSFM_FIR[k], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[k] = fixedToFloat( hPrivateData->prevSFM_IIR[k], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[k][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[k][j], 13 ); - } - } - } - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, N_MAX_TCX - IGF_START_MN ); - } - } #endif /* Spectrum quantization and coding */ @@ -1533,7 +1495,7 @@ void ivas_mct_enc_close( * - reconfigure the MC format encoder *-------------------------------------------------------------------------*/ -ivas_error ivas_mc_enc_config( +ivas_error ivas_mc_enc_config_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { @@ -1542,24 +1504,32 @@ ivas_error ivas_mc_enc_config( ivas_error error; error = IVAS_ERR_OK; + move32(); last_mc_mode = st_ivas->mc_mode; + move32(); /* select MC format mode */ -#ifndef IVAS_FLOAT_FIXED - st_ivas->mc_mode = ivas_mc_mode_select( st_ivas->hEncoderConfig->mc_input_setup, st_ivas->hEncoderConfig->ivas_total_brate ); -#else st_ivas->mc_mode = ivas_mc_mode_select_fx( st_ivas->hEncoderConfig->mc_input_setup, st_ivas->hEncoderConfig->ivas_total_brate ); -#endif + move32(); /* write MC LS setup */ - st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + IF( st_ivas->nSCE > 0 ) + { + st0 = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st0 = st_ivas->hCPE[0]->hCoreCoder[0]; + } + push_indice( st0->hBstr, IND_SMODE, st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_BITS ); /* MC format switching */ - if ( st_ivas->hEncoderConfig->last_ivas_total_brate != st_ivas->hEncoderConfig->ivas_total_brate || st_ivas->mc_mode != last_mc_mode ) + test(); + IF( NE_32( st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate ) || NE_32( st_ivas->mc_mode, last_mc_mode ) ) { - if ( ( error = ivas_mc_enc_reconfig( st_ivas, last_mc_mode ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_enc_reconfig_fx( st_ivas, last_mc_mode ) ), IVAS_ERR_OK ) ) { return error; } @@ -1575,149 +1545,128 @@ ivas_error ivas_mc_enc_config( * Reconfigure the MC format encoder *-------------------------------------------------------------------------*/ -static ivas_error ivas_mc_enc_reconfig( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t last_mc_mode /* i : last frame mc mode */ +static ivas_error ivas_mc_enc_reconfig_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 last_mc_mode /* i : last frame mc mode */ ) { - int16_t nchan_transport_old, nSCE_old, nCPE_old; + Word16 nchan_transport_old, nSCE_old, nCPE_old; ivas_error error; - int32_t new_brate_SCE, new_brate_CPE; + Word32 new_brate_SCE, new_brate_CPE; error = IVAS_ERR_OK; + move32(); nchan_transport_old = st_ivas->nchan_transport; + move16(); nSCE_old = st_ivas->nSCE; + move16(); nCPE_old = st_ivas->nCPE; + move16(); /*-----------------------------------------------------------------* * Reconfigure MC modules *-----------------------------------------------------------------*/ - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = st_ivas->hEncoderConfig->nchan_inp / 2; + move16(); + st_ivas->nCPE = shr( st_ivas->hEncoderConfig->nchan_inp, 1 ); + move16(); -#ifndef IVAS_FLOAT_FIXED - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); -#else st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); -#endif + move16(); - if ( last_mc_mode != MC_MODE_MCT ) + IF( NE_32( last_mc_mode, MC_MODE_MCT ) ) { - if ( st_ivas->hLFE != NULL ) + IF( st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } /* create LFE handle */ - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } /*De-allocate handles for other MC modes*/ -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); -#ifdef IVAS_FLOAT_FIXED /* De-allocate McMasa-related handles */ ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_masa_enc_close( &( st_ivas->hMasa ) ); ivas_qmetadata_close( &st_ivas->hQMetaData ); } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + move16(); + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1; + move16(); st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); - if ( last_mc_mode != MC_MODE_PARAMUPMIX ) + IF( NE_32( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { - if ( st_ivas->hLFE != NULL ) + IF( st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } /* create LFE handle */ - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } } - if ( last_mc_mode != MC_MODE_PARAMUPMIX ) + IF( NE_32( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { - if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } /*De-allocate handles for other MC modes*/ -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_enc_close_fx( &st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_param_mc_enc_close( &st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); -#endif /* De-allocate McMasa-related handles */ -#ifdef IVAS_FLOAT_FIXED ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_masa_enc_close( &( st_ivas->hMasa ) ); ivas_qmetadata_close( &st_ivas->hQMetaData ); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { - if ( last_mc_mode != MC_MODE_PARAMMC ) + IF( NE_32( last_mc_mode, MC_MODE_PARAMMC ) ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_param_mc_enc_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_param_mc_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_param_mc_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } /* De-allocate McMasa-related handles */ -#ifdef IVAS_FLOAT_FIXED ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); -#endif - if ( st_ivas->hMasa != NULL ) + + IF( st_ivas->hMasa != NULL ) { ivas_masa_enc_close( &( st_ivas->hMasa ) ); st_ivas->hMasa = NULL; @@ -1725,7 +1674,8 @@ static ivas_error ivas_mc_enc_reconfig( ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); - if ( last_mc_mode == MC_MODE_PARAMUPMIX && st_ivas->hLFE != NULL ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_PARAMUPMIX ) && st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); @@ -1734,79 +1684,60 @@ static ivas_error ivas_mc_enc_reconfig( ivas_qmetadata_close( &st_ivas->hQMetaData ); /* De-allocate MCT handle if last mode was MCT */ - if ( last_mc_mode == MC_MODE_MCT && st_ivas->nchan_transport <= CPE_CHANNELS ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && LE_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { ivas_mct_enc_close( &( st_ivas->hMCT ) ); } - if ( last_mc_mode == MC_MODE_MCT && st_ivas->hLFE != NULL ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - if ( last_mc_mode != MC_MODE_MCMASA ) + IF( NE_32( last_mc_mode, MC_MODE_MCMASA ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); -#else ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); -#endif - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED - if ( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#else - if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } - else + ELSE { /* reconfigure McMASA instance */ -#ifdef IVAS_FLOAT_FIXED - if ( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) - { - return error; - } -#else - if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#endif } -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#else - ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); -#endif ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); - if ( last_mc_mode == MC_MODE_PARAMUPMIX && st_ivas->hLFE != NULL ) + test(); + IF( EQ_32( last_mc_mode, MC_MODE_PARAMUPMIX ) && st_ivas->hLFE != NULL ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } - if ( last_mc_mode == MC_MODE_MCT ) + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) ) { /* LFE handle */ ivas_lfe_enc_close( &( st_ivas->hLFE ) ); @@ -1815,15 +1746,17 @@ static ivas_error ivas_mc_enc_reconfig( } } - if ( st_ivas->mc_mode != MC_MODE_MCMASA ) + IF( NE_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; + move16(); } - else + ELSE { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } } @@ -1835,74 +1768,77 @@ static ivas_error ivas_mc_enc_reconfig( and might have IGF and TranDet static memory not allocated and the bit stream index list not set, set correct mct_chan_mode and init missing static mem do it here since it is _very_ MC specific */ - if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) + test(); + test(); + IF( EQ_32( last_mc_mode, MC_MODE_MCT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) && GT_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { Encoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; - if ( st_ivas->nchan_transport == 3 ) + IF( EQ_16( st_ivas->nchan_transport, 3 ) ) { st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + move32(); } - else + ELSE { st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); } - if ( st->hTranDet == NULL ) + IF( st->hTranDet == NULL ) { - if ( ( st->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) + IF( ( st->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } -#ifdef IVAS_FLOAT_FIXED InitTransientDetection_ivas_fx( shl( div_l( st->input_Fs, FRAMES_PER_SEC ), 1 ), NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); -#else - InitTransientDetection( (int16_t) ( st->input_Fs / FRAMES_PER_SEC ), NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); -#endif } - if ( st->hIGFEnc == NULL ) + IF( st->hIGFEnc == NULL ) { - if ( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + IF( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } } -#ifndef IVAS_FLOAT_FIXED - st->igf = getIgfPresent( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); -#else st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); -#endif + move16(); /* set last core to TCX20 */ st->last_core = TCX_20_CORE; + move16(); } - if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); -#else ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); -#endif } - else if ( st_ivas->mc_mode == MC_MODE_MCT ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { new_brate_SCE = 0; - new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + move32(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { new_brate_SCE = 0; - new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + move32(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } - else + ELSE { new_brate_SCE = 0; /*st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport;*/ - new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + move32(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } - if ( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index f8787ab7d50621a7f1c371a1caab6f420a9d1fda..8d7aa9855eac22e954c73a010a4d606d7016dff2 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1931,75 +1931,6 @@ void ivas_mdct_core_whitening_enc( st->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac; } - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) - { - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); - } - - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - - float max_sb = 0; - float max_tb = 0; - Word16 max_sb_fx = 0; - Word16 max_tb_fx = 0; - - float max_fir_tb = 0; - float max_iir_tb = 0; - float max_fir_sb = 0; - float max_iir_sb = 0; - - Word16 max_fir_tb_fx = 0; - Word16 max_iir_tb_fx = 0; - Word16 max_fir_sb_fx = 0; - Word16 max_iir_sb_fx = 0; - FOR( Word16 sfb = 0; sfb < 23; sfb++ ) - { - f2me_16( hPrivateData->prevDampingFactor_IIR[sfb], &hPrivateData->prevDampingFactor_IIR_fx[sfb], &hPrivateData->prevDampingFactor_IIR_e[sfb] ); - - max_fir_tb = fmaxf( fabsf( hPrivateData->prevSFM_FIR_SFB_TB[sfb] ), max_fir_tb ); - f2me_16( max_fir_tb, &max_fir_tb_fx, &hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_TB[sfb], sub( 15, hPrivateData->prevSFB_FIR_TB_e[sfb] ) ); - - max_iir_tb = fmaxf( fabsf( hPrivateData->prevSFM_IIR_SFB_TB[sfb] ), max_iir_tb ); - f2me_16( max_iir_tb, &max_iir_tb_fx, &hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_TB[sfb], sub( 15, hPrivateData->prevSFB_IIR_TB_e[sfb] ) ); - - max_fir_sb = fmaxf( fabsf( hPrivateData->prevSFM_FIR_SFB_SB[sfb] ), max_fir_sb ); - f2me_16( max_fir_sb, &max_fir_sb_fx, &hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_SB[sfb], sub( 15, hPrivateData->prevSFB_FIR_SB_e[sfb] ) ); - - max_iir_sb = fmaxf( fabsf( hPrivateData->prevSFM_IIR_SFB_SB[sfb] ), max_iir_sb ); - f2me_16( max_iir_sb, &max_iir_sb_fx, &hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_SB[sfb], sub( 15, hPrivateData->prevSFB_IIR_SB_e[sfb] ) ); - - max_tb = fmaxf( fabsf( hPrivateData->SFM_tb[sfb] ), max_tb ); - f2me_16( max_tb, &max_tb_fx, &hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_tb_fx[sfb] = float_to_fix16( hPrivateData->SFM_tb[sfb], sub( 15, hPrivateData->sfb_tb_e[sfb] ) ); - - max_sb = fmaxf( fabsf( hPrivateData->SFM_sb[sfb] ), max_sb ); - f2me_16( max_sb, &max_sb_fx, &hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->SFM_sb_fx[sfb] = float_to_fix16( hPrivateData->SFM_sb[sfb], sub( 15, hPrivateData->sfb_sb_e[sfb] ) ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR[i] = float_to_fix( hPrivateData->prevSFM_FIR_flt[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR[i] = float_to_fix16( hPrivateData->prevSFM_IIR_flt[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM_fx[i][j] = float_to_fix16( hPrivateData->igfPastSFM[i][j], 13 ); - } - } - } - if ( st->hIGFEnc ) - { - Word16 q_spectrum; - q_spectrum = L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, st->hIGFEnc->infoStopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); hTcxEnc->spectrum_e[0] = 31 - q_spectrum; floatToFixed_arrL32( hTcxEnc->spectrum[0], hTcxEnc->spectrum_fx[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); @@ -2014,35 +1945,6 @@ void ivas_mdct_core_whitening_enc( #endif core_signal_analysis_high_bitrate_ivas_fx( new_samples_fx[ch] + L_INP_MEM, T_op[ch], NULL, NULL, st, tnsSize[ch], tnsBits[ch], param_core[ch], <pBits[ch], windowedSignal_fx[ch], st->L_frame, st->hTcxEnc->L_frameTCX, hCPE->last_element_mode, 0, mdst_spectrum_fx[ch], mdst_spectrum_e[ch], &Q_new ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) - { - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); - } - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } - } IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index bb0a7786609f43d10da6908a3a2aee9f2ede5cf3..788f9dec25f75c0be3f51319db01afbc62776a41 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -902,22 +902,6 @@ static ivas_error ivas_spar_cov_md_process_fx( move32(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) - { - FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) - { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); - move32(); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); - move32(); - } - hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q22; - move16(); - hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q22; - move16(); - } -#endif IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { order = sba_order; @@ -928,23 +912,7 @@ static ivas_error ivas_spar_cov_md_process_fx( order = 1; move16(); } - ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, order, dtx_vad, Wscale_d_fx, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) - { - FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) - { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); - move32(); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); - move32(); - } - hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q28; - move16(); - hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q28; - move16(); - } -#endif + ivas_get_spar_md_from_dirac_enc_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, order, dtx_vad, Wscale_d_fx, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); } IF( hSpar->hMdEnc->spar_hoa_md_flag ) diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 6854716ae7f91a422b316126b59a72a7a5849e12..041913efd1bf12acd3eb94c48419a7c8cf17257c 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -1239,25 +1239,6 @@ void stereo_mdct_core_enc( hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; me2f_buf( sts[ch]->hTcxEnc->spectrum_fx[n], sts[ch]->hTcxEnc->spectrum_e[n], sts[ch]->hTcxEnc->spectrum[n], hGrid->infoGranuleLen ); me2f_buf( &p_powerSpec_fx[ch][0], sts[ch]->hTcxEnc->spectrum_e[n], &p_powerSpec[ch][0], hGrid->infoGranuleLen ); - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } } #endif /**********************************fix to flt ends here*******************************************************/ #else @@ -1298,14 +1279,9 @@ void stereo_mdct_core_enc( q_spectrum = L_get_q_buf1( orig_spectrum[ch][n], hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); if ( st->hIGFEnc ) { - q_spectrum = min( q_spectrum, L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ) ); + q_spectrum = min( q_spectrum, 31 - st->hIGFEnc->spec_be_igf_e ); } floatToFixed_arrL32( orig_spectrum[ch][n], orig_spectrum_fx[ch][n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); - if ( st->hIGFEnc ) - { - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } q_spectrum = L_get_q_buf1( st->hTcxEnc->spectrum[n], hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); floatToFixed_arrL32( st->hTcxEnc->spectrum[n], st->hTcxEnc->spectrum_fx[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); @@ -1319,33 +1295,6 @@ void stereo_mdct_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[n], st->hTcxEnc->spectrum[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); fixedToFloat_arrL32( &powerSpec_fx[ch][n * L_subframeTCX], &powerSpec[ch][n * L_subframeTCX], q_powerSpec, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - } - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } #endif #else ProcessIGF( st, st->hTcxEnc->spectrum[n], orig_spectrum[ch][n], &powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); @@ -1395,14 +1344,9 @@ void stereo_mdct_core_enc( q_spectrum = L_get_q_buf1( orig_spectrum[ch][n], hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); if ( st->hIGFEnc ) { - q_spectrum = min( q_spectrum, L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ) ); + q_spectrum = min( q_spectrum, 31 - st->hIGFEnc->spec_be_igf_e ); } floatToFixed_arrL32( orig_spectrum[ch][n], orig_spectrum_fx[ch][n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine ); - if ( st->hIGFEnc ) - { - floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; - } q_spectrum = L_get_q_buf1( st->hTcxEnc->spectrum[n], hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); floatToFixed_arrL32( st->hTcxEnc->spectrum[n], st->hTcxEnc->spectrum_fx[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); @@ -1410,42 +1354,11 @@ void stereo_mdct_core_enc( q_powerSpec = L_get_q_buf1( &powerSpec[ch][n * L_subframeTCX], hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); floatToFixed_arrL32( &powerSpec[ch][n * L_subframeTCX], &powerSpec_fx[ch][n * L_subframeTCX], q_powerSpec, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); - } #endif ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &q_powerSpec, st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[n], st->hTcxEnc->spectrum[n], q_spectrum, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); fixedToFloat_arrL32( &powerSpec_fx[ch][n * L_subframeTCX], &powerSpec[ch][n * L_subframeTCX], q_powerSpec, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); - - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); - me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, hPrivateData->igfInfo.grid[igfGridIdx].stopLine - IGF_START_MN ); - } - - for ( Word16 sfb = 0; sfb < 23; sfb++ ) - { - hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); - hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); - hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); - hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); - hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); - hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); - } - - for ( i = 0; i < IGF_MAX_TILES; i++ ) - { - hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ - for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); - } - } #endif #else ProcessIGF( st, st->hTcxEnc->spectrum[n], orig_spectrum[ch][n], &powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 849397efc4f1d1dfe922a54e7e80701eeba6bdcd..d067986e2b2e1265650731d9ebbb72e687452bba 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -632,18 +632,18 @@ typedef struct fd_cng_enc_structure typedef struct dtx_enc_structure { - int16_t cnt_SID; /* CNG and DTX - counter of SID update for the interop. mode or DTX, if enabled */ - int16_t first_CNG; /* CNG and DTX - first CNG frame flag */ - int16_t cng_cnt; /* CNG and DTX - counter of CNG frames for averaging */ - int16_t max_SID; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ - int16_t CNG_mode; /* CNG and DTX - mode for DTX configuration */ + Word16 cnt_SID; /* CNG and DTX - counter of SID update for the interop. mode or DTX, if enabled */ + Word16 first_CNG; /* CNG and DTX - first CNG frame flag */ + Word16 cng_cnt; /* CNG and DTX - counter of CNG frames for averaging */ + Word16 max_SID; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ + Word16 CNG_mode; /* CNG and DTX - mode for DTX configuration */ #ifndef IVAS_FLOAT_FIXED float lspCNG[M]; /* CNG and DTX - LP filtered ISPs */ #else Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps Q15 */ #endif - int16_t VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ - int16_t VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ + Word16 VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ + Word16 VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ #ifndef IVAS_FLOAT_FIXED float lt_ener_voiced; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ @@ -653,16 +653,16 @@ typedef struct dtx_enc_structure Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ Word32 frame_ener_fx; /* Q(-7) */ #endif - int16_t cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ + Word16 cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ #ifndef IVAS_FLOAT_FIXED float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ #else Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame Q(-7) */ #endif - int16_t last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ - int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ - int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ - int32_t last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ + Word16 last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ + Word16 var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ + Word16 interval_SID; /* CNG and DTX - interval of SID update, default 8 */ + Word32 last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ } DTX_ENC_DATA, *DTX_ENC_HANDLE; @@ -698,7 +698,7 @@ typedef struct igfscfenc_public_data_struct typedef struct igf_enc_private_data_struct { IGF_INFO igfInfo; - int16_t igfScfQuantized[IGF_MAX_SFB]; + Word16 igfScfQuantized[IGF_MAX_SFB]; IGFSCFENC_INSTANCE hIGFSCFArithEnc; #ifdef IVAS_FLOAT_FIXED Word16 prevSFM_FIR_SFB_TB_fx[IGF_MAX_SFB]; @@ -718,31 +718,21 @@ typedef struct igf_enc_private_data_struct Word16 igfPastSFM_fx[IGF_MAX_TILES][IGF_PAST_SFM_LEN]; /*2Q13*/ #endif // IVAS_FLOAT_FIXED - float prevSFM_FIR_SFB_TB[IGF_MAX_SFB]; - float prevSFM_IIR_SFB_TB[IGF_MAX_SFB]; - float prevSFM_FIR_SFB_SB[IGF_MAX_SFB]; - float prevSFM_IIR_SFB_SB[IGF_MAX_SFB]; - int16_t logSpec[L_FRAME_PLUS]; - - float prevDampingFactor_IIR[IGF_MAX_SFB]; - int16_t dampingFactorSmoothing[IGF_MAX_SFB]; - float SFM_tb[IGF_MAX_SFB]; - float SFM_sb[IGF_MAX_SFB]; - - int16_t igfCurrWhiteningLevel[IGF_MAX_TILES]; - int16_t igfPrevWhiteningLevel[IGF_MAX_TILES]; - int16_t igfWhiteningHangoverCnt[IGF_MAX_TILES]; - float igfPastSFM[IGF_MAX_TILES][IGF_PAST_SFM_LEN]; - int16_t igfPastSFM_pos; - - float prevSFM_FIR_flt[IGF_MAX_TILES]; - float prevSFM_IIR_flt[IGF_MAX_TILES]; + Word16 logSpec[L_FRAME_PLUS]; + + Word16 dampingFactorSmoothing[IGF_MAX_SFB]; + + Word16 igfCurrWhiteningLevel[IGF_MAX_TILES]; + Word16 igfPrevWhiteningLevel[IGF_MAX_TILES]; + Word16 igfWhiteningHangoverCnt[IGF_MAX_TILES]; + Word16 igfPastSFM_pos; + Word32 prevSFM_FIR[IGF_MAX_TILES]; /* 15Q16 */ Word16 prevSFM_IIR[IGF_MAX_TILES]; /* 2Q13 */ - int16_t wasTransient; + Word16 wasTransient; UWord8 igfBitstream[IGF_BITBUFSIZE / 8]; - int16_t igfBitstreamBits; + Word16 igfBitstreamBits; } IGF_ENC_PRIVATE_DATA, *IGF_ENC_PRIVATE_DATA_HANDLE; @@ -750,16 +740,14 @@ typedef struct igf_enc_private_data_struct typedef struct igf_enc_instance_struct { IGF_ENC_PRIVATE_DATA igfData; - int32_t infoSamplingRate; - int16_t infoStartFrequency; - int16_t infoStopFrequency; - int16_t infoStartLine; - int16_t infoStopLine; - int16_t infoTotalBitsWritten; - int16_t infoTotalBitsPerFrameWritten; - int16_t flatteningTrigger; - float spec_be_igf_flt[N_MAX_TCX - IGF_START_MN]; - float tns_predictionGain_flt; + Word32 infoSamplingRate; + Word16 infoStartFrequency; + Word16 infoStopFrequency; + Word16 infoStartLine; + Word16 infoStopLine; + Word16 infoTotalBitsWritten; + Word16 infoTotalBitsPerFrameWritten; + Word16 flatteningTrigger; Word32 spec_be_igf[N_MAX_TCX - IGF_START_MN]; /* copy of MDCT spectrum */ Word16 spec_be_igf_e; /* exponent of copy of MDCT spectrum */ Word16 tns_predictionGain;